|
Class::Runtime - API for dynamic class loading/unloading/status |
Class::Runtime - API for dynamic class loading/unloading/status
To install this module type the following:
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.
Method used to retrieve path associated with this object
Method used to add path to object path list to search from
Method used to remove path from object search path
Method used to check whether given class is 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.
Method used to unload class/library
Method used to load class/library and call specific method with that library.
2003/07/07 Modified to correct issues with method invoke
Currently you can contact the author at the email address listed below.
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.
|
Class::Runtime - API for dynamic class loading/unloading/status |