When your object goes out of scope, perl looks for a
sub DESTROY in your module. Since you haven't defined one, the AUTOLOAD method takes over. Your AUTOLOAD method then checks to see if your object has a field by the same name of the method call and die's if it doesn't.
You can do a couple different things. First, you could add a
DESTROY stub so that the AUTOLOADER doesn't come into play:
sub DESTROY {}
or you can change your
sub AUTOLOAD so that it ignores this method call that perl does automatically:
my $name = $AUTOLOAD;
$name =~ s/.*://; # strip fully-qualified portion
# this is new...
return 0 if($name eq 'DESTROY');
unless (exists $self->{_permitted}->{$name} ) {
croak "Can't access `$name' field in class $type";
}
That should take care of the error.
Update Looks like I was a bit late in my reply as someone else already suggested the
sub DESTROY {} solution... Oh well