NAME
Module::Info - Information about Perl modules
SYNOPSIS
use Module::Info;
my $mod = Module::Info->new_from_file('Some/Module.pm');
my $mod = Module::Info->new_from_module('Some::Module');
my $mod = Module::Info->new_from_loaded('Some::Module');
my @mods = Module::Info->all_installed('Some::Module');
my $name = $mod->name;
my $version = $mod->version;
my $dir = $mod->inc_dir;
my $file = $mod->file;
my $is_core = $mod->is_core;
# Only available in perl 5.6.1 and up.
# These do compile the module.
my @packages = $mod->packages_inside;
my @used = $mod->modules_used;
my @subs = $mod->subroutines;
DESCRIPTION
Module::Info gives you information about Perl modules without actually loading the module.
METHODS
Constructors
There are a few ways to specify which module you want information for. They all return Module::Info objects.
- new_from_file
-
my $module = Module::Info->new_from_file('path/to/Some/Module.pm');Given a file, it will interpret this as the module you want information about.
If the file doesn't exist or isn't readable it will return false.
- new_from_module
-
my $module = Module::Info->new_from_module('Some::Module'); my $module = Module::Info->new_from_module('Some::Module', @INC);Given a module name, @INC will be searched and the first module found used. This is the same module that would be loaded if you just say
use Some::Module.If you give your own @INC, that will be used to search instead.
- new_from_loaded
-
my $module = Module::Info->new_from_loaded('Some::Module');Gets information about the currently loaded version of Some::Module. If it isn't loaded, returns false.
- all_installed
-
my @modules = Module::Info->all_installed('Some::Module'); my @modules = Module::Info->all_installed('Some::Module', @INC);Like new_from_module(), except all modules in @INC will be returned, in the order they are found. Thus $modules[0] is the one that would be loaded by
use Some::Module.
Information without loading
The following methods get their information without actually compiling the module.
- name
-
my $name = $module->name;Name of the module (ie. Some::Module). Module loaded using new_from_file() won't have this information.
- version
-
my $version = $module->version;Divines the value of $VERSION. This uses the same method as ExtUtils::MakeMaker and all caveats therein apply.
- inc_dir
-
my $dir = $module->inc_dir;Include directory in which this module was found. Module::Info objects created with new_from_file() won't have this info.
- file
-
my $file = $module->file;The absolute path to this module.
- is_core
-
my $is_core = $module->is_core;Checks if this module is the one distributed with Perl.
NOTE This goes by what directory it's in. It's possible that the module has been altered or upgraded from CPAN since the original Perl installation.
Information that requires loading.
WARNING! From here down reliability drops rapidly!
The following methods get their information by compiling the module and examining the opcode tree. The module will be compiled in a seperate process so as not to disturb the current program.
They will only work on 5.6.1 and up and requires the B::Utils module.
- packages_inside
-
my @packages = $module->packages_inside;Looks for any explicit
packagedeclarations inside the module and returns a list. Useful for finding hidden classes and functionality (like Tie::StdHandle inside Tie::Handle).KNOWN BUG Currently doesn't spot package changes inside subroutines.
- modules_used
-
my @used = $module->modules_used;Returns a list of all modules and files which may be
use'd orrequire'd by this module.NOTE These modules may be conditionally loaded, can't tell. Also can't find modules which might be used inside an
eval. - subroutines
-
my %subs = $module->subroutines;Returns a hash of all subroutines defined inside this module and some info about it. The key is the *full* name of the subroutine (ie. $subs{'Some::Module::foo'} rather than just $subs{'foo'}), value is a hash ref with information about the subroutine like so:
start => line number of the first statement in the subroutine end => line number of the last statement in the subroutineNote that the line numbers may not be entirely accurate and will change as perl's backend compiler improves. They typically correspond to the first and last run-time statements in a subroutine. For example:
sub foo { package Wibble; $foo = "bar"; return $foo; }Taking
sub foo {as line 1, Module::Info will report line 3 as the start and line 4 as the end.package Wibble;is a compile-time statement. Again, this will change as perl changes.Note this only catches simple
sub foo {...}subroutine declarations. Anonymous, autoloaded or eval'd subroutines are not listed.
AUTHOR
Michael G Schwern <schwern@pobox.com> with code from ExtUtils::MM_Unix and Module::InstalledVersion.
CAVEATS
Code refs in @INC are currently ignored. If this bothers you submit a patch.