Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to dynamic load plugin files in perl?
- Test.pm
- Plugins/Plugin1.pm
- Plugins/Plugin2.pm
- sub new{
- #how to dynamic load plugins?
- my $test=Test->new("Plugin1");
- $test->run ;#should call Plugin1->run
- eval {
- require Plugin1;
- Plugin1->import();
- };
- if ($@) {
- warn "Error including Foobar: $@";
- }
- eval {
- my $module_name = 'Plugin1.pm';
- require $module_name;
- $module_name =~ s/.pm//;
- $module_name->import();
- };
- if ($@) {
- # handle error here
- }
- eval {
- require $plugin;
- }
- if($@) # try another one or report error or whatever ...
- require "Plugins/Plugin1.pm";
- use Module::PluginFinder qw( );
- my $finder = Module::PluginFinder->new(
- search_path => 'Plugins',
- );
- my $test = $finder->construct("Plugin1");
- $test->run();
- sub new {
- my $class = shift;
- ...;
- for my $plugin (@_){
- if( eval "require $plugin" ){
- # successful
- ...;
- }else{
- # unsuccessful
- die $@;
- }
- }
- ...;
- }
- sub new {
- my $class = shift;
- ...;
- for my $plugin (@_){
- eval "require $plugin" or die $@;
- # successful
- ...;
- }
- ...;
- }
Advertisement
Add Comment
Please, Sign In to add comment