-
-
06 Mar 2017 11:54:15 UTC
- Distribution: Module-Data
- Module version: 0.013
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (0)
- Testers (2815 / 27 / 0)
- Kwalitee
Bus factor: 0- 92.47% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (30.35KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
David Steinbrunner
Why not adopt me?
This distribution is up for adoption! If you're interested then please contact the PAUSE module admins via email.NAME
Module::Data - Introspect context information about modules in @INC
VERSION
version 0.013
SYNOPSIS
use Module::Data; my $d = Module::Data->new( 'Package::Stash' ); $d->path; # returns the path to where Package::Stash was found in @INC $d->root; # returns the root directory in @INC that 'Package::Stash' was found inside. # Convenient trick to discern if you're in a development environment my $d = Module::Data->new( 'Module::Im::Developing' ); if ( -e $d->root->parent->subdir('share') ) { # Yep, this dir exists, so we're in a dev context. # because we know in the development context all modules are in lib/*/* # so if the modules are anywhere else, its not a dev context. # see File::ShareDir::ProjectDistDir for more. } # Helpful sugar. my $v = $d->version;
METHODS
package
Returns the package the
Module::Data
instance was created for. In essence, this will just return the value you passed duringnew
, nothing more, nothing less.my $package = $md->package
loaded
Check to see if the module is already recorded as being loaded in
%INC
if ( $md->loaded ) { say "$md was loaded"; }
require
Require the module be loaded into memory and the global stash.
my $mod = Module::Data->new( 'Foo' ); # nothing much happens. $mod->require; # like 'require Foo';
Returns the "package" name itself for convenience so you can do
my $mod = Module::Data->new('Foo'); $mod->require->new( %args );
path
A Path::Tiny object with the absolute path to the found module.
my $md = Module::Data->new( 'Foo' ); my $path = $md->path;
$path
is computed optimistically. If the "package" is listed as being "loaded", then it asks%INC
for where it was found, otherwise, the path is resolved by simulatingperl
's path look up in@INC
viaPath::ScanINC
.root
Returns the base directory of the tree the module was found at. ( Probably from @INC );
local @INC = ( "somewhere/asinine/", "somewhere/in/space/", # Where Lib::Foo::Bar is "somethingelse/", ); my $md = Module::Data->new( "Lib::Foo::Bar"); $md->path ; # somewhere/in/space/Lib/Foo/Bar.pm my $root = $md->root # somewhere/in/space
version
If the module appears to be already loaded in memory:
my $v = $md->version;
is merely shorthand for $package->VERSION;
However, if the module is not loaded into memory, all efforts to extract the value without loading the code permanently are performed.
Here, this means we compute the path to the file manually ( see "path" ) and parse the file with
Module::Metadata
to statically extract$VERSION
.This means you can unleash this code on your entire installed module tree, while incurring no permanent memory gain as you would normally incur if you were to
require
them all.AUTHOR
Kent Fredric <kentnl@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Kent Fredric <kentnl@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install Module::Data, copy and paste the appropriate command in to your terminal.
cpanm Module::Data
perl -MCPAN -e shell install Module::Data
For more information on module installation, please visit the detailed CPAN module installation guide.