in reply to Re^3: a simple matter of elegance
in thread a simple matter of elegance
Of course, you could fail loudly if referencing a key that is not there. You may also define a set of "public" fields that you allow in an array, and return the value of this field only if it is in that public set ... it depends on how protected you want to make the data.sub AUTOLOAD { my ($self, $field ) = @_ ; (my $sub = $AUTOLOAD) =~ s/.*::// ; return (exists($self->{'data'}->{$sub}) ? $self->{'data'}->{$sub} : + undef) ; }
my @public_fields = qw(address phone); sub in_array { ... } sub AUTOLOAD { my ($self, $field ) = @_ ; (my $sub = $AUTOLOAD) =~ s/.*::// ; return (in_array(\@public_fields,$sub) && exists($self->{'data'}->{ +$sub}) ? $self->{'data'}->{$sub} : undef) ; }
|
|---|