Class-Attrib
view release on metacpan or search on metacpan
Called with two arguments, overrides an existing attribute default value
in the closest class that defined it at compile-time.
No mechanism is provided for defining new attributes after compilation.
Returns the newly assigned value, for convenience.
=cut
sub Attrib($;$;$) {
my $this = shift;
my $class = ref( $this ) || $this;
unless ( @_ ) {
my %attribs = ();
my ( $Attr, $attr );
walk_width {
my $pkg = shift;
Sets the instance-specific value of an attribute. If the supplied value
is 'undef', removes any previously stored instance-specific value.
=cut
{ # private lexicals begin
my %values;
sub attrib($;$;$) {
my $self = shift;
# class reference, might want to test or change a default
return $self->Attrib( @_ ) unless ref $self;
my $index = "$self";
$index =~ s/^.*=//; # ignore class
# never return a reference to the real data ;)
return dclone( $values{$index} ) unless @_;
( run in 0.246 second using v1.01-cache-2.11-cpan-1f129e94a17 )