← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:11 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Statement/Include.pm
StatementsExecuted 12559 statements in 42.5ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
12663215.0ms40.4msPPI::Statement::Include::::versionPPI::Statement::Include::version
14103314.3ms43.0msPPI::Statement::Include::::modulePPI::Statement::Include::module
12682211.0ms22.1msPPI::Statement::Include::::typePPI::Statement::Include::type
286113.63ms10.7msPPI::Statement::Include::::pragmaPPI::Statement::Include::pragma
14411416µs416µsPPI::Statement::Include::::CORE:matchPPI::Statement::Include::CORE:match (opcode)
111184µs258µsPPI::Statement::Include::::BEGIN@49PPI::Statement::Include::BEGIN@49
11114µs30µsPPI::Statement::Include::::BEGIN@47PPI::Statement::Include::BEGIN@47
11114µs14µsPPI::Statement::Include::::BEGIN@52PPI::Statement::Include::BEGIN@52
1117µs34µsPPI::Statement::Include::::BEGIN@51PPI::Statement::Include::BEGIN@51
1114µs4µsPPI::Statement::Include::::BEGIN@48PPI::Statement::Include::BEGIN@48
0000s0sPPI::Statement::Include::::argumentsPPI::Statement::Include::arguments
0000s0sPPI::Statement::Include::::module_versionPPI::Statement::Include::module_version
0000s0sPPI::Statement::Include::::version_literalPPI::Statement::Include::version_literal
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package PPI::Statement::Include;
2
3=pod
4
5=head1 NAME
6
7PPI::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
30Despite its name, the C<PPI::Statement::Include> class covers a number
31of different types of statement that cover all statements starting with
32C<use>, C<no> and C<require>.
33
34But basically, they cover three situations.
35
36Firstly, a dependency on a particular version of perl (for which the
37C<version> method returns true), a pragma (for which the C<pragma> method
38returns true, or the loading (and unloading via no) of modules.
39
40=head1 METHODS
41
42C<PPI::Statement::Include> has a number of methods in addition to the standard
43L<PPI::Statement>, L<PPI::Node> and L<PPI::Element> methods.
44
45=cut
46
47222µs246µ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
use strict;
# spent 30µs making 1 call to PPI::Statement::Include::BEGIN@47 # spent 16µs making 1 call to strict::import
48217µs14µ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
use PPI::Statement ();
# spent 4µs making 1 call to PPI::Statement::Include::BEGIN@48
492102µs1258µ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
use PPI::Statement::Include::Perl6 ();
# spent 258µs making 1 call to PPI::Statement::Include::BEGIN@49
50
51229µs261µ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
use vars qw{$VERSION @ISA};
# 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
BEGIN {
531300ns $VERSION = '1.215';
54114µs @ISA = 'PPI::Statement';
551406µs114µs}
# spent 14µs making 1 call to PPI::Statement::Include::BEGIN@52
56
57=pod
58
59=head2 type
60
61The C<type> method returns the general type of statement (C<'use'>, C<'no'>
62or C<'require'>).
63
64Returns the type as a string, or C<undef> if the type cannot be detected.
65
66=begin testing type 9
67
68my $document = PPI::Document->new(\<<'END_PERL');
69require 5.6;
70require Module;
71require 'Module.pm';
72use 5.6;
73use Module;
74use Module 1.00;
75no Module;
76END_PERL
77
78isa_ok( $document, 'PPI::Document' );
79my $statements = $document->find('PPI::Statement::Include');
80is( scalar(@$statements), 7, 'Found 7 include statements' );
81my @expected = qw{ require require require use use use no };
82foreach ( 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
sub type {
911268225µs my $self = shift;
9212684.48ms25368.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
9312686.46ms25362.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
100The C<module> method returns the module name specified in any include
101statement. This C<includes> pragma names, because pragma are implemented
102as modules. (And lets face it, the definition of a pragma can be fuzzy
103at the best of times in any case)
104
105This 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
118Returns the module name as a string, or C<undef> if the include does
119not 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
sub module {
1241410290µs my $self = shift;
12514105.09ms282026.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
126141011.7ms23942.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
133The C<module_version> method returns the minimum version of the module
134required by the statement, if there is one.
135
136=begin testing module_version 9
137
138my $document = PPI::Document->new(\<<'END_PERL');
139use Integer::Version 1;
140use Float::Version 1.5;
141use Version::With::Argument 1 2;
142use No::Version;
143use No::Version::With::Argument 'x';
144use No::Version::With::Arguments 1, 2;
145use 5.005;
146END_PERL
147
148isa_ok( $document, 'PPI::Document' );
149my $statements = $document->find('PPI::Statement::Include');
150is( scalar @{$statements}, 7, 'Found expected include statements.' );
151is( $statements->[0]->module_version, 1, 'Integer version' );
152is( $statements->[1]->module_version, 1.5, 'Float version' );
153is( $statements->[2]->module_version, 1, 'Version and argument' );
154is( $statements->[3]->module_version, undef, 'No version, no arguments' );
155is( $statements->[4]->module_version, undef, 'No version, with argument' );
156is( $statements->[5]->module_version, undef, 'No version, with arguments' );
157is( $statements->[6]->module_version, undef, 'Version include, no module' );
158
159=end testing
160
161=cut
162
163sub 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
180The C<pragma> method checks for an include statement's use as a
181pragma, and returns it if so.
182
183Or at least, it claims to. In practice it's a lot harder to say exactly
184what is or isn't a pragma, because the definition is fuzzy.
185
186The C<intent> of a pragma is to modify the way in which the parser works.
187This is done though the use of modules that do various types of internals
188magic.
189
190For now, PPI assumes that any "module name" that is only a set of
191lowercase letters (and perhaps numbers, like C<use utf8;>). This
192behaviour is expected to change, most likely to something that knows
193the specific names of the various "pragmas".
194
195Returns the name of the pragma, or false ('') if the include is not a
196pragma.
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
sub pragma {
20128695µs my $self = shift;
202286875µs2866.65ms my $module = $self->module or return '';
# spent 6.65ms making 286 calls to PPI::Statement::Include::module, avg 23µs/call
2031441.09ms144416µ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
210The C<version> method checks for an include statement that introduces a
211dependency on the version of C<perl> the code is compatible with.
212
213This covers two specific statements.
214
215 use 5.006;
216 require 5.006;
217
218Currently the version is returned as a string, although in future the version
219may be returned as a L<version> object. If you want a numeric representation,
220use C<version_literal()>. Returns false if the statement is not a version
221dependency.
222
223=begin testing version 13
224
225my $document = PPI::Document->new(\<<'END_PERL');
226# Examples from perlfunc in 5.10.
227use v5.6.1;
228use 5.6.1;
229use 5.006_001;
230use 5.006; use 5.6.1;
231
232# Same, but using require.
233require v5.6.1;
234require 5.6.1;
235require 5.006_001;
236require 5.006; require 5.6.1;
237
238# Module.
239use Float::Version 1.5;
240END_PERL
241
242isa_ok( $document, 'PPI::Document' );
243my $statements = $document->find('PPI::Statement::Include');
244is( scalar @{$statements}, 11, 'Found expected include statements.' );
245
246is( $statements->[0]->version, 'v5.6.1', 'use v-string' );
247is( $statements->[1]->version, '5.6.1', 'use v-string, no leading "v"' );
248is( $statements->[2]->version, '5.006_001', 'use developer release' );
249is( $statements->[3]->version, '5.006', 'use back-compatible version, followed by...' );
250is( $statements->[4]->version, '5.6.1', '... use v-string, no leading "v"' );
251
252is( $statements->[5]->version, 'v5.6.1', 'require v-string' );
253is( $statements->[6]->version, '5.6.1', 'require v-string, no leading "v"' );
254is( $statements->[7]->version, '5.006_001', 'require developer release' );
255is( $statements->[8]->version, '5.006', 'require back-compatible version, followed by...' );
256is( $statements->[9]->version, '5.6.1', '... require v-string, no leading "v"' );
257
258is( $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
sub version {
2651266284µs my $self = shift;
26612664.54ms253223.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
26712666.73ms16922.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
274The C<version_literal> method has the same behavior as C<version()>, but the
275version is returned as a numeric literal. Returns false if the statement is
276not a version dependency.
277
278=begin testing version_literal 13
279
280my $document = PPI::Document->new(\<<'END_PERL');
281# Examples from perlfunc in 5.10.
282use v5.6.1;
283use 5.6.1;
284use 5.006_001;
285use 5.006; use 5.6.1;
286
287# Same, but using require.
288require v5.6.1;
289require 5.6.1;
290require 5.006_001;
291require 5.006; require 5.6.1;
292
293# Module.
294use Float::Version 1.5;
295END_PERL
296
297isa_ok( $document, 'PPI::Document' );
298my $statements = $document->find('PPI::Statement::Include');
299is( scalar @{$statements}, 11, 'Found expected include statements.' );
300
301is( $statements->[0]->version_literal, v5.6.1, 'use v-string' );
302is( $statements->[1]->version_literal, 5.6.1, 'use v-string, no leading "v"' );
303is( $statements->[2]->version_literal, 5.006_001, 'use developer release' );
304is( $statements->[3]->version_literal, 5.006, 'use back-compatible version, followed by...' );
305is( $statements->[4]->version_literal, 5.6.1, '... use v-string, no leading "v"' );
306
307is( $statements->[5]->version_literal, v5.6.1, 'require v-string' );
308is( $statements->[6]->version_literal, 5.6.1, 'require v-string, no leading "v"' );
309is( $statements->[7]->version_literal, 5.006_001, 'require developer release' );
310is( $statements->[8]->version_literal, 5.006, 'require back-compatible version, followed by...' );
311is( $statements->[9]->version_literal, 5.6.1, '... require v-string, no leading "v"' );
312
313is( $statements->[10]->version_literal, '', 'use module version' );
314
315=end testing
316
317=cut
318
319sub 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
327The C<arguments> method gives you the rest of the statement after the the
328module/pragma and module version, i.e. the stuff that will be used to
329construct what gets passed to the module's C<import()> subroutine. This does
330include the comma, etc. operators, but doesn't include non-significant direct
331children or any final semicolon.
332
333=begin testing arguments 19
334
335my $document = PPI::Document->new(\<<'END_PERL');
336use 5.006; # Don't expect anything.
337use Foo; # Don't expect anything.
338use Foo 5; # Don't expect anything.
339use Foo 'bar'; # One thing.
340use Foo 5 'bar'; # One thing.
341use Foo qw< bar >, "baz";
342use Test::More tests => 5 * 9 # Don't get tripped up by the lack of the ";"
343END_PERL
344
345isa_ok( $document, 'PPI::Document' );
346my $statements = $document->find('PPI::Statement::Include');
347is( scalar @{$statements}, 7, 'Found expected include statements.' );
348
349is(
350 scalar $statements->[0]->arguments, undef, 'arguments for perl version',
351);
352is(
353 scalar $statements->[1]->arguments,
354 undef,
355 'arguments with no arguments',
356);
357is(
358 scalar $statements->[2]->arguments,
359 undef,
360 'arguments with no arguments but module version',
361);
362
363my @arguments = $statements->[3]->arguments;
364is( scalar @arguments, 1, 'arguments with single argument' );
365is( $arguments[0]->content, q<'bar'>, 'arguments with single argument' );
366
367@arguments = $statements->[4]->arguments;
368is(
369 scalar @arguments,
370 1,
371 'arguments with single argument and module version',
372);
373is(
374 $arguments[0]->content,
375 q<'bar'>,
376 'arguments with single argument and module version',
377);
378
379@arguments = $statements->[5]->arguments;
380is(
381 scalar @arguments,
382 3,
383 'arguments with multiple arguments',
384);
385is(
386 $arguments[0]->content,
387 q/qw< bar >/,
388 'arguments with multiple arguments',
389);
390is(
391 $arguments[1]->content,
392 q<,>,
393 'arguments with multiple arguments',
394);
395is(
396 $arguments[2]->content,
397 q<"baz">,
398 'arguments with multiple arguments',
399);
400
401@arguments = $statements->[6]->arguments;
402is(
403 scalar @arguments,
404 5,
405 'arguments with Test::More',
406);
407is(
408 $arguments[0]->content,
409 'tests',
410 'arguments with Test::More',
411);
412is(
413 $arguments[1]->content,
414 q[=>],
415 'arguments with Test::More',
416);
417is(
418 $arguments[2]->content,
419 5,
420 'arguments with Test::More',
421);
422is(
423 $arguments[3]->content,
424 '*',
425 'arguments with Test::More',
426);
427is(
428 $arguments[4]->content,
429 9,
430 'arguments with Test::More',
431);
432
433=end testing
434
435=cut
436
437sub 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
46612µs1;
467
468=pod
469
470=head1 TO DO
471
472- Write specific unit tests for this package
473
474=head1 SUPPORT
475
476See the L<support section|PPI/SUPPORT> in the main module.
477
478=head1 AUTHOR
479
480Adam Kennedy E<lt>adamk@cpan.orgE<gt>
481
482=head1 COPYRIGHT
483
484Copyright 2001 - 2011 Adam Kennedy.
485
486This program is free software; you can redistribute
487it and/or modify it under the same terms as Perl itself.
488
489The full text of the license can be found in the
490LICENSE 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
sub PPI::Statement::Include::CORE:match; # opcode