Oh great and venerable monks, I come to ye with a question of great significance.

I was wondering about discovering modules that have been previously loaded. In the codebase that I work to maintain and develop, we have a database access layer that consists of 150+ table wrappers that all are all sub-classed from a common class (let's call it A).

We have a script that will crawl the codebase directory structure to generate a Classes.pm that simply is a big list of 'use' statements for all of these table wrappers.

It would be beneficial if we had a way of getting the list of all loaded modules at run time without have to crawl a directory structure or parse any code files.

I have already worked out a way to determine whether or not a given module inherits from another. Now the question becomes, how can I get a listing of all modules that have been loaded?

I know that I could modify the script that produces the Classes.pm to also produce a list that is accessible from outside the package, and that would work for my purposes.

However, in thinking about about this problem I became interested to see what you guys would come up with in regards to the more general problem of discovering ALL modules that have been loaded.

One thought is to use %INC but that yields entries such as

'ICA/DB/Object/Facility.pm' => '/opt/A3AE/lib/ICA/DB/Object/ +Facility.pm', 'ICA/DB/Vault/Aggregator.pm' => '/opt/A3AE/lib/ICA/DB/Vault/ +Aggregator.pm',

And as we all know, perl allows you to have multiple packages in the same file, so the conventional mapping between 'ICA/DB/Object/Facility.pm' and 'ICA::DB::Object::Facility' cannot always be trusted.

I look forward to reading your responses.

¥peace from CaMelRyder¥

In reply to Discovering Loaded Modules by CaMelRyder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.