Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Statement/Include.pm |
Statements | Executed 12559 statements in 42.5ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1266 | 3 | 2 | 15.0ms | 40.4ms | version | PPI::Statement::Include::
1410 | 3 | 3 | 14.3ms | 43.0ms | module | PPI::Statement::Include::
1268 | 2 | 2 | 11.0ms | 22.1ms | type | PPI::Statement::Include::
286 | 1 | 1 | 3.63ms | 10.7ms | pragma | PPI::Statement::Include::
144 | 1 | 1 | 416µs | 416µs | CORE:match (opcode) | PPI::Statement::Include::
1 | 1 | 1 | 184µs | 258µs | BEGIN@49 | PPI::Statement::Include::
1 | 1 | 1 | 14µs | 30µs | BEGIN@47 | PPI::Statement::Include::
1 | 1 | 1 | 14µs | 14µs | BEGIN@52 | PPI::Statement::Include::
1 | 1 | 1 | 7µs | 34µs | BEGIN@51 | PPI::Statement::Include::
1 | 1 | 1 | 4µs | 4µs | BEGIN@48 | PPI::Statement::Include::
0 | 0 | 0 | 0s | 0s | arguments | PPI::Statement::Include::
0 | 0 | 0 | 0s | 0s | module_version | PPI::Statement::Include::
0 | 0 | 0 | 0s | 0s | version_literal | PPI::Statement::Include::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package PPI::Statement::Include; | ||||
2 | |||||
3 | =pod | ||||
4 | |||||
5 | =head1 NAME | ||||
6 | |||||
7 | PPI::Statement::Include - Statements that include other code | ||||
8 | |||||
9 | =head1 SYNOPSIS | ||||
10 | |||||
11 | # The following are all includes | ||||
12 | use 5.006; | ||||
13 | use strict; | ||||
14 | use My::Module; | ||||
15 | use constant FOO => 'Foo'; | ||||
16 | require Foo::Bar; | ||||
17 | require "Foo/Bar.pm"; | ||||
18 | require $foo if 1; | ||||
19 | no strict 'refs'; | ||||
20 | |||||
21 | =head1 INHERITANCE | ||||
22 | |||||
23 | PPI::Statement::Include | ||||
24 | isa PPI::Statement | ||||
25 | isa PPI::Node | ||||
26 | isa PPI::Element | ||||
27 | |||||
28 | =head1 DESCRIPTION | ||||
29 | |||||
30 | Despite its name, the C<PPI::Statement::Include> class covers a number | ||||
31 | of different types of statement that cover all statements starting with | ||||
32 | C<use>, C<no> and C<require>. | ||||
33 | |||||
34 | But basically, they cover three situations. | ||||
35 | |||||
36 | Firstly, a dependency on a particular version of perl (for which the | ||||
37 | C<version> method returns true), a pragma (for which the C<pragma> method | ||||
38 | returns true, or the loading (and unloading via no) of modules. | ||||
39 | |||||
40 | =head1 METHODS | ||||
41 | |||||
42 | C<PPI::Statement::Include> has a number of methods in addition to the standard | ||||
43 | L<PPI::Statement>, L<PPI::Node> and L<PPI::Element> methods. | ||||
44 | |||||
45 | =cut | ||||
46 | |||||
47 | 2 | 22µs | 2 | 46µs | # spent 30µs (14+16) within PPI::Statement::Include::BEGIN@47 which was called:
# once (14µs+16µs) by PPI::Statement::BEGIN@167 at line 47 # spent 30µs making 1 call to PPI::Statement::Include::BEGIN@47
# spent 16µs making 1 call to strict::import |
48 | 2 | 17µs | 1 | 4µs | # spent 4µs within PPI::Statement::Include::BEGIN@48 which was called:
# once (4µs+0s) by PPI::Statement::BEGIN@167 at line 48 # spent 4µs making 1 call to PPI::Statement::Include::BEGIN@48 |
49 | 2 | 102µs | 1 | 258µs | # spent 258µs (184+74) within PPI::Statement::Include::BEGIN@49 which was called:
# once (184µs+74µs) by PPI::Statement::BEGIN@167 at line 49 # spent 258µs making 1 call to PPI::Statement::Include::BEGIN@49 |
50 | |||||
51 | 2 | 29µs | 2 | 61µs | # spent 34µs (7+27) within PPI::Statement::Include::BEGIN@51 which was called:
# once (7µs+27µs) by PPI::Statement::BEGIN@167 at line 51 # spent 34µs making 1 call to PPI::Statement::Include::BEGIN@51
# spent 27µs making 1 call to vars::import |
52 | # spent 14µs within PPI::Statement::Include::BEGIN@52 which was called:
# once (14µs+0s) by PPI::Statement::BEGIN@167 at line 55 | ||||
53 | 1 | 300ns | $VERSION = '1.215'; | ||
54 | 1 | 14µs | @ISA = 'PPI::Statement'; | ||
55 | 1 | 406µs | 1 | 14µs | } # spent 14µs making 1 call to PPI::Statement::Include::BEGIN@52 |
56 | |||||
57 | =pod | ||||
58 | |||||
59 | =head2 type | ||||
60 | |||||
61 | The C<type> method returns the general type of statement (C<'use'>, C<'no'> | ||||
62 | or C<'require'>). | ||||
63 | |||||
64 | Returns the type as a string, or C<undef> if the type cannot be detected. | ||||
65 | |||||
66 | =begin testing type 9 | ||||
67 | |||||
68 | my $document = PPI::Document->new(\<<'END_PERL'); | ||||
69 | require 5.6; | ||||
70 | require Module; | ||||
71 | require 'Module.pm'; | ||||
72 | use 5.6; | ||||
73 | use Module; | ||||
74 | use Module 1.00; | ||||
75 | no Module; | ||||
76 | END_PERL | ||||
77 | |||||
78 | isa_ok( $document, 'PPI::Document' ); | ||||
79 | my $statements = $document->find('PPI::Statement::Include'); | ||||
80 | is( scalar(@$statements), 7, 'Found 7 include statements' ); | ||||
81 | my @expected = qw{ require require require use use use no }; | ||||
82 | foreach ( 0 .. 6 ) { | ||||
83 | is( $statements->[$_]->type, $expected[$_], "->type $_ ok" ); | ||||
84 | } | ||||
85 | |||||
86 | =end testing | ||||
87 | |||||
88 | =cut | ||||
89 | |||||
90 | # spent 22.1ms (11.0+11.1) within PPI::Statement::Include::type which was called 1268 times, avg 17µs/call:
# 982 times (8.51ms+8.53ms) by Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict::violates at line 65 of Perl/Critic/Policy/TestingAndDebugging/ProhibitNoStrict.pm, avg 17µs/call
# 286 times (2.53ms+2.56ms) by Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm:116] at line 90 of Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm, avg 18µs/call | ||||
91 | 1268 | 225µs | my $self = shift; | ||
92 | 1268 | 4.48ms | 2536 | 8.42ms | my $keyword = $self->schild(0) or return undef; # spent 7.61ms making 1268 calls to PPI::Node::schild, avg 6µs/call
# spent 808µs making 1268 calls to PPI::Util::TRUE, avg 637ns/call |
93 | 1268 | 6.46ms | 2536 | 2.67ms | $keyword->isa('PPI::Token::Word') and $keyword->content; # spent 1.76ms making 1268 calls to PPI::Token::content, avg 1µs/call
# spent 910µs making 1268 calls to UNIVERSAL::isa, avg 717ns/call |
94 | } | ||||
95 | |||||
96 | =pod | ||||
97 | |||||
98 | =head2 module | ||||
99 | |||||
100 | The C<module> method returns the module name specified in any include | ||||
101 | statement. This C<includes> pragma names, because pragma are implemented | ||||
102 | as modules. (And lets face it, the definition of a pragma can be fuzzy | ||||
103 | at the best of times in any case) | ||||
104 | |||||
105 | This covers all of these... | ||||
106 | |||||
107 | use strict; | ||||
108 | use My::Module; | ||||
109 | no strict; | ||||
110 | require My::Module; | ||||
111 | |||||
112 | ...but does not cover any of these... | ||||
113 | |||||
114 | use 5.006; | ||||
115 | require 5.005; | ||||
116 | require "explicit/file/name.pl"; | ||||
117 | |||||
118 | Returns the module name as a string, or C<undef> if the include does | ||||
119 | not specify a module name. | ||||
120 | |||||
121 | =cut | ||||
122 | |||||
123 | # spent 43.0ms (14.3+28.8) within PPI::Statement::Include::module which was called 1410 times, avg 31µs/call:
# 982 times (10.9ms+20.1ms) by Perl::Critic::Policy::Modules::ProhibitEvilModules::violates at line 246 of Perl/Critic/Policy/Modules/ProhibitEvilModules.pm, avg 32µs/call
# 286 times (2.40ms+4.25ms) by PPI::Statement::Include::pragma at line 202, avg 23µs/call
# 142 times (974µs+4.47ms) by Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm:116] at line 96 of Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm, avg 38µs/call | ||||
124 | 1410 | 290µs | my $self = shift; | ||
125 | 1410 | 5.09ms | 2820 | 26.0ms | my $module = $self->schild(1) or return undef; # spent 25.1ms making 1410 calls to PPI::Node::schild, avg 18µs/call
# spent 916µs making 1410 calls to PPI::Util::TRUE, avg 649ns/call |
126 | 1410 | 11.7ms | 2394 | 2.78ms | $module->isa('PPI::Token::Word') and $module->content; # spent 1.42ms making 1410 calls to UNIVERSAL::isa, avg 1µs/call
# spent 1.36ms making 984 calls to PPI::Token::content, avg 1µs/call |
127 | } | ||||
128 | |||||
129 | =pod | ||||
130 | |||||
131 | =head2 module_version | ||||
132 | |||||
133 | The C<module_version> method returns the minimum version of the module | ||||
134 | required by the statement, if there is one. | ||||
135 | |||||
136 | =begin testing module_version 9 | ||||
137 | |||||
138 | my $document = PPI::Document->new(\<<'END_PERL'); | ||||
139 | use Integer::Version 1; | ||||
140 | use Float::Version 1.5; | ||||
141 | use Version::With::Argument 1 2; | ||||
142 | use No::Version; | ||||
143 | use No::Version::With::Argument 'x'; | ||||
144 | use No::Version::With::Arguments 1, 2; | ||||
145 | use 5.005; | ||||
146 | END_PERL | ||||
147 | |||||
148 | isa_ok( $document, 'PPI::Document' ); | ||||
149 | my $statements = $document->find('PPI::Statement::Include'); | ||||
150 | is( scalar @{$statements}, 7, 'Found expected include statements.' ); | ||||
151 | is( $statements->[0]->module_version, 1, 'Integer version' ); | ||||
152 | is( $statements->[1]->module_version, 1.5, 'Float version' ); | ||||
153 | is( $statements->[2]->module_version, 1, 'Version and argument' ); | ||||
154 | is( $statements->[3]->module_version, undef, 'No version, no arguments' ); | ||||
155 | is( $statements->[4]->module_version, undef, 'No version, with argument' ); | ||||
156 | is( $statements->[5]->module_version, undef, 'No version, with arguments' ); | ||||
157 | is( $statements->[6]->module_version, undef, 'Version include, no module' ); | ||||
158 | |||||
159 | =end testing | ||||
160 | |||||
161 | =cut | ||||
162 | |||||
163 | sub module_version { | ||||
164 | my $self = shift; | ||||
165 | my $argument = $self->schild(3); | ||||
166 | if ( $argument and $argument->isa('PPI::Token::Operator') ) { | ||||
167 | return undef; | ||||
168 | } | ||||
169 | |||||
170 | my $version = $self->schild(2) or return undef; | ||||
171 | return undef unless $version->isa('PPI::Token::Number'); | ||||
172 | |||||
173 | return $version; | ||||
174 | } | ||||
175 | |||||
176 | =pod | ||||
177 | |||||
178 | =head2 pragma | ||||
179 | |||||
180 | The C<pragma> method checks for an include statement's use as a | ||||
181 | pragma, and returns it if so. | ||||
182 | |||||
183 | Or at least, it claims to. In practice it's a lot harder to say exactly | ||||
184 | what is or isn't a pragma, because the definition is fuzzy. | ||||
185 | |||||
186 | The C<intent> of a pragma is to modify the way in which the parser works. | ||||
187 | This is done though the use of modules that do various types of internals | ||||
188 | magic. | ||||
189 | |||||
190 | For now, PPI assumes that any "module name" that is only a set of | ||||
191 | lowercase letters (and perhaps numbers, like C<use utf8;>). This | ||||
192 | behaviour is expected to change, most likely to something that knows | ||||
193 | the specific names of the various "pragmas". | ||||
194 | |||||
195 | Returns the name of the pragma, or false ('') if the include is not a | ||||
196 | pragma. | ||||
197 | |||||
198 | =cut | ||||
199 | |||||
200 | # spent 10.7ms (3.63+7.07) within PPI::Statement::Include::pragma which was called 286 times, avg 37µs/call:
# 286 times (3.63ms+7.07ms) by Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm:116] at line 96 of Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm, avg 37µs/call | ||||
201 | 286 | 95µs | my $self = shift; | ||
202 | 286 | 875µs | 286 | 6.65ms | my $module = $self->module or return ''; # spent 6.65ms making 286 calls to PPI::Statement::Include::module, avg 23µs/call |
203 | 144 | 1.09ms | 144 | 416µs | $module =~ /^[a-z][a-z\d]*$/ ? $module : ''; # spent 416µs making 144 calls to PPI::Statement::Include::CORE:match, avg 3µs/call |
204 | } | ||||
205 | |||||
206 | =pod | ||||
207 | |||||
208 | =head2 version | ||||
209 | |||||
210 | The C<version> method checks for an include statement that introduces a | ||||
211 | dependency on the version of C<perl> the code is compatible with. | ||||
212 | |||||
213 | This covers two specific statements. | ||||
214 | |||||
215 | use 5.006; | ||||
216 | require 5.006; | ||||
217 | |||||
218 | Currently the version is returned as a string, although in future the version | ||||
219 | may be returned as a L<version> object. If you want a numeric representation, | ||||
220 | use C<version_literal()>. Returns false if the statement is not a version | ||||
221 | dependency. | ||||
222 | |||||
223 | =begin testing version 13 | ||||
224 | |||||
225 | my $document = PPI::Document->new(\<<'END_PERL'); | ||||
226 | # Examples from perlfunc in 5.10. | ||||
227 | use v5.6.1; | ||||
228 | use 5.6.1; | ||||
229 | use 5.006_001; | ||||
230 | use 5.006; use 5.6.1; | ||||
231 | |||||
232 | # Same, but using require. | ||||
233 | require v5.6.1; | ||||
234 | require 5.6.1; | ||||
235 | require 5.006_001; | ||||
236 | require 5.006; require 5.6.1; | ||||
237 | |||||
238 | # Module. | ||||
239 | use Float::Version 1.5; | ||||
240 | END_PERL | ||||
241 | |||||
242 | isa_ok( $document, 'PPI::Document' ); | ||||
243 | my $statements = $document->find('PPI::Statement::Include'); | ||||
244 | is( scalar @{$statements}, 11, 'Found expected include statements.' ); | ||||
245 | |||||
246 | is( $statements->[0]->version, 'v5.6.1', 'use v-string' ); | ||||
247 | is( $statements->[1]->version, '5.6.1', 'use v-string, no leading "v"' ); | ||||
248 | is( $statements->[2]->version, '5.006_001', 'use developer release' ); | ||||
249 | is( $statements->[3]->version, '5.006', 'use back-compatible version, followed by...' ); | ||||
250 | is( $statements->[4]->version, '5.6.1', '... use v-string, no leading "v"' ); | ||||
251 | |||||
252 | is( $statements->[5]->version, 'v5.6.1', 'require v-string' ); | ||||
253 | is( $statements->[6]->version, '5.6.1', 'require v-string, no leading "v"' ); | ||||
254 | is( $statements->[7]->version, '5.006_001', 'require developer release' ); | ||||
255 | is( $statements->[8]->version, '5.006', 'require back-compatible version, followed by...' ); | ||||
256 | is( $statements->[9]->version, '5.6.1', '... require v-string, no leading "v"' ); | ||||
257 | |||||
258 | is( $statements->[10]->version, '', 'use module version' ); | ||||
259 | |||||
260 | =end testing | ||||
261 | |||||
262 | =cut | ||||
263 | |||||
264 | # spent 40.4ms (15.0+25.4) within PPI::Statement::Include::version which was called 1266 times, avg 32µs/call:
# 982 times (12.0ms+17.8ms) by Perl::Critic::Document::_is_a_version_statement at line 496 of Perl/Critic/Document.pm, avg 30µs/call
# 142 times (1.55ms+4.89ms) by Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm:116] at line 96 of Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm, avg 45µs/call
# 142 times (1.44ms+2.76ms) by Perl::Critic::Document::highest_explicit_perl_version at line 375 of Perl/Critic/Document.pm, avg 30µs/call | ||||
265 | 1266 | 284µs | my $self = shift; | ||
266 | 1266 | 4.54ms | 2532 | 23.4ms | my $version = $self->schild(1) or return undef; # spent 22.6ms making 1266 calls to PPI::Node::schild, avg 18µs/call
# spent 798µs making 1266 calls to PPI::Util::TRUE, avg 631ns/call |
267 | 1266 | 6.73ms | 1692 | 2.04ms | $version->isa('PPI::Token::Number') ? $version->content : ''; # spent 1.34ms making 1266 calls to UNIVERSAL::isa, avg 1µs/call
# spent 709µs making 426 calls to PPI::Token::content, avg 2µs/call |
268 | } | ||||
269 | |||||
270 | =pod | ||||
271 | |||||
272 | =head2 version_literal | ||||
273 | |||||
274 | The C<version_literal> method has the same behavior as C<version()>, but the | ||||
275 | version is returned as a numeric literal. Returns false if the statement is | ||||
276 | not a version dependency. | ||||
277 | |||||
278 | =begin testing version_literal 13 | ||||
279 | |||||
280 | my $document = PPI::Document->new(\<<'END_PERL'); | ||||
281 | # Examples from perlfunc in 5.10. | ||||
282 | use v5.6.1; | ||||
283 | use 5.6.1; | ||||
284 | use 5.006_001; | ||||
285 | use 5.006; use 5.6.1; | ||||
286 | |||||
287 | # Same, but using require. | ||||
288 | require v5.6.1; | ||||
289 | require 5.6.1; | ||||
290 | require 5.006_001; | ||||
291 | require 5.006; require 5.6.1; | ||||
292 | |||||
293 | # Module. | ||||
294 | use Float::Version 1.5; | ||||
295 | END_PERL | ||||
296 | |||||
297 | isa_ok( $document, 'PPI::Document' ); | ||||
298 | my $statements = $document->find('PPI::Statement::Include'); | ||||
299 | is( scalar @{$statements}, 11, 'Found expected include statements.' ); | ||||
300 | |||||
301 | is( $statements->[0]->version_literal, v5.6.1, 'use v-string' ); | ||||
302 | is( $statements->[1]->version_literal, 5.6.1, 'use v-string, no leading "v"' ); | ||||
303 | is( $statements->[2]->version_literal, 5.006_001, 'use developer release' ); | ||||
304 | is( $statements->[3]->version_literal, 5.006, 'use back-compatible version, followed by...' ); | ||||
305 | is( $statements->[4]->version_literal, 5.6.1, '... use v-string, no leading "v"' ); | ||||
306 | |||||
307 | is( $statements->[5]->version_literal, v5.6.1, 'require v-string' ); | ||||
308 | is( $statements->[6]->version_literal, 5.6.1, 'require v-string, no leading "v"' ); | ||||
309 | is( $statements->[7]->version_literal, 5.006_001, 'require developer release' ); | ||||
310 | is( $statements->[8]->version_literal, 5.006, 'require back-compatible version, followed by...' ); | ||||
311 | is( $statements->[9]->version_literal, 5.6.1, '... require v-string, no leading "v"' ); | ||||
312 | |||||
313 | is( $statements->[10]->version_literal, '', 'use module version' ); | ||||
314 | |||||
315 | =end testing | ||||
316 | |||||
317 | =cut | ||||
318 | |||||
319 | sub version_literal { | ||||
320 | my $self = shift; | ||||
321 | my $version = $self->schild(1) or return undef; | ||||
322 | $version->isa('PPI::Token::Number') ? $version->literal : ''; | ||||
323 | } | ||||
324 | |||||
325 | =pod | ||||
326 | |||||
327 | The C<arguments> method gives you the rest of the statement after the the | ||||
328 | module/pragma and module version, i.e. the stuff that will be used to | ||||
329 | construct what gets passed to the module's C<import()> subroutine. This does | ||||
330 | include the comma, etc. operators, but doesn't include non-significant direct | ||||
331 | children or any final semicolon. | ||||
332 | |||||
333 | =begin testing arguments 19 | ||||
334 | |||||
335 | my $document = PPI::Document->new(\<<'END_PERL'); | ||||
336 | use 5.006; # Don't expect anything. | ||||
337 | use Foo; # Don't expect anything. | ||||
338 | use Foo 5; # Don't expect anything. | ||||
339 | use Foo 'bar'; # One thing. | ||||
340 | use Foo 5 'bar'; # One thing. | ||||
341 | use Foo qw< bar >, "baz"; | ||||
342 | use Test::More tests => 5 * 9 # Don't get tripped up by the lack of the ";" | ||||
343 | END_PERL | ||||
344 | |||||
345 | isa_ok( $document, 'PPI::Document' ); | ||||
346 | my $statements = $document->find('PPI::Statement::Include'); | ||||
347 | is( scalar @{$statements}, 7, 'Found expected include statements.' ); | ||||
348 | |||||
349 | is( | ||||
350 | scalar $statements->[0]->arguments, undef, 'arguments for perl version', | ||||
351 | ); | ||||
352 | is( | ||||
353 | scalar $statements->[1]->arguments, | ||||
354 | undef, | ||||
355 | 'arguments with no arguments', | ||||
356 | ); | ||||
357 | is( | ||||
358 | scalar $statements->[2]->arguments, | ||||
359 | undef, | ||||
360 | 'arguments with no arguments but module version', | ||||
361 | ); | ||||
362 | |||||
363 | my @arguments = $statements->[3]->arguments; | ||||
364 | is( scalar @arguments, 1, 'arguments with single argument' ); | ||||
365 | is( $arguments[0]->content, q<'bar'>, 'arguments with single argument' ); | ||||
366 | |||||
367 | @arguments = $statements->[4]->arguments; | ||||
368 | is( | ||||
369 | scalar @arguments, | ||||
370 | 1, | ||||
371 | 'arguments with single argument and module version', | ||||
372 | ); | ||||
373 | is( | ||||
374 | $arguments[0]->content, | ||||
375 | q<'bar'>, | ||||
376 | 'arguments with single argument and module version', | ||||
377 | ); | ||||
378 | |||||
379 | @arguments = $statements->[5]->arguments; | ||||
380 | is( | ||||
381 | scalar @arguments, | ||||
382 | 3, | ||||
383 | 'arguments with multiple arguments', | ||||
384 | ); | ||||
385 | is( | ||||
386 | $arguments[0]->content, | ||||
387 | q/qw< bar >/, | ||||
388 | 'arguments with multiple arguments', | ||||
389 | ); | ||||
390 | is( | ||||
391 | $arguments[1]->content, | ||||
392 | q<,>, | ||||
393 | 'arguments with multiple arguments', | ||||
394 | ); | ||||
395 | is( | ||||
396 | $arguments[2]->content, | ||||
397 | q<"baz">, | ||||
398 | 'arguments with multiple arguments', | ||||
399 | ); | ||||
400 | |||||
401 | @arguments = $statements->[6]->arguments; | ||||
402 | is( | ||||
403 | scalar @arguments, | ||||
404 | 5, | ||||
405 | 'arguments with Test::More', | ||||
406 | ); | ||||
407 | is( | ||||
408 | $arguments[0]->content, | ||||
409 | 'tests', | ||||
410 | 'arguments with Test::More', | ||||
411 | ); | ||||
412 | is( | ||||
413 | $arguments[1]->content, | ||||
414 | q[=>], | ||||
415 | 'arguments with Test::More', | ||||
416 | ); | ||||
417 | is( | ||||
418 | $arguments[2]->content, | ||||
419 | 5, | ||||
420 | 'arguments with Test::More', | ||||
421 | ); | ||||
422 | is( | ||||
423 | $arguments[3]->content, | ||||
424 | '*', | ||||
425 | 'arguments with Test::More', | ||||
426 | ); | ||||
427 | is( | ||||
428 | $arguments[4]->content, | ||||
429 | 9, | ||||
430 | 'arguments with Test::More', | ||||
431 | ); | ||||
432 | |||||
433 | =end testing | ||||
434 | |||||
435 | =cut | ||||
436 | |||||
437 | sub arguments { | ||||
438 | my $self = shift; | ||||
439 | my @args = $self->schildren; | ||||
440 | |||||
441 | # Remove the "use", "no" or "require" | ||||
442 | shift @args; | ||||
443 | |||||
444 | # Remove the statement terminator | ||||
445 | if ( | ||||
446 | $args[-1]->isa('PPI::Token::Structure') | ||||
447 | and | ||||
448 | $args[-1]->content eq ';' | ||||
449 | ) { | ||||
450 | pop @args; | ||||
451 | } | ||||
452 | |||||
453 | # Remove the module or perl version. | ||||
454 | shift @args; | ||||
455 | |||||
456 | return unless @args; | ||||
457 | |||||
458 | if ( $args[0]->isa('PPI::Token::Number') ) { | ||||
459 | my $after = $args[1] or return; | ||||
460 | $after->isa('PPI::Token::Operator') or shift @args; | ||||
461 | } | ||||
462 | |||||
463 | return @args; | ||||
464 | } | ||||
465 | |||||
466 | 1 | 2µs | 1; | ||
467 | |||||
468 | =pod | ||||
469 | |||||
470 | =head1 TO DO | ||||
471 | |||||
472 | - Write specific unit tests for this package | ||||
473 | |||||
474 | =head1 SUPPORT | ||||
475 | |||||
476 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
477 | |||||
478 | =head1 AUTHOR | ||||
479 | |||||
480 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||
481 | |||||
482 | =head1 COPYRIGHT | ||||
483 | |||||
484 | Copyright 2001 - 2011 Adam Kennedy. | ||||
485 | |||||
486 | This program is free software; you can redistribute | ||||
487 | it and/or modify it under the same terms as Perl itself. | ||||
488 | |||||
489 | The full text of the license can be found in the | ||||
490 | LICENSE file included with this module. | ||||
491 | |||||
492 | =cut | ||||
# spent 416µs within PPI::Statement::Include::CORE:match which was called 144 times, avg 3µs/call:
# 144 times (416µs+0s) by PPI::Statement::Include::pragma at line 203, avg 3µs/call |