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

In reply to Re: Using eval for by dmmiller2k
in thread Using eval for by SuperCruncher

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.