1Module::Extract::NamespUasceers(C3o)ntributed Perl DocumMeondtualtei:o:nExtract::Namespaces(3)
2
3
4

NAME

6       Module::Extract::Namespaces - extract the package declarations from a
7       module
8

SYNOPSIS

10               use Module::Extract::Namespaces;
11
12               # in scalar context, extract first package namespace
13               my $namespace  = Module::Extract::Namespaces->from_file( $filename );
14               if( Module::Extract::Namespaces->error ) { ... }
15
16               # in list context, extract all namespaces
17               my @namespaces = Module::Extract::Namespaces->from_file( $filename );
18               if( Module::Extract::Namespaces->error ) { ... }
19
20               # can do the Perl 5.12 package syntax with possible versions
21               # in list context, extract all namespaces and versions as duples
22               my @namespaces = Module::Extract::Namespaces->from_file( $filename, 1 );
23               if( Module::Extract::Namespaces->error ) { ... }
24

DESCRIPTION

26       This module extracts package declarations from Perl code without
27       running the code.
28
29       It does not extract:
30
31       •   packages declared dynamically (e.g. in "eval")
32
33       •   packages created as part of a fully qualified variable name
34
35   Class methods
36       from_module( MODULE, [ @DIRS ] )
37           Extract the namespaces declared in MODULE. In list context, it
38           returns all of the namespaces, including possible duplicates. In
39           scalar context it returns the first declared namespace.
40
41           You can specify a list of directories to search for the module. If
42           you don't, it uses @INC by default.
43
44           If it cannot find MODULE, it returns undef in scalar context and
45           the empty list in list context.
46
47           On failure it returns nothing, but you have to check with "error"
48           to see if that is really an error or a file with no namespaces in
49           it.
50
51       from_file( FILENAME [,WITH_VERSIONS] )
52           Extract the namespaces declared in FILENAME. In list context, it
53           returns all of the namespaces, including possible duplicates. In
54           scalar context it returns the first declared namespace.
55
56           If FILENAME does not exist, it returns undef in scalar context and
57           the empty list in list context.
58
59           On failure it returns nothing, but you have to check with "error"
60           to see if that is really an error or a file with no namespaces in
61           it.
62
63   Subclassable hooks
64       $class->pdom_base_class()
65           Return the base class for the PDOM. This is "PPI" by default. If
66           you want to use something else, you'll have to change all the other
67           PDOM methods to adapt to the different interface.
68
69           This is the class name to use with "require" to load the module
70           that while handle the parsing.
71
72       $class->pdom_document_class()
73           Return the class name to use to create the PDOM object. This is
74           "PPI::Document".
75
76       get_pdom( FILENAME )
77           Creates the PDOM from FILENAME. This depends on calls to
78           "pdom_base_class" and "pdom_document_class".
79
80       $class->pdom_preprocess( PDOM )
81           Override this method to play with the PDOM before extracting the
82           package declarations.
83
84           By default, it strips Pod and comments from the PDOM.
85
86       $class->pdom_strip_pod( PDOM )
87           Strips Pod documentation from the PDOM.
88
89       $class->pdom_strip_comments( PDOM )
90           Strips comments from the PDOM.
91
92       $class->get_namespaces_from_pdom( PDOM )
93           Extract the namespaces from the PDOM. It returns a list of package
94           names in the order that it finds them in the PDOM. It does not
95           remove duplicates (do that later if you like).
96
97       $class->get_namespaces_and_versions_from_pdom( PDOM )
98           This extracts version information if the package statement uses the
99           Perl 5.12 syntax:
100
101                   package NAME VERSION BLOCK
102
103           Extract the namespaces from the PDOM. It returns a list anonymous
104           arrays of package names and versions in the order that it finds
105           them in the PDOM. It does not remove duplicates (do that later if
106           you like).
107
108       $class->error
109           Return the error from the last call to "get_modules".
110

TO DO

112       * Add caching based on file digest?
113

SOURCE AVAILABILITY

115       This code is in Github:
116
117               http://github.com/briandfoy/module-extract-namespaces
118

AUTHOR

120       brian d foy, "<bdfoy@cpan.org>"
121
122       This module was partially funded by The Perl Foundation
123       (www.perlfoundation.org) and LogicLAB (www.logiclab.dk), both of whom
124       provided travel assistance to the 2008 Oslo QA Hackathon where I
125       created this module.
126
128       Copyright © 2008-2022, brian d foy <bdfoy@cpan.org>. All rights
129       reserved.
130
131       You may redistribute this under the Artistic License 2.0.
132
133
134
135perl v5.38.0                      2023-07-20    Module::Extract::Namespaces(3)
Impressum