in reply to a simple matter of elegance
package foo; use strict; use warnings; sub new { my $class = shift; my $self = {}; $self->{data} = undef; bless ($self, $class); return $self; } # setter and getter sub data { my ( $self, $attr ) = @_; $self->{'data'}->{$attr} = $attr if (defined($attr)); return $self->{'data'}->{$attr}; } 1; __END__
Update: Added to make a complete working sample.$ perl -l use foo; use strict; use warnings; my $foo = foo::->new(); $foo->data('bar', 42); print $foo->data('bar'); __END__ bar
|
|---|