Dear Monks
I'm writing a set of modules, which I will group in, let say, package ABC.
Now, I've a script abc.pl that I can call like:
abc.pl -h (help). It should tell me what modules are available to format its output. So here is the problem, if I have two modules inside ABC:
ABC::plot_XML.pm
ABC::plot_BLABLA.pm
How can abc.pl dynamically determine what modules are available (plot_*) ?
I don't want to hardcode this inside abc.pl, because I might add other modules in a later stage.
Any suggestions ?
Thanks a lot
Luca
Re: what modules are available in Package
Check out
Module::Pluggable
-Lee
"To be civilized is to deny one's nature."
Re^2: what modules are available in Package
Hmmm,
I think I see a problem, I don't have a file called ABC.pm......... ?!?
What I wanted to do was to put/install a bunch of modules in one directory, called 'ABC'.....
Do I need a file called ABC.pm ? if yes what should be in there ?
Is Module::Pluggable still useful ?
Luca
Re^3: what modules are available in Package
Don't have any personal experience with it, but don't see why you would. Worst case, you can specify the dirs for it to look in according to the docs.
You could use PodMaster's method too. I just figured using plugins is more suited to what you're trying to do.
-Lee
"To be civilized is to deny one's nature."
Re: what modules are available in Package
use
ExtUtils::Installed or
Combine File::Find and @INC and //.
| MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!" |
| I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README). |
| ** The third rule of perl club is a statement of fact: pod is sexy. |
Re: what modules are available in Package
I think I know what you're looking for, but there are a couple of problems to resolve, first.
Let's start with how you name modules. Given the two names you have (ABC::plot_XML.pm and ABC::plot_BLABLA.pm), here's what you need:
- A directory somewhere in @INC (which usually includes '.') named 'ABC'
- Two files in that directory, named 'plot_XML.pm' and 'plot_BLABLA.pm'
- These files have statements package ABC::plot_XML.pm; and package ABC::plot_BLABLA.pm, respectively.
I suggest a quick review of [doc://perlmod], as it covers the basics nicely.
Now, to find which 'ABC' modules are available from within your script 'abc.pl', you can use [cpan://Module::Find]:
use Module::Find;
# my @found = findsubmod('ABC'); #if you want all ABC::* modules
my @found = grep { m/^ABC::plot_/ } findsubmod('ABC'); #all ABC::plot_* modules