Keep It Simple, Stupid | |
PerlMonks |
Re: Dynamic Tk buttons from init fileby rjray (Chaplain) |
on Mar 19, 2003 at 23:42 UTC ( [id://244491]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|