sub AUTOLOAD { my ($self, $newval) = @_; $AUTOLOAD =~ s/.*:://; my $attr; if (exists $self->{$attr=$AUTOLOAD}) { # public attribute always accessible } elsif (exists $self->{$attr="_$AUTOLOAD"}) { croak "Cannot access protected attribute '$attr'" unless caller().isa(ref $self); } elsif (exists $self->{$attr="__$AUTOLOAD"}) { croak "Cannot access private attribute '$attr'" unless caller() eq ref $self; } else { croak "No such attribute ($AUTOLOAD) for object" } $self->{$attr} = $newval if @_ > 1; return $self->{$attr}; }