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

I'm wondering, if there's any way to find out what packages have been compiled by now?

The task I was solving, is to find all packages, whose name start with Foo::.
Wrong solution: to require all Foo/*.pm modules. What if module contains more than one package? Or when package has been evaled at runtime?

For now I place each package in separate module, but the question still remains.

Replies are listed 'Best First'.
Re: What packages are compiled?
by PodMaster (Abbot) on Dec 08, 2005 at 10:42 UTC
    Try Devel::Symdump

    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 packages are compiled?
by rinceWind (Monsignor) on Dec 08, 2005 at 13:42 UTC

    Looks like there are several answers depending on what you want to do. There is a distinction between package namespaces, modules and distributions.

    If you are wanting to take a snapshot of all namespaces that have been used, at a particular point during execution, you can, as PodMaster has suggested, use Devel::Symdump. Or you can walk through the symbol table yourself:

    all_below('Foo::'); sub all_below { my $ns = shift; no strict 'refs'; ( $ns, map { (/::$/ && !/main::/) ? all_below($ns.$_) : () } keys %$ns ); }

    But if you are looking at determining dependencies without running any code, this won't include everything, but Module::ScanDeps has a good attempt at finding everything used or required.

    As you pointed out, any .pm module can potentially put stuff into any namespace, and it's a matter of convention and etiquette that we don't lose control of namespaces.

    In terms of distributions, the META.yml and the .packlist file (written by make install) list out which .pm modules are installed by a distribution.

    Hope this helps.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

      Thank you and PodMaster, I followed your advices. Moreover, I rethought the design and put restriction for myself: to preload all Foo::Basic::* modules with use Foo. I't all kind of plugins (Foo::Plugin::*), with overloading basic system functionality (Foo::Basic::*), so this way I always know what Foo::Plugin::* modules to search (for each Foo::Basic::*) to try to require them.