NAME

Module::ExtractUse - Find out what are modules are used

SYNOPSIS

use Module::ExtractUse;

# get a parser
my $p=Module::ExtractUse->new;

# parse from a file
$p->extract_use('/path/to/module.pm');

# or parse from a ref to a string in memory
$p->extract_use(\$string_containg_code);

# use some reporting methods
my @uses=$p->array;
my $uses=$p->string;

DESCRIPTION

Module::ExtractUse is basically a Parse::RecDescent grammar to parse Perl code. It tries very hard to find all modules (whether pragmas, Core, or from CPAN) used by the parsed code.

"Usage" is defined by either calling use or require.

Methods

  • new

    Returns a parser object

  • extract_use($module)

    Runs the parser.

    $module can be either a SCALAR, in which case Module::ExtractUse tries to open the file specified in $module. Or a reference to a SCALAR, in which case Module::ExtractUse assumes the referenced scalar contains the source code.

    The code will be stripped from POD (using a quickly hacked POD-Remover based on Pod::Simple, that should go away as soon as this hack is included in Pod::Simple).

    Afterwards, the code will be parsed an the result stored to some save interal place.

Accessor Methods

Those are various ways to get at the result of the parse.

Note that extract_use returns the parser object, so you can say

print $p->extract_use($module)->string;
  • string($seperator)

    Returns a string of all used modules, joined using the value of $seperator or using a blank space as a default;

  • array

    Returns an array of all used modules.

  • arrayref

    Returns a reference to an array of all used modules. Surprise!

  • hashref

    Returns a reference to an hash of all used modules.

    Keys are the names of the modules, values are the number of times they were used.

RE-COMPILING THE GRAMMAR

If - for some reasons - you need to alter the grammar, edit the file grammar and afterwards run:

perl -MParse::RecDescent - grammar Module::ExtractUseGrammar

EXPORT

Nothing.

AUTHOR

Thomas Klausner <domm@zsi.at>

SEE ALSO

Parse::RecDescent, Module::ScanDeps, Module::Info