Anansi::Class - A base module definition
package Anansi::Example; use base qw(Anansi::Class); sub finalise { my ($self, %parameters) = @_; } sub initialise { my ($self, %parameters) = @_; } 1; package main; use Anansi::Example; my $object = Anansi::Example->new(); 1;
This is a base module definition that manages the creation and destruction of module object instances including embedded objects and ensures that destruction can only occur when an object is no longer used. Makes use of Anansi::ObjectManager.
An object of this namespace.
Performs module object instance clean-up actions. Calls the finalise method prior to dereferencing the object. Indirectly called by the perl interpreter.
$OBJECT->finalise(); $OBJECT->SUPER::finalise();
A virtual method. Called just prior to module instance object destruction.
Returns this object's unique identification or undef on error.
sub implicate { my ($self, $caller, $parameter) = @_; if('EXAMPLE_VARIABLE' eq $parameter) { return \EXAMPLE_VARIABLE; } try { return $self->SUPER::implicate($caller, $parameter); } return if($@); }
An array containing the package, file name and line number of the caller.
A string containing the name to import.
A virtual method. Performs one module instance name import. Called for each name to import.
use Anansi::Example qw(EXAMPLE_VARIABLE);
An array containing all of the names to import.
Performs all required module name imports. Indirectly called via an extending module.
$OBJECT->initialise(); $OBJECT->SUPER::initialise();
Named parameters that were supplied to the new method.
A virtual method. Called just after module instance object creation.
Returns this object's namespace or undef on error.
my $object = Anansi::Example->new(); my $object = Anansi::Example->new( SETTING => 'example', );
Either an object or a string of this namespace.
Named parameters.
Instantiates an object instance of a module. Calls the initialise module with the supplied parameters after the object is instantiated. Indirectly called via an extending module through inheritance.
$object->old();
Enables a module instance object to be externally destroyed.
$object->used('EXAMPLE');
An array of strings containing the names of blessed objects currently in use by this object.
Releases a module instance object to enable it to be destroyed.
$object->uses( EXAMPLE => $example, ); $object->uses( EXAMPLE => 'Anansi::Example', ); $object->{EXAMPLE}->doSomething();
A hash containing keys that represent the name to associate with the string namespace or object within the associated values.
Binds module instance objects to the current object to ensure that the objects are not prematurely destroyed. Adds the parameters to the object namespace.
my $names = $object->using(); foreach my $name (@{$names}) { $object->{$name}->doSomething(); } $object->using('EXAMPLE')->doSomething(); if(1 == $object->using( 'EXAMPLE', 'ANOTHER', ));
A string or an array of strings containing the names of blessed objects currently in use by this object.
Either returns an array of strings containing the names of the blessed objects currently in use by this object or the blessed object represented by the single specified name or whether the specified names represent blessed objects with a 1 (one) for yes and 0 (zero) for no.
This module is designed to make it simple, easy and quite fast to code your design in perl. If for any reason you feel that it doesn't achieve these goals then please let me know. I am here to help. All constructive criticisms are also welcomed.
Kevin Treleaven <kevin AT treleaven DOT net>
To install Anansi::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Anansi::Class
CPAN shell
perl -MCPAN -e shell install Anansi::Class
For more information on module installation, please visit the detailed CPAN module installation guide.