Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

what modules are available in Package

by jeanluca (Deacon)
on Mar 03, 2006 at 13:24 UTC ( [id://534223]=perlquestion: print w/replies, xml ) Need Help??

jeanluca has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: what modules are available in Package
by shotgunefx (Parson) on Mar 03, 2006 at 13:40 UTC
      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
        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
by PodMaster (Abbot) on Mar 03, 2006 at 13:40 UTC
    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
by radiantmatrix (Parson) on Mar 03, 2006 at 15:56 UTC

    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:

    1. A directory somewhere in @INC (which usually includes '.') named 'ABC'
    2. Two files in that directory, named 'plot_XML.pm' and 'plot_BLABLA.pm'
    3. These files have statements package ABC::plot_XML.pm; and package ABC::plot_BLABLA.pm, respectively.

    I suggest a quick review of perlmod, as it covers the basics nicely.

    Now, to find which 'ABC' modules are available from within your script 'abc.pl', you can use 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
    <-radiant.matrix->
    A collection of thoughts and links from the minds of geeks
    The Code that can be seen is not the true Code
    I haven't found a problem yet that can't be solved by a well-placed trebuchet

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://534223]
Approved by shotgunefx
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-04-23 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found