Data::Plugin - A Mother class for modules that can load/unload/reload
package Foo::Bar; use base ("Data::Plugin"); use vars ( $VERSION $AUTHORS )
$VERSION="8.1.6" # Can be also 8.1.6, but as it's a # new perl feature, I didn't used it yet. # the version format is not used yet, it's # just a way to provide a way to store it.
$AUTHORS=[ "Richie the Hacker" ];
sub on_load { my $class=shift; $class->SUPER::on_load(@_);
printf "Loading $class (version ".$class->version.") inherited from Foo::Bar\n"; }
sub on_unload { my $class=shift; $class->SUPER::on_unload(@_);
printf "Unloading $class (version ".$class->version.") inherited from Foo::Bar\n"; }
sub init { printf "Loading the Foo Bar class\n"; }
sub end { printf "Ending the Foo Bar class\n"; }
...
This is class is a mother class for Plugins. All the children'll have the ability to unload/reload/load.
The unloading/reloading isn't done very properly, but this will be enought for me, perhaps for you too.
class Data::Plugin
Attributs :
$- VERSION : SCALAR $- AUTHORS : [ author1 : SCALAR, ... ] $- PLUGINS : { _list => { className1 => { version => classVersion1 : SCALAR, order => : INTEGER } : SCALAR, ... } _classnames => [ className1 : SCALAR, ... ] }
Methods :
-$ import ()
+$ new () : Data::Plugin
+$ version () : SCALAR + version () : SCALAR
+$ authors () : [ author1 : SCALAR, ... ]
+$ load () +$ unload () +$ reload ()
+$ init () +$ end ()
+$ on_load () +$ on_unload ()
#$ _getModuleFileName () : SCALAR #$ _getModuleId () : SCALAR
#$ _getStaticScalar ( variableName : SCALAR ) : SCALAR # _getStaticScalar ( variableName : SCALAR ) : SCALAR
# DESTROY () :
-$ import ()
import routine. Called each time a class inherit directly or not from this one.
This method SHOULD NOT BE OVERRIDEN.
+$ new () : Data::Plugin
Constructor for plugins Should be called recursivelly.
+$ version () : SCALAR + version () : SCALAR
Return the version of the module.
The version is the current one for the statical method. Otherwise it's the creation time's version.
+$ authors () : [ author1 : SCALAR, ... ]
Return the author of the module.
+$ load (...)
load the class (must have been ``use''d at least one, and when the first use is done, you haven't to do a load)
+$ unload ()
Unload a class. As long as the @ISA is not clean, you can then call a load on the class. But it is highly prefered to call a ``reload'' when you can.
Now unload can be used as a method call to unload non-plugins packages.
+$ reload ()
Unload and then re-load a class.
+$ init () +$ end ()
Those methods contains initializations/desinitializations for the class. Those ARE NOT recurive
+$ on_load () +$ on_unload ()
Those methods contains initializations/desinitializations for the class and sub. Those ARE AND MUST BE recursive.
#$ _getModuleFileName () : SCALAR
Returns the file name of the module. Can be used for an auto-update from a plugin server for exemple.
Return a ID for the module. Now the file name. DO NOT USE, may change.
#$ _getStaticScalar ( variableName : SCALAR ) : SCALAR # _getStaticScalar ( variableName : SCALAR ) : SCALAR
Return the static scalar associated with the class/instance.
# DESTROY () :
Destroy process. Nothing done here, just to be sure not to core dump.
ending process. All plugins are unloaded.
This class have been written by Gissehel <gissehel@vachefolle.com> on March 2001
This class is part of the Boucherot project.
A plugin (which has this class as ancestor) can't use END statement. You have to find an other way (for exemple overloading the ``end'' static method).
Usage of ``BEGIN'' statement is discouraged.
The plugin can only works if the class is located in a file with the same name. But this is not quite a big bug because the code will be smarter.
This won't work if you maintains variables that are'nt DIRECTLY in the class' name space.