File: Base.pm

package info (click to toggle)
debconf 1.5.11etch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 3,364 kB
  • ctags: 714
  • sloc: perl: 8,347; sh: 286; makefile: 174; python: 117
file content (85 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/perl -w

=head1 NAME

Debconf::Base - Debconf base class

=cut

package Debconf::Base;
use Debconf::Log ':all';
use strict;

=head1 DESCRIPTION

Objects of this class may have any number of fields. These fields can
be read by calling the method with the same name as the field. If a
parameter is passed into the method, the field is set.

Fields can be made up and used on the fly; I don't care what you call
them.

=head1 METHODS

=over 4

=item new

Returns a new object of this class. Optionally, you can pass in named
parameters that specify the values of any fields in the class.

=cut

sub new {
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $this=bless ({@_}, $class);
	$this->init;
#	debug debug => "new $this";
	return $this;
}

=item init

This is called by new(). It's a handy place to set fields, etc, without
having to write your own new() method.

=cut

sub init {}

=item AUTOLOAD

Handles all fields, by creating accessor methods for them the first time
they are accessed.

=cut

sub AUTOLOAD {
	(my $field = our $AUTOLOAD) =~ s/.*://;

	no strict 'refs';
	*$AUTOLOAD = sub {
		my $this=shift;

		return $this->{$field} unless @_;
		return $this->{$field}=shift;
	};
	goto &$AUTOLOAD;
}

# Must exist so AUTOLOAD doesn't try to handle it.
sub DESTROY {
#	my $this=shift;
#	debug debug => "DESTROY $this";
}

=back

=head1 AUTHOR

Joey Hess <joeyh@debian.org>

=cut

1