1Module::Data(3)       User Contributed Perl Documentation      Module::Data(3)
2
3
4

NAME

6       Module::Data - Introspect context information about modules in @INC
7

VERSION

9       version 0.013
10

SYNOPSIS

12               use Module::Data;
13
14               my $d = Module::Data->new( 'Package::Stash' );
15
16               $d->path; # returns the path to where Package::Stash was found in @INC
17
18               $d->root; # returns the root directory in @INC that 'Package::Stash' was found inside.
19
20               # Convenient trick to discern if you're in a development environment
21
22               my $d = Module::Data->new( 'Module::Im::Developing' );
23
24               if ( -e $d->root->parent->subdir('share') ) {
25                       # Yep, this dir exists, so we're in a dev context.
26                       # because we know in the development context all modules are in lib/*/*
27                       # so if the modules are anywhere else, its not a dev context.
28                       # see File::ShareDir::ProjectDistDir for more.
29               }
30
31               # Helpful sugar.
32
33               my $v = $d->version;
34

METHODS

36   package
37       Returns the package the "Module::Data" instance was created for. In
38       essence, this will just return the value you passed during "new",
39       nothing more, nothing less.
40
41               my $package = $md->package
42
43   loaded
44       Check to see if the module is already recorded as being loaded in %INC
45
46               if ( $md->loaded ) {
47                       say "$md was loaded";
48               }
49
50   require
51       Require the module be loaded into memory and the global stash.
52
53         my $mod = Module::Data->new( 'Foo' ); # nothing much happens.
54         $mod->require; # like 'require Foo';
55
56       Returns the "package" name itself for convenience so you can do
57
58         my $mod = Module::Data->new('Foo');
59         $mod->require->new( %args );
60
61   path
62       A Path::Tiny object with the absolute path to the found module.
63
64               my $md = Module::Data->new( 'Foo' );
65               my $path = $md->path;
66
67       $path is computed optimistically. If the "package" is listed as being
68       "loaded", then it asks %INC for where it was found, otherwise, the path
69       is resolved by simulating "perl"'s path look up in @INC via
70       "Path::ScanINC".
71
72   root
73       Returns the base directory of the tree the module was found at.  (
74       Probably from @INC );
75
76               local @INC = (
77                       "somewhere/asinine/",
78                       "somewhere/in/space/",   # Where Lib::Foo::Bar is
79                       "somethingelse/",
80               );
81               my $md = Module::Data->new( "Lib::Foo::Bar");
82               $md->path ; # somewhere/in/space/Lib/Foo/Bar.pm
83               my $root = $md->root # somewhere/in/space
84
85   version
86       If the module appears to be already loaded in memory:
87
88               my $v = $md->version;
89
90       is merely shorthand for $package->VERSION;
91
92       However, if the module is not loaded into memory, all efforts to
93       extract the value without loading the code permanently are performed.
94
95       Here, this means we compute the path to the file manually ( see "path"
96       ) and parse the file with "Module::Metadata" to statically extract
97       $VERSION.
98
99       This means you can unleash this code on your entire installed module
100       tree, while incurring no permanent memory gain as you would normally
101       incur if you were to "require" them all.
102

AUTHOR

104       Kent Fredric <kentnl@cpan.org>
105
107       This software is copyright (c) 2017 by Kent Fredric <kentnl@cpan.org>.
108
109       This is free software; you can redistribute it and/or modify it under
110       the same terms as the Perl 5 programming language system itself.
111
112
113
114perl v5.30.0                      2019-07-26                   Module::Data(3)
Impressum