in reply to Using eval for

question 1: simply, yes.

question 2: for what you are trying to do, exists is not the way to go. Also, you are using plugin:: as the name of the package, but for this to work, you would have to declare, package plugin; in all of your plugin files. Unloading, too, is more complicated than simply undef &plugin::do_stuff;.

You probably want each plugin to be a perl object, with all such objects derived from a common base class, rather like this:

# in Plugin.pm: package Plugin; # the common base class sub new { my $type = shift; my $class = ref($type) || $type; return bless {}, $class; } # the public entry point, calls a private entry point in each derived +class, _do_stuff(), to actually do the work sub do_stuff { my $self = shift; die 'Illegal plugin function' unless ($self->can('_do_stuff')); # polymorphic method call return $self->_do_stuff(); } # in Whatever.pm: package Whatever; use base qw( Plugin ); # subclass of Plugin sub new { my $type = shift; my $class = ref($type) || $type; return bless $class->SUPER::new, $class; } sub _do_stuff { # whatever this plugin does goes here } # etc.

Then, in your main program, you would have code similar to this:

use Basename; for my $plugin_file ( ... ) { my $plugin_pkg = basename $pluginfile, '.pm'; eval { use $plugin_pkg; my $plugin_object = new $plugin_pkg; $plugin_object->do_stuff(); } if ($@) { # handle the error } }

This way there'd be no name clashes nor would you necessarily have to unload a plugin, once loaded.

dmm

You can give a man a fish and feed him for a day ...
Or, you can
teach him to fish and feed him for a lifetime