|No such thing as a small change|
Redefine package subroutinesby Melly (Hermit)
|on Dec 19, 2012 at 09:28 UTC||Need Help??|
Melly has asked for the
wisdom of the Perl Monks concerning the following question:
I have a perl program that I'm rewriting to accommodate the growing list of requirements.
One thing I want/need to do is to have 3 different packages containing subroutines with, potentially, the same names (not a problem).
I will have a global package, GP, a local package, LP, and a file package, FP, so that people can call GP::format_date, or LP::format_date, etc.
My problem is the FP package. GP and LP are loaded at run-time, but FP needs to have its routines reloaded during the program's duration (basically, everytime I switch to a new file, I want to initialise and repopulate FP with routines defined in filename.lib
Another nice feature (although not essential) would be to allow the user NOT to specify the package name, and have the program default to FP::routine if it exists, then LP::routine if it exists, before finally defaulting to GP::routine (and returning an error if the routine doesn't exist in any package). I would also need the user to be able to over-ride this by explicitly specifying the package...
As I said, the last requirement is not essential - I can always require the users to specify the package, but it would be nice.
Tom Melly, pm (at) cursingmaggot (stop) co (stop) uk