Mp3a
my %attributes = (
login => undef,
uid => undef,
gid => undef,
err_msg => '',
err_cnt => 0,
)
sub new {
my $this = shift;
# No Inheritance
my $class = ref($this) || $this;
my $self = {
_permitted => {},
%attributes,
};
bless $self, $class;
foreach my $attrib (keys %attributes) {
$self->{_permitted}->{$attrib} = $attributes{$attrib};
}
$self->_init();
return $self;
}
sub AUTOLOAD {
my $self = shift;
my $type = ref($self) || croak "$self is not an object";
my $name = $AUTOLOAD;
$name =~ s/.*://; # strip fully-qualified portion
unless (exists $self->{_permitted}->{$name} ) {
croak "Can't access `$name' field in object of class $type";
}
if (@_) { return $self->{$name} = shift; }
else { return $self->{$name}; }
}