Class::Attrib - Abstract translucent attribute management.
Provides an inherited view of attributes.
AUTOLOAD's accessor methods for visible attributes only.
Supplies a simple way to specify attributes and default values.
package MyApp::MyPackage; use strict; our @ISA = qw( Class::Attrib ); our %Attrib = ( ClassAttrib => 12345, translucent_attrib => "foo", mandatory_attrib => undef, ); 1;
Attribute definitions are kept in hashes named 'Attrib' in the derived class package.
ClassAttrib (a class attribute) only has useful meaning during instantiation of an object, therefore instance data is ignored entirely during accessor calls.
translucent_attrib is an instance attribute. Instances inherit their value from their (possibly itself inherited) class default, unless an overriding value has been stored on the object itself.
mandatory_attrib has an undefined default, therefore warnings will be issued if the program tries to access the attribute before it sets a value on the object.
Called without arguments, returns a hash containing all known attributes and their default values as inherited from the calling class. (TODO)
Returns a hash reference.
Called with one argument, returns the default value of the named attribute as inherited by the calling class.
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.
All three forms act exactly as Attrib when called as a class method.
Returns a copy of all attribute values specific to the instance.
Returns the value of the named attribute. If the instance does not have a corresponding value set, the inherited default value is returned.
Sets the instance-specific value of an attribute. If the supplied value is 'undef', removes any previously stored instance-specific value.
Each attribute has a corresponding accessor method with the same name. A closure is installed when first called to improve performance.
Equivalent to $this->attrib( 'foo' );
$this->attrib( 'foo' );
Equivalent to $this->attrib( 'foo', $value );
$this->attrib( 'foo', $value );
Equivalent to $this->Attrib( 'Bar' );
$this->Attrib( 'Bar' );
Attribute values stored on the instance are actually stored within a Class::Attrib lexical; this avoids collisions and also removes the assumption of a hash. Class::Attrib works perfectly well on scalar and array classes as well. However, this also means that attributes are invisible to serializers.
Storing references (blessed or otherwise) in an attribute won't ruffle any feathers in Class::Attrib itself, but could cause exceptions to be thrown if the composite class has a persistence mechanism.
Class::Attrib is an abstract class. It contains no constructors, therefore it cannot be instantiated without some impolite bless hackery.
To install Class::Attrib, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Attrib
CPAN shell
perl -MCPAN -e shell install Class::Attrib
For more information on module installation, please visit the detailed CPAN module installation guide.