Debian Codegraph @

Debconf/Base.pm

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 Debconf::Base - Debconf base class
6
7 =cut
8
9 package Debconf::Base;
10 use warnings;
11 use strict;
12 use Debconf::Log ':all';
13
14 =head1 DESCRIPTION
15
16 Objects of this class may have any number of fields. These fields can
17 be read by calling the method with the same name as the field. If a
18 parameter is passed into the method, the field is set.
19
20 Fields can be made up and used on the fly; I don't care what you call
21 them.
22
23 =head1 METHODS
24
25 =over 4
26
27 =item new
28
29 Returns a new object of this class. Optionally, you can pass in named
30 parameters that specify the values of any fields in the class.
31
32 =cut
33
34 sub new {
35 my $proto = shift;
36 my $class = ref($proto) || $proto;
37 my $this=bless ({@_}, $class);
38 $this->init;
39 # debug debug => "new $this";
40 return $this;
41 }
42
43 =item init
44
45 This is called by new(). It's a handy place to set fields, etc, without
46 having to write your own new() method.
47
48 =cut
49
50 sub init {}
51
52 =item AUTOLOAD
53
54 Handles all fields, by creating accessor methods for them the first time
55 they are accessed.
56
57 =cut
58
59 sub AUTOLOAD {
60 (my $field = our $AUTOLOAD) =~ s/.*://;
61
62 no strict 'refs';
63 *$AUTOLOAD = sub {
64 my $this=shift;
65
66 return $this->{$field} unless @_;
67 return $this->{$field}=shift;
68 };
69 goto &$AUTOLOAD;
70 }
71
72 # Must exist so AUTOLOAD doesn't try to handle it.
73 sub DESTROY {
74 # my $this=shift;
75 # debug debug => "DESTROY $this";
76 }
77
78 =back
79
80 =head1 AUTHOR
81
82 Joey Hess <[email protected]>
83
84 =cut
85
86 1