sub AUTOLOAD { # AUTOLOAD object accessor/mutator method no strict "refs"; # allow me access to the symbol table my ($self,$newval) = @_; return if $AUTOLOAD =~ /::DESTROY$/o; # let perl handle its own clean up if ($AUTOLOAD =~/.*::get(_\w+)/ && $self->_accessible($1, 'read')){ my $attr_name = $1; *{$AUTOLOAD} = sub{ return $_[0]->{$attr_name}; }; # Creates an encapsulated method in the symbol table return $self->{$attr_name}; } # determine set or get method if ($AUTOLOAD =~/.*::set(_\w+)/ && $self->_accessible($1, 'write')){ my $attr_name = $1; *{$AUTOLOAD} = sub{ return $_[0]->{$attr_name}=$_[1]; }; return $self->{$attr_name}=$newval; } # no method for this object attribute die "No such method!: $AUTOLOAD"; }