I'm about to start making a simple program in Perl. All it does is monitor an arbitrary number of URLs for changes (I mean changes in the pages pointed to by URLs, not changes in the actual URL itself by the way) and take certain action if a change is detected.

This sounds simple but the catch is that if a URL changes, the action to be taken will be completely different from URL to URL.

So I thought a relatively "clean" way of implementing this was to have a set of "plugin" files (Perl code) like foo.plugin, bar.plugin etc. These will specify a URL to check, and a 'do' function that will determine what is to be done if the URL has changed.

So, my questions:

  1. Is it OK to use eval like:
    foreach my $plugin (glob("*.plugin")) { do $plugin; }
  2. Can I check that the plugin is 'legal' (implements the correct functions, variables and so on) by using exists and then by remembering to use undef before I eval a new plugin? For example:
    foreach my $plugin (glob("*.plugin")) { do $plugin; if (!exists(&plugin::do_stuff) or !exists($url)) { die "Invalid plugin: function(s) not implemented.\n"; } # Call the various plugin 'methods' plugin::do_stuff(); undef (&plugin::do_stuff); }
Thanks in advance.

In reply to 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.