Probably the cleanest way of doing this would be to have a more formalized plug-in framework, and the PlugIn.pm file would have not just the new subroutines, but also calls into a "registry" of some sort, to make their presence known.

There are a lot of ways of doing plug-ins, and how you choose to do them is mainly a function of how quickly you want results versus how elegant and maintainable you want the end product to be.

Here's one suggestion: Have each plug-in use its own file, and mandate that each declare a package name, using a common prefix (such as Plugin:: and the file name, just like a "normal" Perl module. We'll call the example one "Print", so the plug-in is in Print.pm and it declares "package Plugin::Print;" near the top. Additionally, require that the plug-in have a common entry-point routine, much like Apache location handlers default to the name "handler". Call this one "run", for example. Now, we have a file with a known package name (it can be derived from the file name) and a known subroutine entry-point (Plugin::Print::run). Your configuration script now needs only to point to the Print.pm file, and you know that (a) you have to load it in, and (b) the button you create should have the "-command" option point to \&Plugin::Print::run.

This is one way. It has benefits and drawbacks. I encourage you to look at other solutions, as well.

--rjray


In reply to Re: Dynamic Tk buttons from init file by rjray
in thread Dynamic Tk buttons from init file by TunesMan

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.