Anansi::Singleton - A base module definition where only a single object instance is allowed.
package Anansi::Example; use base qw(Anansi::Singleton); sub finalise { my ($self, %parameters) = @_; } sub fixate { my ($self, %parameters) = @_; } sub initialise { my ($self, %parameters) = @_; } sub reinitialise { my ($self, %parameters) = @_; } 1;
This is a base module definition that manages the creation and destruction of module object instances that are not repeatable including embedded objects and ensures that destruction can only occur when all duplicate object instances are no longer used. Uses Anansi::Class, Anansi::ObjectManager and base.
(Anansi::Class) A parent module.
(Anansi::Class::DESTROY)
Overridden by Anansi::Singleton::DESTROY.
(Anansi::Class::finalise)
A virtual method.
(Anansi::Class::implicate)
(Anansi::Class::import)
(Anansi::Class::initialise)
(Anansi::Class::new)
Overridden by Anansi::Singleton::new.
(Anansi::Class::old)
(Anansi::Class::used)
(Anansi::Class::uses)
An object of this namespace.
Overrides Anansi::Class::DESTROY. Performs module object instance clean-up actions. Either calls the fixate method prior to dereferencing an instance of the object where more than one instance exists or the finalise method prior to dereferencing the last instance. Indirectly called by the perl interpreter.
$OBJECT->fixate(); $OBJECT->SUPER::fixate();
Named parameters.
A virtual method. Called just prior to module instance object destruction where there are multiple instances of the object remaining.
my $object = Anansi::Example->new(); my $object = Anansi::Example->new( SETTING => 'example', );
Either an object or a string of this namespace.
Overrides Anansi::Class::new. Instantiates or reinstantiates an object instance of a module. Either calls the initialise method with the supplied parameters after the object is first instantiated or the reinitialise method after subsequent instantiations.
$OBJECT->reinitialise(); $OBJECT->SUPER::reinitialise();
A virtual method. Called just after module instance object recreation. Intended to be overridden by an extending module.
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::Singleton, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Anansi::Singleton
CPAN shell
perl -MCPAN -e shell install Anansi::Singleton
For more information on module installation, please visit the detailed CPAN module installation guide.