- or download this
sub _attr {
my $self = shift;
my $name = shift;
...
$self->{"_$name"} = shift;
}
sub name { shift->_attr(name => @_); }
- or download this
package Parent;
use attribute sub {
...
# we have an ordinary hashref for the object
return \$self->{"_$name"};
}, [qw(city name)];
- or download this
package Child;
use base 'Parent';
...
# object is arrayref, and the attributes are stored in element 0
return \$self->[0]->{"_$name"};
};
- or download this
package attribute;
use strict;
use warnings;
...
}
}
1;