Based on a couple searches, it looks like there hasn't been a thread about plugins here for a couple years now, so I guess it's about time...

I have a couple applications which currently use a class hierarchy with an abstract MyNamespace::Event base class and half a dozen MyNamespace::Event::Foo subclasses which actually do things. I'll be adding more of them in the future. A lot more. And I don't want to have the headaches of trying to keep everything updated to be aware of every subclass each time I add a new one.

I suppose I could just create one huge module which contains all of them, but that has its own issues. What I'd ideally like to be able to do is use MyNamespace::Event::*, but, as I expected, that doesn't work.

The closest thing I've been able to find to a solution is to find the plugin directory, get a list of the files there, and then require each one. While it would work, I don't like it. Multiple apps means I can't just use a subdirectory of the app directory without duplicating all relevant files, plus I want to leave them in @INC anyhow for times when I'm dealing with simple side tasks that only need to use a couple of them without needing to load up everything. require also lacks a little of use's functionality, although I'm not sure whether I'll ever need to worry about exporting from this section of the namespace, so that may not matter anyhow.

Are there any other options or is foreach my $file (glob('/some/dir/*')) { require $file } pretty much the only way to do this?


In reply to Polymorphic Plugins by dsheroh

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.