Class::Runtime - API for dynamic class loading/unloading/status
Symbol
File::Spec
To install this module type the following:
perl Makefile.PL
make
make test
make install
Class for dynamically loading/unloading/stat on modules. Currently it is designed for loading a class local to the system at runtime. Future versions may include loading in a distributed environment.
A specific search path can be associated with the object which will be 'unshifted' onto @INC before attempting to load the class and 'shifted' off after attempting to load.
Also, a class can be checked whether it is loaded or not in the process.
my $class = 'MyClass::MySubClass'; my $obj = Class::Runtime->new( class=> $class ); ## LOADING CLASS AT RUNTIME unless ( $cl->load ) { warn "Error in loading class\n"; warn "\n\n", $@, "\n\n" if DEBUG; } ## CHECKING FOR CLASS AVAILABILITY AT RUNTIME unless ( $cl->isLoaded ) { warn 'Class - ', $class, ' - is loaded', "\n"; } my $newPath; ## ADDING SEACH PATH TO OBJECT ## Multiple $newPath = $cl->addPath( path=> [ qw( /tmp/lib /tmp/lib2 ) ] ); ##OR Single $newPath = $cl->addPath( path=> '/tmp/lib' ); ## REMOVING SEARCH PATH FROM OBJECT ## Multiple $newPath = $cl->dropPath( path=> [ qw( /tmp/lib /tmp/lib2 ) ] ); ##OR Single $newPath = $cl->dropPath( path=> '/tmp/lib' ); ## GETTING PATH ASSOCIATED WITH OBJECT my @path = $cl->getPath; ## INVOKING METHOD my $method = 'new'; if ( $cl->isLoaded and $class->can( 'new' ) ) { my $obj = $cl->invoke( 'new', arg1=> 1, arg2=> 2 ); $obj->method2; } ## NOT NECESSARY AS ONCE CLASS HAS BEEN LOADED CAN INVOKE DIRECTLY if ( $cl->isLoaded and $class->can( 'new' ) ) { my $obj = $class->new( arg1=> 1, arg2=> 2 ); $obj->method2; } ## UNLOADING CLASS if ( $cl->isLoaded ) { $cl->unload or warn 'Unable to unload class - ', $class, "\n"; }
Creates new object and initializes member variables if passed in as arguments. Takes parameterized argument list.
class => name of class to dynamically load
Class::Runtime object
Method used to retrieve path associated with this object
None
array of paths
integer 0 if no paths exist
Method used to add path to object path list to search from
path => As a single string or as a reference to an array
undef if error
Method used to remove path from object search path
path=> As a single string or as a reference to an array
Method used to check whether given class is loaded.
1 if loaded
0 if not loaded
Method used to load library/class. If a path has been associated with this object it will be 'unshifted' onto the global @INC array. Immediately after the attempted load the paths 'unshifted' onto the @INC array will be 'spliced' out. This is done so as to prevent any wrongful modification of @INC since the loading library may modify @INC or perhaps some other code.
1 on successful load
undef if error (setting $@)
Method used to unload class/library
1 on successful unload
Method used to load class/library and call specific method with that library.
name of method
remaining list of arguments to pass off to invoked method
value of returned method call
2002/02/14 Created
2003/07/07 Modified to correct issues with method invoke
Currently you can contact the author at the email address listed below.
Stathy G. Touloumis <stathy-classruntime@stathy.com>
Per Einar Ellefsen - For providing the code to conver class to file path portably.
Bhavesh Jardosh - For providing bug info in test.pl and method invoke.
Copyright (C) 2002 Stathy G. Touloumis
This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::Runtime, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Runtime
CPAN shell
perl -MCPAN -e shell install Class::Runtime
For more information on module installation, please visit the detailed CPAN module installation guide.