http://www.perlmonks.org?node_id=1210484


in reply to Re: Help Changing use into require/import
in thread Help Changing use into require/import

I wrote Plugin::Simple, primarily because I had a bit of time and wanted to write my own basic plugin architecture for a learning exercise. Here's a runtime snip of actually loading a plugin. It can be in the form of a file name with a path, a filename without a path, or a standard Module::IAm syntax. The load() function is brought in from Module::Load.

The conditional load doesn't affect the program, it simply determines whether the plugin name will be returned to the caller:

sub _load { my ($self, $plugin) = @_; if ($plugin =~ /(.*)\W(\w+)\.pm/){ unshift @INC, $1; $plugin = $2; } elsif ($plugin =~ /^(\w+)\.pm$/){ unshift @INC, '.'; $plugin = $1; } my $loaded = eval { load $plugin; 1; }; if ($loaded) { return $plugin; } }