← 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:13 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Document.pm
StatementsExecuted 1207006 statements in 1.44s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11055211515ms515msPerl::Critic::Document::::__ANON__[:531]Perl::Critic::Document::__ANON__[:531]
11055211374ms513msPerl::Critic::Document::::_is_a_version_statementPerl::Critic::Document::_is_a_version_statement
36007525.7ms3.17sPerl::Critic::Document::::findPerl::Critic::Document::find
4608618.40ms11.4msPerl::Critic::Document::::CORE:matchPerl::Critic::Document::CORE:match (opcode)
149226.30ms1.50sPerl::Critic::Document::::highest_explicit_perl_versionPerl::Critic::Document::highest_explicit_perl_version
576435.67ms4.48sPerl::Critic::Document::::AUTOLOADPerl::Critic::Document::AUTOLOAD
144115.08ms15.6msPerl::Critic::Document::::_disable_shebang_fixPerl::Critic::Document::_disable_shebang_fix
144114.93ms16.5sPerl::Critic::Document::::_init_from_external_sourcePerl::Critic::Document::_init_from_external_source
144113.67ms10.4msPerl::Critic::Document::::_determine_is_modulePerl::Critic::Document::_determine_is_module
288222.10ms82.3msPerl::Critic::Document::::find_firstPerl::Critic::Document::find_first
144112.01ms16.5sPerl::Critic::Document::::newPerl::Critic::Document::new
144112.00ms2.35msPerl::Critic::Document::::add_annotationPerl::Critic::Document::add_annotation
144111.82ms1.78sPerl::Critic::Document::::process_annotationsPerl::Critic::Document::process_annotations
144111.41ms1.90msPerl::Critic::Document::::filenamePerl::Critic::Document::filename
144111.15ms1.15msPerl::Critic::Document::::_caching_finderPerl::Critic::Document::_caching_finder
1111.04ms1.88msPerl::Critic::Document::::BEGIN@24Perl::Critic::Document::BEGIN@24
111886┬Ás38.0msPerl::Critic::Document::::BEGIN@28Perl::Critic::Document::BEGIN@28
111706┬Ás1.42msPerl::Critic::Document::::BEGIN@22Perl::Critic::Document::BEGIN@22
14411674┬Ás674┬ÁsPerl::Critic::Document::::_init_commonPerl::Critic::Document::_init_common
28821651┬Ás651┬ÁsPerl::Critic::Document::::CORE:regcompPerl::Critic::Document::CORE:regcomp (opcode)
14411638┬Ás757┬ÁsPerl::Critic::Document::::_is_ppi_docPerl::Critic::Document::_is_ppi_doc
14411372┬Ás372┬ÁsPerl::Critic::Document::::CORE:qrPerl::Critic::Document::CORE:qr (opcode)
14411345┬Ás345┬ÁsPerl::Critic::Document::::is_modulePerl::Critic::Document::is_module
11147┬Ás52┬ÁsPerl::Critic::Document::::BEGIN@12Perl::Critic::Document::BEGIN@12
11126┬Ás26┬ÁsPerl::Critic::Document::::BEGIN@10Perl::Critic::Document::BEGIN@10
11118┬Ás48┬ÁsPerl::Critic::Document::::BEGIN@16Perl::Critic::Document::BEGIN@16
31112┬Ás12┬ÁsPerl::Critic::Document::::line_is_disabled_for_policyPerl::Critic::Document::line_is_disabled_for_policy
11112┬Ás49┬ÁsPerl::Critic::Document::::BEGIN@25Perl::Critic::Document::BEGIN@25
11110┬Ás46┬ÁsPerl::Critic::Document::::BEGIN@17Perl::Critic::Document::BEGIN@17
1119┬Ás9┬ÁsPerl::Critic::Document::::BEGIN@21Perl::Critic::Document::BEGIN@21
1119┬Ás34┬ÁsPerl::Critic::Document::::BEGIN@14Perl::Critic::Document::BEGIN@14
1119┬Ás21┬ÁsPerl::Critic::Document::::BEGIN@519Perl::Critic::Document::BEGIN@519
1118┬Ás25┬ÁsPerl::Critic::Document::::BEGIN@18Perl::Critic::Document::BEGIN@18
1118┬Ás294┬ÁsPerl::Critic::Document::::BEGIN@26Perl::Critic::Document::BEGIN@26
3118┬Ás8┬ÁsPerl::Critic::Document::::add_suppressed_violationPerl::Critic::Document::add_suppressed_violation
1117┬Ás20┬ÁsPerl::Critic::Document::::BEGIN@11Perl::Critic::Document::BEGIN@11
1116┬Ás6┬ÁsPerl::Critic::Document::::BEGIN@20Perl::Critic::Document::BEGIN@20
0000s0sPerl::Critic::Document::::__ANON__[:374]Perl::Critic::Document::__ANON__[:374]
0000s0sPerl::Critic::Document::::_find_use_re_modifiers_in_scope_from_elementPerl::Critic::Document::_find_use_re_modifiers_in_scope_from_element
0000s0sPerl::Critic::Document::::_modules_usedPerl::Critic::Document::_modules_used
0000s0sPerl::Critic::Document::::_new_for_parent_documentPerl::Critic::Document::_new_for_parent_document
0000s0sPerl::Critic::Document::::_nodes_by_namespacePerl::Critic::Document::_nodes_by_namespace
0000s0sPerl::Critic::Document::::annotationsPerl::Critic::Document::annotations
0000s0sPerl::Critic::Document::::element_is_in_lexical_scope_after_statement_containingPerl::Critic::Document::element_is_in_lexical_scope_after_statement_containing
0000s0sPerl::Critic::Document::::find_anyPerl::Critic::Document::find_any
0000s0sPerl::Critic::Document::::is_programPerl::Critic::Document::is_program
0000s0sPerl::Critic::Document::::isaPerl::Critic::Document::isa
0000s0sPerl::Critic::Document::::namespacesPerl::Critic::Document::namespaces
0000s0sPerl::Critic::Document::::ppi_documentPerl::Critic::Document::ppi_document
0000s0sPerl::Critic::Document::::ppix_regexp_from_elementPerl::Critic::Document::ppix_regexp_from_element
0000s0sPerl::Critic::Document::::subdocuments_for_namespacePerl::Critic::Document::subdocuments_for_namespace
0000s0sPerl::Critic::Document::::suppressed_violationsPerl::Critic::Document::suppressed_violations
0000s0sPerl::Critic::Document::::uses_modulePerl::Critic::Document::uses_module
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1##############################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6##############################################################################
7
8package Perl::Critic::Document;
9
10244┬Ás126┬Ás
# spent 26┬Ás within Perl::Critic::Document::BEGIN@10 which was called: # once (26┬Ás+0s) by Perl::Critic::BEGIN@26 at line 10
use 5.006001;
# spent 26┬Ás making 1 call to Perl::Critic::Document::BEGIN@10
11230┬Ás232┬Ás
# spent 20┬Ás (7+13) within Perl::Critic::Document::BEGIN@11 which was called: # once (7┬Ás+13┬Ás) by Perl::Critic::BEGIN@26 at line 11
use strict;
# spent 20┬Ás making 1 call to Perl::Critic::Document::BEGIN@11 # spent 13┬Ás making 1 call to strict::import
12224┬Ás258┬Ás
# spent 52┬Ás (47+5) within Perl::Critic::Document::BEGIN@12 which was called: # once (47┬Ás+5┬Ás) by Perl::Critic::BEGIN@26 at line 12
use warnings;
# spent 52┬Ás making 1 call to Perl::Critic::Document::BEGIN@12 # spent 6┬Ás making 1 call to warnings::import
13
14224┬Ás259┬Ás
# spent 34┬Ás (9+25) within Perl::Critic::Document::BEGIN@14 which was called: # once (9┬Ás+25┬Ás) by Perl::Critic::BEGIN@26 at line 14
use Carp qw< confess >;
# spent 34┬Ás making 1 call to Perl::Critic::Document::BEGIN@14 # spent 25┬Ás making 1 call to Exporter::import
15
16229┬Ás257┬Ás
# spent 48┬Ás (18+30) within Perl::Critic::Document::BEGIN@16 which was called: # once (18┬Ás+30┬Ás) by Perl::Critic::BEGIN@26 at line 16
use List::Util qw< reduce >;
# spent 48┬Ás making 1 call to Perl::Critic::Document::BEGIN@16 # spent 9┬Ás making 1 call to List::Util::import
17224┬Ás282┬Ás
# spent 46┬Ás (10+36) within Perl::Critic::Document::BEGIN@17 which was called: # once (10┬Ás+36┬Ás) by Perl::Critic::BEGIN@26 at line 17
use Scalar::Util qw< blessed refaddr weaken >;
# spent 46┬Ás making 1 call to Perl::Critic::Document::BEGIN@17 # spent 36┬Ás making 1 call to Exporter::import
18224┬Ás241┬Ás
# spent 25┬Ás (8+16) within Perl::Critic::Document::BEGIN@18 which was called: # once (8┬Ás+16┬Ás) by Perl::Critic::BEGIN@26 at line 18
use version;
# spent 25┬Ás making 1 call to Perl::Critic::Document::BEGIN@18 # spent 16┬Ás making 1 call to version::import
19
20220┬Ás16┬Ás
# spent 6┬Ás within Perl::Critic::Document::BEGIN@20 which was called: # once (6┬Ás+0s) by Perl::Critic::BEGIN@26 at line 20
use PPI::Document;
# spent 6┬Ás making 1 call to Perl::Critic::Document::BEGIN@20
21224┬Ás19┬Ás
# spent 9┬Ás within Perl::Critic::Document::BEGIN@21 which was called: # once (9┬Ás+0s) by Perl::Critic::BEGIN@26 at line 21
use PPI::Document::File;
# spent 9┬Ás making 1 call to Perl::Critic::Document::BEGIN@21
22295┬Ás21.45ms
# spent 1.42ms (706┬Ás+711┬Ás) within Perl::Critic::Document::BEGIN@22 which was called: # once (706┬Ás+711┬Ás) by Perl::Critic::BEGIN@26 at line 22
use PPIx::Utilities::Node qw< split_ppi_node_by_namespace >;
# spent 1.42ms making 1 call to Perl::Critic::Document::BEGIN@22 # spent 37┬Ás making 1 call to Exporter::import
23
24292┬Ás11.88ms
# spent 1.88ms (1.04+838┬Ás) within Perl::Critic::Document::BEGIN@24 which was called: # once (1.04ms+838┬Ás) by Perl::Critic::BEGIN@26 at line 24
use Perl::Critic::Annotation;
# spent 1.88ms making 1 call to Perl::Critic::Document::BEGIN@24
25227┬Ás286┬Ás
# spent 49┬Ás (12+37) within Perl::Critic::Document::BEGIN@25 which was called: # once (12┬Ás+37┬Ás) by Perl::Critic::BEGIN@26 at line 25
use Perl::Critic::Exception::Parse qw< throw_parse >;
# spent 49┬Ás making 1 call to Perl::Critic::Document::BEGIN@25 # spent 37┬Ás making 1 call to Exporter::import
26226┬Ás2580┬Ás
# spent 294┬Ás (8+286) within Perl::Critic::Document::BEGIN@26 which was called: # once (8┬Ás+286┬Ás) by Perl::Critic::BEGIN@26 at line 26
use Perl::Critic::Utils qw< :booleans :characters shebang_line >;
# spent 294┬Ás making 1 call to Perl::Critic::Document::BEGIN@26 # spent 286┬Ás making 1 call to Exporter::import
27
2831.59ms238.0ms
# spent 38.0ms (886┬Ás+37.1) within Perl::Critic::Document::BEGIN@28 which was called: # once (886┬Ás+37.1ms) by Perl::Critic::BEGIN@26 at line 28
use PPIx::Regexp 0.010 qw< >;
# spent 38.0ms making 1 call to Perl::Critic::Document::BEGIN@28 # spent 12┬Ás making 1 call to UNIVERSAL::VERSION
29
30#-----------------------------------------------------------------------------
31
321600nsour $VERSION = '1.121';
33
34#-----------------------------------------------------------------------------
35
361100nsour $AUTOLOAD;
37
# spent 4.48s (5.67ms+4.48) within Perl::Critic::Document::AUTOLOAD which was called 576 times, avg 7.78ms/call: # 144 times (1.68ms+3.24s) by Perl::Critic::Document::_init_from_external_source at line 123, avg 22.5ms/call # 144 times (1.60ms+1.23s) by Perl::Critic::Statistics::accumulate at line 64 of Perl/Critic/Statistics.pm, avg 8.57ms/call # 144 times (1.41ms+4.73ms) by Perl::Critic::Document::_disable_shebang_fix at line 545, avg 43┬Ás/call # 144 times (974┬Ás+841┬Ás) by Perl::Critic::Utils::shebang_line at line 1154 of Perl/Critic/Utils.pm, avg 13┬Ás/call
sub AUTOLOAD { ## no critic (ProhibitAutoloading,ArgUnpacking)
385764.22ms5762.36ms my ( $function_name ) = $AUTOLOAD =~ m/ ([^:\']+) \z /xms;
# spent 2.36ms making 576 calls to Perl::Critic::Document::CORE:match, avg 4┬Ás/call
39576275┬Ás return if $function_name eq 'DESTROY';
40576224┬Ás my $self = shift;
415763.02ms5764.48s return $self->{_doc}->$function_name(@_);
# spent 3.24s making 144 calls to PPI::Document::index_locations, avg 22.5ms/call # spent 1.23s making 144 calls to PPI::Document::serialize, avg 8.55ms/call # spent 4.12ms making 144 calls to PPI::Node::schild, avg 29┬Ás/call # spent 361┬Ás making 144 calls to PPI::Node::first_element, avg 3┬Ás/call
42}
43
44#-----------------------------------------------------------------------------
45
46
# spent 16.5s (2.01ms+16.5) within Perl::Critic::Document::new which was called 144 times, avg 115ms/call: # 144 times (2.01ms+16.5s) by Perl::Critic::critique at line 104 of Perl/Critic.pm, avg 115ms/call
sub new {
47144224┬Ás my ($class, @args) = @_;
48
49144217┬Ás my $self = bless {}, $class;
50
51144287┬Ás144674┬Ás $self->_init_common();
# spent 674┬Ás making 144 calls to Perl::Critic::Document::_init_common, avg 5┬Ás/call
52144303┬Ás14416.5s $self->_init_from_external_source(@args);
# spent 16.5s making 144 calls to Perl::Critic::Document::_init_from_external_source, avg 115ms/call
53
54144675┬Ás return $self;
55}
56
57#-----------------------------------------------------------------------------
58
59sub _new_for_parent_document {
60 my ($class, $ppi_document, $parent_document) = @_;
61
62 my $self = bless {}, $class;
63
64 $self->_init_common();
65
66 $self->{_doc} = $ppi_document;
67 $self->{_is_module} = $parent_document->is_module();
68
69 return $self;
70}
71
72#-----------------------------------------------------------------------------
73
74
# spent 674┬Ás within Perl::Critic::Document::_init_common which was called 144 times, avg 5┬Ás/call: # 144 times (674┬Ás+0s) by Perl::Critic::Document::new at line 51, avg 5┬Ás/call
sub _init_common {
7514447┬Ás my ($self) = @_;
76
77144184┬Ás $self->{_annotations} = [];
7814497┬Ás $self->{_suppressed_violations} = [];
7914468┬Ás $self->{_disabled_line_map} = {};
80
81144400┬Ás return;
82}
83
84#-----------------------------------------------------------------------------
85
86
# spent 16.5s (4.93ms+16.5) within Perl::Critic::Document::_init_from_external_source which was called 144 times, avg 115ms/call: # 144 times (4.93ms+16.5s) by Perl::Critic::Document::new at line 52, avg 115ms/call
sub _init_from_external_source { ## no critic (Subroutines::RequireArgUnpacking)
8714451┬Ás my $self = shift;
8814433┬Ás my %args;
89
90144113┬Ás if (@_ == 1) {
91 warnings::warnif(
92 'deprecated',
93 'Perl::Critic::Document->new($source) deprecated, use Perl::Critic::Document->new(-source => $source) instead.' ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
94 );
95 %args = ('-source' => shift);
96 } else {
97144228┬Ás %args = @_;
98 }
99
100144107┬Ás my $source_code = $args{'-source'};
101
102 # $source_code can be a file name, or a reference to a
103 # PPI::Document, or a reference to a scalar containing source
104 # code. In the last case, PPI handles the translation for us.
105
106144825┬Ás28813.3s my $ppi_document =
# spent 13.3s making 144 calls to PPI::Document::File::new, avg 92.0ms/call # spent 757┬Ás making 144 calls to Perl::Critic::Document::_is_ppi_doc, avg 5┬Ás/call
107 _is_ppi_doc($source_code)
108 ? $source_code
109 : ref $source_code
110 ? PPI::Document->new($source_code)
111 : PPI::Document::File->new($source_code);
112
113 # Bail on error
11414449┬Ás if (not defined $ppi_document) {
115 my $errstr = PPI::Document::errstr();
116 my $file = ref $source_code ? undef : $source_code;
117 throw_parse
118 message => qq<Can't parse code: $errstr>,
119 file_name => $file;
120 }
121
122144185┬Ás $self->{_doc} = $ppi_document;
123144881┬Ás1443.24s $self->index_locations();
# spent 3.24s making 144 calls to Perl::Critic::Document::AUTOLOAD, avg 22.5ms/call
124144495┬Ás14415.6ms $self->_disable_shebang_fix();
# spent 15.6ms making 144 calls to Perl::Critic::Document::_disable_shebang_fix, avg 109┬Ás/call
125144185┬Ás $self->{_filename_override} = $args{'-filename-override'};
126144847┬Ás28810.8ms $self->{_is_module} = $self->_determine_is_module(\%args);
# spent 10.4ms making 144 calls to Perl::Critic::Document::_determine_is_module, avg 72┬Ás/call # spent 329┬Ás making 144 calls to Readonly::Scalar::FETCH, avg 2┬Ás/call
127
128144627┬Ás return;
129}
130
131#-----------------------------------------------------------------------------
132
133
# spent 757┬Ás (638+119) within Perl::Critic::Document::_is_ppi_doc which was called 144 times, avg 5┬Ás/call: # 144 times (638┬Ás+119┬Ás) by Perl::Critic::Document::_init_from_external_source at line 106, avg 5┬Ás/call
sub _is_ppi_doc {
13414455┬Ás my ($ref) = @_;
135144783┬Ás144119┬Ás return blessed($ref) && $ref->isa('PPI::Document');
# spent 119┬Ás making 144 calls to Scalar::Util::blessed, avg 828ns/call
136}
137
138#-----------------------------------------------------------------------------
139
140sub ppi_document {
141 my ($self) = @_;
142 return $self->{_doc};
143}
144
145#-----------------------------------------------------------------------------
146
147sub isa {
148 my ($self, @args) = @_;
149 return $self->SUPER::isa(@args)
150 || ( (ref $self) && $self->{_doc} && $self->{_doc}->isa(@args) );
151}
152
153#-----------------------------------------------------------------------------
154
155
# spent 3.17s (25.7ms+3.15) within Perl::Critic::Document::find which was called 3600 times, avg 882┬Ás/call: # 2736 times (13.0ms+4.29ms) by Perl::Critic::_critique at line 171 of Perl/Critic.pm, avg 6┬Ás/call # 144 times (6.23ms+1.66s) by Perl::Critic::Annotation::create_annotations at line 34 of Perl/Critic/Annotation.pm, avg 11.6ms/call # 144 times (791┬Ás+1.49s) by Perl::Critic::Document::highest_explicit_perl_version at line 355, avg 10.3ms/call # 144 times (3.48ms+150┬Ás) by Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::_find_isnt_include_or_package at line 126 of Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm, avg 25┬Ás/call # 144 times (958┬Ás+280┬Ás) by Perl::Critic::Statistics::accumulate at line 60 of Perl/Critic/Statistics.pm, avg 9┬Ás/call # 144 times (616┬Ás+148┬Ás) by Perl::Critic::Statistics::accumulate at line 52 of Perl/Critic/Statistics.pm, avg 5┬Ás/call # 144 times (569┬Ás+90┬Ás) by Perl::Critic::Document::find_first at line 198, avg 5┬Ás/call
sub find {
15636001.66ms my ($self, $wanted, @more_args) = @_;
157
158 # This method can only find elements by their class names. For
159 # other types of searches, delegate to the PPI::Document
160360015.9ms36001.49s if ( ( ref $wanted ) || !$wanted || $wanted !~ m/ \A PPI:: /xms ) {
# spent 1.49s making 144 calls to PPI::Node::find, avg 10.3ms/call # spent 5.19ms making 3456 calls to Perl::Critic::Document::CORE:match, avg 2┬Ás/call
161 return $self->{_doc}->find($wanted, @more_args);
162 }
163
164 # Build the class cache if it doesn't exist. This happens at most
165 # once per Perl::Critic::Document instance. %elements of will be
166 # populated as a side-effect of calling the $finder_sub coderef
167 # that is produced by the caching_finder() closure.
16834561.33ms if ( !$self->{_elements_of} ) {
169
170144302┬Ás my %cache = ( 'PPI::Document' => [ $self ] );
171
172 # The cache refers to $self, and $self refers to the cache. This
173 # creates a circular reference that leaks memory (i.e. $self is not
174 # destroyed until execution is complete). By weakening the reference,
175 # we allow perl to collect the garbage properly.
176144850┬Ás144422┬Ás weaken( $cache{'PPI::Document'}->[0] );
# spent 422┬Ás making 144 calls to Scalar::Util::weaken, avg 3┬Ás/call
177
178144354┬Ás1441.15ms my $finder_coderef = _caching_finder( \%cache );
# spent 1.15ms making 144 calls to Perl::Critic::Document::_caching_finder, avg 8┬Ás/call
179144334┬Ás1441.66s $self->{_doc}->find( $finder_coderef );
# spent 1.66s making 144 calls to PPI::Node::find, avg 11.5ms/call
1801443.47ms $self->{_elements_of} = \%cache;
181 }
182
183 # find() must return false-but-defined on fail
18434568.64ms return $self->{_elements_of}->{$wanted} || q{};
185}
186
187#-----------------------------------------------------------------------------
188
189
# spent 82.3ms (2.10+80.2) within Perl::Critic::Document::find_first which was called 288 times, avg 286┬Ás/call: # 144 times (942┬Ás+79.3ms) by Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::violates at line 58 of Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm, avg 558┬Ás/call # 144 times (1.16ms+839┬Ás) by Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::violates at line 48 of Perl/Critic/Policy/Modules/RequireFilenameMatchesPackage.pm, avg 14┬Ás/call
sub find_first {
190288196┬Ás my ($self, $wanted, @more_args) = @_;
191
192 # This method can only find elements by their class names. For
193 # other types of searches, delegate to the PPI::Document
1942881.39ms28879.5ms if ( ( ref $wanted ) || !$wanted || $wanted !~ m/ \A PPI:: /xms ) {
# spent 79.3ms making 144 calls to PPI::Node::find_first, avg 551┬Ás/call # spent 180┬Ás making 144 calls to Perl::Critic::Document::CORE:match, avg 1┬Ás/call
195 return $self->{_doc}->find_first($wanted, @more_args);
196 }
197
198144230┬Ás144659┬Ás my $result = $self->find($wanted);
# spent 659┬Ás making 144 calls to Perl::Critic::Document::find, avg 5┬Ás/call
199144497┬Ás return $result ? $result->[0] : $result;
200}
201
202#-----------------------------------------------------------------------------
203
204sub find_any {
205 my ($self, $wanted, @more_args) = @_;
206
207 # This method can only find elements by their class names. For
208 # other types of searches, delegate to the PPI::Document
209 if ( ( ref $wanted ) || !$wanted || $wanted !~ m/ \A PPI:: /xms ) {
210 return $self->{_doc}->find_any($wanted, @more_args);
211 }
212
213 my $result = $self->find($wanted);
214 return $result ? 1 : $result;
215}
216
217#-----------------------------------------------------------------------------
218
219sub namespaces {
220 my ($self) = @_;
221
222 return keys %{ $self->_nodes_by_namespace() };
223}
224
225#-----------------------------------------------------------------------------
226
227sub subdocuments_for_namespace {
228 my ($self, $namespace) = @_;
229
230 my $subdocuments = $self->_nodes_by_namespace()->{$namespace};
231
232 return $subdocuments ? @{$subdocuments} : ();
233}
234
235#-----------------------------------------------------------------------------
236
237sub ppix_regexp_from_element {
238 my ( $self, $element ) = @_;
239
240 if ( blessed( $element ) && $element->isa( 'PPI::Element' ) ) {
241 my $addr = refaddr( $element );
242 return $self->{_ppix_regexp_from_element}{$addr}
243 if exists $self->{_ppix_regexp_from_element}{$addr};
244 return ( $self->{_ppix_regexp_from_element}{$addr} =
245 PPIx::Regexp->new( $element,
246 default_modifiers =>
247 $self->_find_use_re_modifiers_in_scope_from_element(
248 $element ),
249 ) );
250 } else {
251 return PPIx::Regexp->new( $element );
252 }
253}
254
255sub _find_use_re_modifiers_in_scope_from_element {
256 my ( $self, $elem ) = @_;
257 my @found;
258 foreach my $use_re ( @{ $self->find( 'PPI::Statement::Include' ) || [] } )
259 {
260 're' eq $use_re->module()
261 or next;
262 $self->element_is_in_lexical_scope_after_statement_containing(
263 $elem, $use_re )
264 or next;
265 my $prefix = 'no' eq $use_re->type() ? q{-} : $EMPTY;
266 push @found,
267 map { "$prefix$_" }
268 grep { m{ \A / }smx }
269 map {
270 $_->isa( 'PPI::Token::Quote' ) ? $_->string() :
271 $_->isa( 'PPI::Token::QuoteLike::Words' ) ? $_->literal() :
272 $_->content() }
273 $use_re->schildren();
274 }
275 return \@found;
276}
277
278#-----------------------------------------------------------------------------
279
280# This got hung on the Perl::Critic::Document, rather than living in
281# Perl::Critic::Utils::PPI, because of the possibility that caching of scope
282# objects would turn out to be desirable.
283
284sub element_is_in_lexical_scope_after_statement_containing {
285 my ( $self, $inner_elem, $outer_elem ) = @_;
286
287 # If the outer element defines a scope, we're true if and only if
288 # the outer element contains the inner element.
289 $outer_elem->scope()
290 and return $inner_elem->descendant_of( $outer_elem );
291
292 # In the more general case:
293
294 # The last element of the statement containing the outer element
295 # must be before the inner element. If not, we know we're false,
296 # without walking the parse tree.
297
298 my $stmt = $outer_elem->statement()
299 or return;
300 my $last_elem = $stmt->last_element()
301 or return;
302
303 my $stmt_loc = $last_elem->location()
304 or return;
305
306 my $inner_loc = $inner_elem->location()
307 or return;
308
309 $stmt_loc->[0] > $inner_loc->[0]
310 and return;
311 $stmt_loc->[0] == $inner_loc->[0]
312 and $stmt_loc->[1] > $inner_loc->[1]
313 and return;
314
315 # Since we know the inner element is after the outer element, find
316 # the element that defines the scope of the statement that contains
317 # the outer element.
318
319 my $parent = $stmt;
320 while ( ! $parent->scope() ) {
321 $parent = $parent->parent()
322 or return;
323 }
324
325 # We're true if and only if the scope of the outer element contains
326 # the inner element.
327
328 return $inner_elem->descendant_of( $parent );
329
330}
331
332#-----------------------------------------------------------------------------
333
334
# spent 1.90ms (1.41+487┬Ás) within Perl::Critic::Document::filename which was called 144 times, avg 13┬Ás/call: # 144 times (1.41ms+487┬Ás) by Perl::Critic::Document::_determine_is_module at line 566, avg 13┬Ás/call
sub filename {
33514456┬Ás my ($self) = @_;
336
33714495┬Ás if (defined $self->{_filename_override}) {
338 return $self->{_filename_override};
339 }
340 else {
34114454┬Ás my $doc = $self->{_doc};
3421441.23ms288487┬Ás return $doc->can('filename') ? $doc->filename() : undef;
# spent 318┬Ás making 144 calls to PPI::Document::File::filename, avg 2┬Ás/call # spent 169┬Ás making 144 calls to UNIVERSAL::can, avg 1┬Ás/call
343 }
344}
345
346#-----------------------------------------------------------------------------
347
348
# spent 1.50s (6.30ms+1.49) within Perl::Critic::Document::highest_explicit_perl_version which was called 149 times, avg 10.1ms/call: # 144 times (6.18ms+1.42s) by Perl::Critic::Policy::Variables::RequireLexicalLoopIterators::prepare_to_scan_document at line 41 of Perl/Critic/Policy/Variables/RequireLexicalLoopIterators.pm, avg 9.89ms/call # 5 times (121┬Ás+74.3ms) by Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen::violates at line 47 of Perl/Critic/Policy/InputOutput/ProhibitTwoArgOpen.pm, avg 14.9ms/call
sub highest_explicit_perl_version {
34914949┬Ás my ($self) = @_;
350
35114984┬Ás my $highest_explicit_perl_version =
352 $self->{_highest_explicit_perl_version};
353
354149116┬Ás if ( not exists $self->{_highest_explicit_perl_version} ) {
355144286┬Ás1441.49s my $includes = $self->find( \&_is_a_version_statement );
# spent 1.49s making 144 calls to Perl::Critic::Document::find, avg 10.3ms/call
356
357144351┬Ás if ($includes) {
358 # Note: this doesn't use List::Util::max() because that function
359 # doesn't use the overloaded ">=" etc of a version object. The
360 # reduce() style lets version.pm take care of all comparing.
361 #
362 # For reference, max() ends up looking at the string converted to
363 # an NV, or something like that. An underscore like "5.005_04"
364 # provokes a warning and is chopped off at "5.005" thus losing the
365 # minor part from the comparison.
366 #
367 # An underscore "5.005_04" is supposed to mean an alpha release
368 # and shouldn't be used in a perl version. But it's shown in
369 # perlfunc under "use" (as a number separator), and appears in
370 # several modules supplied with perl 5.10.0 (like version.pm
371 # itself!). At any rate if version.pm can understand it then
372 # that's enough for here.
373 $highest_explicit_perl_version =
374 reduce { $a >= $b ? $a : $b }
3751421.32ms2844.83ms map { version->new( $_->version() ) }
# spent 4.21ms making 142 calls to PPI::Statement::Include::version, avg 30┬Ás/call # spent 625┬Ás making 142 calls to version::new, avg 4┬Ás/call
3761423.60ms142480┬Ás @{$includes};
# spent 480┬Ás making 142 calls to List::Util::reduce, avg 3┬Ás/call
377 }
378 else {
3792800ns $highest_explicit_perl_version = undef;
380 }
381
382144407┬Ás $self->{_highest_explicit_perl_version} =
383 $highest_explicit_perl_version;
384 }
385
3861491.44ms147590┬Ás return $highest_explicit_perl_version if $highest_explicit_perl_version;
# spent 590┬Ás making 147 calls to version::(bool, avg 4┬Ás/call
38727┬Ás return;
388}
389
390#-----------------------------------------------------------------------------
391
392sub uses_module {
393 my ($self, $module_name) = @_;
394
395 return exists $self->_modules_used()->{$module_name};
396}
397
398#-----------------------------------------------------------------------------
399
400
# spent 1.78s (1.82ms+1.78) within Perl::Critic::Document::process_annotations which was called 144 times, avg 12.4ms/call: # 144 times (1.82ms+1.78s) by Perl::Critic::_gather_violations at line 128 of Perl/Critic.pm, avg 12.4ms/call
sub process_annotations {
40114454┬Ás my ($self) = @_;
402
403144755┬Ás1441.77s my @annotations = Perl::Critic::Annotation->create_annotations($self);
# spent 1.77s making 144 calls to Perl::Critic::Annotation::create_annotations, avg 12.3ms/call
404144352┬Ás1442.35ms $self->add_annotation(@annotations);
# spent 2.35ms making 144 calls to Perl::Critic::Document::add_annotation, avg 16┬Ás/call
405144330┬Ás return $self;
406}
407
408#-----------------------------------------------------------------------------
409
410
# spent 12┬Ás within Perl::Critic::Document::line_is_disabled_for_policy which was called 3 times, avg 4┬Ás/call: # 3 times (12┬Ás+0s) by Perl::Critic::_critique at line 186 of Perl/Critic.pm, avg 4┬Ás/call
sub line_is_disabled_for_policy {
4113900ns my ($self, $line, $policy) = @_;
41232┬Ás my $policy_name = ref $policy || $policy;
413
414 # HACK: This Policy is special. If it is active, it cannot be
415 # disabled by a "## no critic" annotation. Rather than create a general
416 # hook in Policy.pm for enabling this behavior, we chose to hack
417 # it here, since this isn't the kind of thing that most policies do
418
4193800ns return 0 if $policy_name eq
420 'Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic';
421
422313┬Ás return 1 if $self->{_disabled_line_map}->{$line}->{$policy_name};
423 return 1 if $self->{_disabled_line_map}->{$line}->{ALL};
424 return 0;
425}
426
427#-----------------------------------------------------------------------------
428
429
# spent 2.35ms (2.00+351┬Ás) within Perl::Critic::Document::add_annotation which was called 144 times, avg 16┬Ás/call: # 144 times (2.00ms+351┬Ás) by Perl::Critic::Document::process_annotations at line 404, avg 16┬Ás/call
sub add_annotation {
43014487┬Ás my ($self, @annotations) = @_;
431
432 # Add annotation to our private map for quick lookup
433144133┬Ás for my $annotation (@annotations) {
434
4355191┬Ás51104┬Ás my ($start, $end) = $annotation->effective_range();
# spent 104┬Ás making 51 calls to Perl::Critic::Annotation::effective_range, avg 2┬Ás/call
43651192┬Ás102247┬Ás my @affected_policies = $annotation->disables_all_policies ?
# spent 152┬Ás making 51 calls to Perl::Critic::Annotation::disabled_policies, avg 3┬Ás/call # spent 96┬Ás making 51 calls to Perl::Critic::Annotation::disables_all_policies, avg 2┬Ás/call
437 qw(ALL) : $annotation->disabled_policies();
438
439 # TODO: Find clever way to do this with hash slices
4405184┬Ás for my $line ($start .. $end) {
441485158┬Ás for my $policy (@affected_policies) {
442510516┬Ás $self->{_disabled_line_map}->{$line}->{$policy} = 1;
443 }
444 }
445 }
446
447144120┬Ás push @{ $self->{_annotations} }, @annotations;
448144367┬Ás return $self;
449}
450
451#-----------------------------------------------------------------------------
452
453sub annotations {
454 my ($self) = @_;
455 return @{ $self->{_annotations} };
456}
457
458#-----------------------------------------------------------------------------
459
460
# spent 8┬Ás within Perl::Critic::Document::add_suppressed_violation which was called 3 times, avg 3┬Ás/call: # 3 times (8┬Ás+0s) by Perl::Critic::_critique at line 187 of Perl/Critic.pm, avg 3┬Ás/call
sub add_suppressed_violation {
4613900ns my ($self, $violation) = @_;
46232┬Ás push @{$self->{_suppressed_violations}}, $violation;
46337┬Ás return $self;
464}
465
466#-----------------------------------------------------------------------------
467
468sub suppressed_violations {
469 my ($self) = @_;
470 return @{ $self->{_suppressed_violations} };
471}
472
473#-----------------------------------------------------------------------------
474
475sub is_program {
476 my ($self) = @_;
477
478 return not $self->is_module();
479}
480
481#-----------------------------------------------------------------------------
482
483
# spent 345┬Ás within Perl::Critic::Document::is_module which was called 144 times, avg 2┬Ás/call: # 144 times (345┬Ás+0s) by Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::prepare_to_scan_document at line 39 of Perl/Critic/Policy/Modules/RequireFilenameMatchesPackage.pm, avg 2┬Ás/call
sub is_module {
48414447┬Ás my ($self) = @_;
485
486144432┬Ás return $self->{_is_module};
487}
488
489#-----------------------------------------------------------------------------
490# PRIVATE functions & methods
491
492
# spent 513ms (374+139) within Perl::Critic::Document::_is_a_version_statement which was called 110552 times, avg 5┬Ás/call: # 110552 times (374ms+139ms) by PPI::Node::find at line 381 of PPI/Node.pm, avg 5┬Ás/call
sub _is_a_version_statement {
49311055225.1ms my (undef, $element) = @_;
494
495110552579ms110552109ms return 0 if not $element->isa('PPI::Statement::Include');
# spent 90.8ms making 107866 calls to UNIVERSAL::isa, avg 842ns/call # spent 18.2ms making 2683 calls to PPI::Structure::List::isa, avg 7┬Ás/call # spent 19┬Ás making 3 calls to PPI::Structure::For::isa, avg 6┬Ás/call
4969821.27ms98229.8ms return 1 if $element->version();
# spent 29.8ms making 982 calls to PPI::Statement::Include::version, avg 30┬Ás/call
4978401.42ms return 0;
498}
499
500#-----------------------------------------------------------------------------
501
502
# spent 1.15ms within Perl::Critic::Document::_caching_finder which was called 144 times, avg 8┬Ás/call: # 144 times (1.15ms+0s) by Perl::Critic::Document::find at line 178, avg 8┬Ás/call
sub _caching_finder {
50314460┬Ás my $cache_ref = shift; # These vars will persist for the life
50414487┬Ás my %isa_cache = (); # of the code ref that this sub returns
505
506
507 # Gather up all the PPI elements and sort by @ISA. Note: if any
508 # instances used multiple inheritance, this implementation would
509 # lead to multiple copies of $element in the $elements_of lists.
510 # However, PPI::* doesn't do multiple inheritance, so we are safe
511
512
# spent 515ms within Perl::Critic::Document::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Document.pm:531] which was called 110552 times, avg 5┬Ás/call: # 110552 times (515ms+0s) by PPI::Node::find at line 381 of PPI/Node.pm, avg 5┬Ás/call
return sub {
51311055227.9ms my (undef, $element) = @_;
51411055237.2ms my $classes = $isa_cache{ref $element};
51511055210.8ms if ( !$classes ) {
51642302.71ms $classes = [ ref $element ];
517 # Use a C-style loop because we append to the classes array inside
51842309.88ms for ( my $i = 0; $i < @{$classes}; $i++ ) { ## no critic(ProhibitCStyleForLoops)
5192462┬Ás234┬Ás
# spent 21┬Ás (9+13) within Perl::Critic::Document::BEGIN@519 which was called: # once (9┬Ás+13┬Ás) by Perl::Critic::BEGIN@26 at line 519
no strict 'refs'; ## no critic(ProhibitNoStrict)
# spent 21┬Ás making 1 call to Perl::Critic::Document::BEGIN@519 # spent 13┬Ás making 1 call to strict::unimport
5201669521.6ms push @{$classes}, @{"$classes->[$i]::ISA"};
521166957.14ms $cache_ref->{$classes->[$i]} ||= [];
522 }
52342301.83ms $isa_cache{$classes->[0]} = $classes;
524 }
525
52611055247.5ms for my $class ( @{$classes} ) {
527356657160ms push @{$cache_ref->{$class}}, $element;
528 }
529
530110552427ms return 0; # 0 tells find() to keep traversing, but not to store this $element
5311441.06ms };
532}
533
534#-----------------------------------------------------------------------------
535
536
# spent 15.6ms (5.08+10.5) within Perl::Critic::Document::_disable_shebang_fix which was called 144 times, avg 109┬Ás/call: # 144 times (5.08ms+10.5ms) by Perl::Critic::Document::_init_from_external_source at line 124, avg 109┬Ás/call
sub _disable_shebang_fix {
53714464┬Ás my ($self) = @_;
538
539 # When you install a program using ExtUtils::MakeMaker or Module::Build, it
540 # inserts some magical code into the top of the file (just after the
541 # shebang). This code allows people to call your program using a shell,
542 # like `sh my_script`. Unfortunately, this code causes several Policy
543 # violations, so we disable them as if they had "## no critic" annotations.
544
5451441.37ms2886.31ms my $first_stmnt = $self->schild(0) || return;
# spent 6.13ms making 144 calls to Perl::Critic::Document::AUTOLOAD, avg 43┬Ás/call # spent 180┬Ás making 144 calls to PPI::Util::TRUE, avg 1┬Ás/call
546
547 # Different versions of MakeMaker and Build use slightly different shebang
548 # fixing strings. This matches most of the ones I've found in my own Perl
549 # distribution, but it may not be bullet-proof.
550
551144720┬Ás144372┬Ás my $fixin_rx = qr<^eval 'exec .* \$0 \$[{]1[+]"\$@"}'\s*[\r\n]\s*if.+;>ms; ## no critic (ExtendedFormatting)
# spent 372┬Ás making 144 calls to Perl::Critic::Document::CORE:qr, avg 3┬Ás/call
5521443.61ms4326.91ms if ( $first_stmnt =~ $fixin_rx ) {
# spent 3.48ms making 144 calls to Perl::Critic::Document::CORE:match, avg 24┬Ás/call # spent 3.04ms making 144 calls to PPI::Node::content, avg 21┬Ás/call # spent 383┬Ás making 144 calls to Perl::Critic::Document::CORE:regcomp, avg 3┬Ás/call
553 my $line = $first_stmnt->location->[0];
554 $self->{_disabled_line_map}->{$line}->{ALL} = 1;
555 $self->{_disabled_line_map}->{$line + 1}->{ALL} = 1;
556 }
557
558144469┬Ás return $self;
559}
560
561#-----------------------------------------------------------------------------
562
563
# spent 10.4ms (3.67+6.75) within Perl::Critic::Document::_determine_is_module which was called 144 times, avg 72┬Ás/call: # 144 times (3.67ms+6.75ms) by Perl::Critic::Document::_init_from_external_source at line 126, avg 72┬Ás/call
sub _determine_is_module {
56414464┬Ás my ($self, $args) = @_;
565
566144388┬Ás1441.90ms my $file_name = $self->filename();
# spent 1.90ms making 144 calls to Perl::Critic::Document::filename, avg 13┬Ás/call
567144250┬Ás if (
568 defined $file_name
569 and ref $args->{'-program-extensions'} eq 'ARRAY'
570 ) {
571144173┬Ás foreach my $ext ( @{ $args->{'-program-extensions'} } ) {
572 my $regex =
573 ref $ext eq 'Regexp'
574 ? $ext
575144139┬Ás : qr< @{ [ quotemeta $ext ] } \z >xms;
576
577144986┬Ás288375┬Ás return $FALSE if $file_name =~ m/$regex/smx;
# spent 268┬Ás making 144 calls to Perl::Critic::Document::CORE:regcomp, avg 2┬Ás/call # spent 106┬Ás making 144 calls to Perl::Critic::Document::CORE:match, avg 740ns/call
578 }
579 }
580
581144417┬Ás1444.02ms return $FALSE if shebang_line($self);
# spent 4.02ms making 144 calls to Perl::Critic::Utils::shebang_line, avg 28┬Ás/call
582144393┬Ás144123┬Ás return $FALSE if defined $file_name && $file_name =~ m/ [.] PL \z /smx;
# spent 123┬Ás making 144 calls to Perl::Critic::Document::CORE:match, avg 854ns/call
583
584144698┬Ás return $TRUE;
585}
586
587#-----------------------------------------------------------------------------
588
589sub _nodes_by_namespace {
590 my ($self) = @_;
591
592 my $nodes = $self->{_nodes_by_namespace};
593
594 return $nodes if $nodes;
595
596 my $ppi_document = $self->ppi_document();
597 if (not $ppi_document) {
598 return $self->{_nodes_by_namespace} = {};
599 }
600
601 my $raw_nodes_map = split_ppi_node_by_namespace($ppi_document);
602
603 my %wrapped_nodes;
604 while ( my ($namespace, $raw_nodes) = each %{$raw_nodes_map} ) {
605 $wrapped_nodes{$namespace} = [
606 map { __PACKAGE__->_new_for_parent_document($_, $self) }
607 @{$raw_nodes}
608 ];
609 }
610
611 return $self->{_nodes_by_namespace} = \%wrapped_nodes;
612}
613
614#-----------------------------------------------------------------------------
615
616# Note: must use exists on return value to determine membership because all
617# the values are false, unlike the result of hashify().
618sub _modules_used {
619 my ($self) = @_;
620
621 my $mapping = $self->{_modules_used};
622
623 return $mapping if $mapping;
624
625 my $includes = $self->find('PPI::Statement::Include');
626 if (not $includes) {
627 return $self->{_modules_used} = {};
628 }
629
630 my %mapping;
631 for my $module (
632 grep { $_ } map { $_->module() || $_->pragma() } @{$includes}
633 ) {
634 # Significanly ess memory than $h{$k} => 1. Thanks Mr. Lembark.
635 $mapping{$module} = ();
636 }
637
638 return $self->{_modules_used} = \%mapping;
639}
640
641#-----------------------------------------------------------------------------
642
64313┬Ás1;
644
645__END__
 
# spent 11.4ms (8.40+3.04) within Perl::Critic::Document::CORE:match which was called 4608 times, avg 2┬Ás/call: # 3456 times (5.19ms+0s) by Perl::Critic::Document::find at line 160, avg 2┬Ás/call # 576 times (2.36ms+0s) by Perl::Critic::Document::AUTOLOAD at line 38, avg 4┬Ás/call # 144 times (440┬Ás+3.04ms) by Perl::Critic::Document::_disable_shebang_fix at line 552, avg 24┬Ás/call # 144 times (180┬Ás+0s) by Perl::Critic::Document::find_first at line 194, avg 1┬Ás/call # 144 times (123┬Ás+0s) by Perl::Critic::Document::_determine_is_module at line 582, avg 854ns/call # 144 times (106┬Ás+0s) by Perl::Critic::Document::_determine_is_module at line 577, avg 740ns/call
sub Perl::Critic::Document::CORE:match; # opcode
# spent 372┬Ás within Perl::Critic::Document::CORE:qr which was called 144 times, avg 3┬Ás/call: # 144 times (372┬Ás+0s) by Perl::Critic::Document::_disable_shebang_fix at line 551, avg 3┬Ás/call
sub Perl::Critic::Document::CORE:qr; # opcode
# spent 651┬Ás within Perl::Critic::Document::CORE:regcomp which was called 288 times, avg 2┬Ás/call: # 144 times (383┬Ás+0s) by Perl::Critic::Document::_disable_shebang_fix at line 552, avg 3┬Ás/call # 144 times (268┬Ás+0s) by Perl::Critic::Document::_determine_is_module at line 577, avg 2┬Ás/call
sub Perl::Critic::Document::CORE:regcomp; # opcode