Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Document.pm |
Statements | Executed 1207006 statements in 1.44s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
110552 | 1 | 1 | 515ms | 515ms | __ANON__[:531] | Perl::Critic::Document::
110552 | 1 | 1 | 374ms | 513ms | _is_a_version_statement | Perl::Critic::Document::
3600 | 7 | 5 | 25.7ms | 3.17s | find | Perl::Critic::Document::
4608 | 6 | 1 | 8.40ms | 11.4ms | CORE:match (opcode) | Perl::Critic::Document::
149 | 2 | 2 | 6.30ms | 1.50s | highest_explicit_perl_version | Perl::Critic::Document::
576 | 4 | 3 | 5.67ms | 4.48s | AUTOLOAD | Perl::Critic::Document::
144 | 1 | 1 | 5.08ms | 15.6ms | _disable_shebang_fix | Perl::Critic::Document::
144 | 1 | 1 | 4.93ms | 16.5s | _init_from_external_source | Perl::Critic::Document::
144 | 1 | 1 | 3.67ms | 10.4ms | _determine_is_module | Perl::Critic::Document::
288 | 2 | 2 | 2.10ms | 82.3ms | find_first | Perl::Critic::Document::
144 | 1 | 1 | 2.01ms | 16.5s | new | Perl::Critic::Document::
144 | 1 | 1 | 2.00ms | 2.35ms | add_annotation | Perl::Critic::Document::
144 | 1 | 1 | 1.82ms | 1.78s | process_annotations | Perl::Critic::Document::
144 | 1 | 1 | 1.41ms | 1.90ms | filename | Perl::Critic::Document::
144 | 1 | 1 | 1.15ms | 1.15ms | _caching_finder | Perl::Critic::Document::
1 | 1 | 1 | 1.04ms | 1.88ms | BEGIN@24 | Perl::Critic::Document::
1 | 1 | 1 | 886µs | 38.0ms | BEGIN@28 | Perl::Critic::Document::
1 | 1 | 1 | 706µs | 1.42ms | BEGIN@22 | Perl::Critic::Document::
144 | 1 | 1 | 674µs | 674µs | _init_common | Perl::Critic::Document::
288 | 2 | 1 | 651µs | 651µs | CORE:regcomp (opcode) | Perl::Critic::Document::
144 | 1 | 1 | 638µs | 757µs | _is_ppi_doc | Perl::Critic::Document::
144 | 1 | 1 | 372µs | 372µs | CORE:qr (opcode) | Perl::Critic::Document::
144 | 1 | 1 | 345µs | 345µs | is_module | Perl::Critic::Document::
1 | 1 | 1 | 47µs | 52µs | BEGIN@12 | Perl::Critic::Document::
1 | 1 | 1 | 26µs | 26µs | BEGIN@10 | Perl::Critic::Document::
1 | 1 | 1 | 18µs | 48µs | BEGIN@16 | Perl::Critic::Document::
3 | 1 | 1 | 12µs | 12µs | line_is_disabled_for_policy | Perl::Critic::Document::
1 | 1 | 1 | 12µs | 49µs | BEGIN@25 | Perl::Critic::Document::
1 | 1 | 1 | 10µs | 46µs | BEGIN@17 | Perl::Critic::Document::
1 | 1 | 1 | 9µs | 9µs | BEGIN@21 | Perl::Critic::Document::
1 | 1 | 1 | 9µs | 34µs | BEGIN@14 | Perl::Critic::Document::
1 | 1 | 1 | 9µs | 21µs | BEGIN@519 | Perl::Critic::Document::
1 | 1 | 1 | 8µs | 25µs | BEGIN@18 | Perl::Critic::Document::
1 | 1 | 1 | 8µs | 294µs | BEGIN@26 | Perl::Critic::Document::
3 | 1 | 1 | 8µs | 8µs | add_suppressed_violation | Perl::Critic::Document::
1 | 1 | 1 | 7µs | 20µs | BEGIN@11 | Perl::Critic::Document::
1 | 1 | 1 | 6µs | 6µs | BEGIN@20 | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | __ANON__[:374] | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | _find_use_re_modifiers_in_scope_from_element | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | _modules_used | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | _new_for_parent_document | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | _nodes_by_namespace | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | annotations | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | element_is_in_lexical_scope_after_statement_containing | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | find_any | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | is_program | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | isa | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | namespaces | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | ppi_document | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | ppix_regexp_from_element | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | subdocuments_for_namespace | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | suppressed_violations | Perl::Critic::Document::
0 | 0 | 0 | 0s | 0s | uses_module | Perl::Critic::Document::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | ############################################################################## | ||||
2 | # $URL$ | ||||
3 | # $Date$ | ||||
4 | # $Author$ | ||||
5 | # $Revision$ | ||||
6 | ############################################################################## | ||||
7 | |||||
8 | package Perl::Critic::Document; | ||||
9 | |||||
10 | 2 | 44µs | 1 | 26µ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 # spent 26µs making 1 call to Perl::Critic::Document::BEGIN@10 |
11 | 2 | 30µs | 2 | 32µ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 # spent 20µs making 1 call to Perl::Critic::Document::BEGIN@11
# spent 13µs making 1 call to strict::import |
12 | 2 | 24µs | 2 | 58µ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 # spent 52µs making 1 call to Perl::Critic::Document::BEGIN@12
# spent 6µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 24µs | 2 | 59µ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 # spent 34µs making 1 call to Perl::Critic::Document::BEGIN@14
# spent 25µs making 1 call to Exporter::import |
15 | |||||
16 | 2 | 29µs | 2 | 57µ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 # spent 48µs making 1 call to Perl::Critic::Document::BEGIN@16
# spent 9µs making 1 call to List::Util::import |
17 | 2 | 24µs | 2 | 82µ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 # spent 46µs making 1 call to Perl::Critic::Document::BEGIN@17
# spent 36µs making 1 call to Exporter::import |
18 | 2 | 24µs | 2 | 41µ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 # spent 25µs making 1 call to Perl::Critic::Document::BEGIN@18
# spent 16µs making 1 call to version::import |
19 | |||||
20 | 2 | 20µs | 1 | 6µ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 # spent 6µs making 1 call to Perl::Critic::Document::BEGIN@20 |
21 | 2 | 24µs | 1 | 9µ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 # spent 9µs making 1 call to Perl::Critic::Document::BEGIN@21 |
22 | 2 | 95µs | 2 | 1.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 # spent 1.42ms making 1 call to Perl::Critic::Document::BEGIN@22
# spent 37µs making 1 call to Exporter::import |
23 | |||||
24 | 2 | 92µs | 1 | 1.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 # spent 1.88ms making 1 call to Perl::Critic::Document::BEGIN@24 |
25 | 2 | 27µs | 2 | 86µ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 # spent 49µs making 1 call to Perl::Critic::Document::BEGIN@25
# spent 37µs making 1 call to Exporter::import |
26 | 2 | 26µs | 2 | 580µ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 # spent 294µs making 1 call to Perl::Critic::Document::BEGIN@26
# spent 286µs making 1 call to Exporter::import |
27 | |||||
28 | 3 | 1.59ms | 2 | 38.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 # spent 38.0ms making 1 call to Perl::Critic::Document::BEGIN@28
# spent 12µs making 1 call to UNIVERSAL::VERSION |
29 | |||||
30 | #----------------------------------------------------------------------------- | ||||
31 | |||||
32 | 1 | 600ns | our $VERSION = '1.121'; | ||
33 | |||||
34 | #----------------------------------------------------------------------------- | ||||
35 | |||||
36 | 1 | 100ns | our $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 | ||||
38 | 576 | 4.22ms | 576 | 2.36ms | my ( $function_name ) = $AUTOLOAD =~ m/ ([^:\']+) \z /xms; # spent 2.36ms making 576 calls to Perl::Critic::Document::CORE:match, avg 4µs/call |
39 | 576 | 275µs | return if $function_name eq 'DESTROY'; | ||
40 | 576 | 224µs | my $self = shift; | ||
41 | 576 | 3.02ms | 576 | 4.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 | ||||
47 | 144 | 224µs | my ($class, @args) = @_; | ||
48 | |||||
49 | 144 | 217µs | my $self = bless {}, $class; | ||
50 | |||||
51 | 144 | 287µs | 144 | 674µs | $self->_init_common(); # spent 674µs making 144 calls to Perl::Critic::Document::_init_common, avg 5µs/call |
52 | 144 | 303µs | 144 | 16.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 | |||||
54 | 144 | 675µs | return $self; | ||
55 | } | ||||
56 | |||||
57 | #----------------------------------------------------------------------------- | ||||
58 | |||||
59 | sub _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 | ||||
75 | 144 | 47µs | my ($self) = @_; | ||
76 | |||||
77 | 144 | 184µs | $self->{_annotations} = []; | ||
78 | 144 | 97µs | $self->{_suppressed_violations} = []; | ||
79 | 144 | 68µs | $self->{_disabled_line_map} = {}; | ||
80 | |||||
81 | 144 | 400µ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 | ||||
87 | 144 | 51µs | my $self = shift; | ||
88 | 144 | 33µs | my %args; | ||
89 | |||||
90 | 144 | 113µ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 { | ||||
97 | 144 | 228µs | %args = @_; | ||
98 | } | ||||
99 | |||||
100 | 144 | 107µ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 | |||||
106 | 144 | 825µs | 288 | 13.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 | ||||
114 | 144 | 49µ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 | |||||
122 | 144 | 185µs | $self->{_doc} = $ppi_document; | ||
123 | 144 | 881µs | 144 | 3.24s | $self->index_locations(); # spent 3.24s making 144 calls to Perl::Critic::Document::AUTOLOAD, avg 22.5ms/call |
124 | 144 | 495µs | 144 | 15.6ms | $self->_disable_shebang_fix(); # spent 15.6ms making 144 calls to Perl::Critic::Document::_disable_shebang_fix, avg 109µs/call |
125 | 144 | 185µs | $self->{_filename_override} = $args{'-filename-override'}; | ||
126 | 144 | 847µs | 288 | 10.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 | |||||
128 | 144 | 627µ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 | ||||
134 | 144 | 55µs | my ($ref) = @_; | ||
135 | 144 | 783µs | 144 | 119µ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 | |||||
140 | sub ppi_document { | ||||
141 | my ($self) = @_; | ||||
142 | return $self->{_doc}; | ||||
143 | } | ||||
144 | |||||
145 | #----------------------------------------------------------------------------- | ||||
146 | |||||
147 | sub 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 | ||||
156 | 3600 | 1.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 | ||||
160 | 3600 | 15.9ms | 3600 | 1.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. | ||||
168 | 3456 | 1.33ms | if ( !$self->{_elements_of} ) { | ||
169 | |||||
170 | 144 | 302µ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. | ||||
176 | 144 | 850µs | 144 | 422µs | weaken( $cache{'PPI::Document'}->[0] ); # spent 422µs making 144 calls to Scalar::Util::weaken, avg 3µs/call |
177 | |||||
178 | 144 | 354µs | 144 | 1.15ms | my $finder_coderef = _caching_finder( \%cache ); # spent 1.15ms making 144 calls to Perl::Critic::Document::_caching_finder, avg 8µs/call |
179 | 144 | 334µs | 144 | 1.66s | $self->{_doc}->find( $finder_coderef ); # spent 1.66s making 144 calls to PPI::Node::find, avg 11.5ms/call |
180 | 144 | 3.47ms | $self->{_elements_of} = \%cache; | ||
181 | } | ||||
182 | |||||
183 | # find() must return false-but-defined on fail | ||||
184 | 3456 | 8.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 | ||||
190 | 288 | 196µ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 | ||||
194 | 288 | 1.39ms | 288 | 79.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 | |||||
198 | 144 | 230µs | 144 | 659µs | my $result = $self->find($wanted); # spent 659µs making 144 calls to Perl::Critic::Document::find, avg 5µs/call |
199 | 144 | 497µs | return $result ? $result->[0] : $result; | ||
200 | } | ||||
201 | |||||
202 | #----------------------------------------------------------------------------- | ||||
203 | |||||
204 | sub 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 | |||||
219 | sub namespaces { | ||||
220 | my ($self) = @_; | ||||
221 | |||||
222 | return keys %{ $self->_nodes_by_namespace() }; | ||||
223 | } | ||||
224 | |||||
225 | #----------------------------------------------------------------------------- | ||||
226 | |||||
227 | sub 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 | |||||
237 | sub 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 | |||||
255 | sub _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 | |||||
284 | sub 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 | ||||
335 | 144 | 56µs | my ($self) = @_; | ||
336 | |||||
337 | 144 | 95µs | if (defined $self->{_filename_override}) { | ||
338 | return $self->{_filename_override}; | ||||
339 | } | ||||
340 | else { | ||||
341 | 144 | 54µs | my $doc = $self->{_doc}; | ||
342 | 144 | 1.23ms | 288 | 487µ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 | ||||
349 | 149 | 49µs | my ($self) = @_; | ||
350 | |||||
351 | 149 | 84µs | my $highest_explicit_perl_version = | ||
352 | $self->{_highest_explicit_perl_version}; | ||||
353 | |||||
354 | 149 | 116µs | if ( not exists $self->{_highest_explicit_perl_version} ) { | ||
355 | 144 | 286µs | 144 | 1.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 | |||||
357 | 144 | 351µ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 } | ||||
375 | 142 | 1.32ms | 284 | 4.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 |
376 | 142 | 3.60ms | 142 | 480µs | @{$includes}; # spent 480µs making 142 calls to List::Util::reduce, avg 3µs/call |
377 | } | ||||
378 | else { | ||||
379 | 2 | 800ns | $highest_explicit_perl_version = undef; | ||
380 | } | ||||
381 | |||||
382 | 144 | 407µs | $self->{_highest_explicit_perl_version} = | ||
383 | $highest_explicit_perl_version; | ||||
384 | } | ||||
385 | |||||
386 | 149 | 1.44ms | 147 | 590µs | return $highest_explicit_perl_version if $highest_explicit_perl_version; # spent 590µs making 147 calls to version::(bool, avg 4µs/call |
387 | 2 | 7µs | return; | ||
388 | } | ||||
389 | |||||
390 | #----------------------------------------------------------------------------- | ||||
391 | |||||
392 | sub 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 | ||||
401 | 144 | 54µs | my ($self) = @_; | ||
402 | |||||
403 | 144 | 755µs | 144 | 1.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 |
404 | 144 | 352µs | 144 | 2.35ms | $self->add_annotation(@annotations); # spent 2.35ms making 144 calls to Perl::Critic::Document::add_annotation, avg 16µs/call |
405 | 144 | 330µ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 | ||||
411 | 3 | 900ns | my ($self, $line, $policy) = @_; | ||
412 | 3 | 2µ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 | |||||
419 | 3 | 800ns | return 0 if $policy_name eq | ||
420 | 'Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic'; | ||||
421 | |||||
422 | 3 | 13µ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 | ||||
430 | 144 | 87µs | my ($self, @annotations) = @_; | ||
431 | |||||
432 | # Add annotation to our private map for quick lookup | ||||
433 | 144 | 133µs | for my $annotation (@annotations) { | ||
434 | |||||
435 | 51 | 91µs | 51 | 104µs | my ($start, $end) = $annotation->effective_range(); # spent 104µs making 51 calls to Perl::Critic::Annotation::effective_range, avg 2µs/call |
436 | 51 | 192µs | 102 | 247µ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 | ||||
440 | 51 | 84µs | for my $line ($start .. $end) { | ||
441 | 485 | 158µs | for my $policy (@affected_policies) { | ||
442 | 510 | 516µs | $self->{_disabled_line_map}->{$line}->{$policy} = 1; | ||
443 | } | ||||
444 | } | ||||
445 | } | ||||
446 | |||||
447 | 144 | 120µs | push @{ $self->{_annotations} }, @annotations; | ||
448 | 144 | 367µs | return $self; | ||
449 | } | ||||
450 | |||||
451 | #----------------------------------------------------------------------------- | ||||
452 | |||||
453 | sub 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 | ||||
461 | 3 | 900ns | my ($self, $violation) = @_; | ||
462 | 3 | 2µs | push @{$self->{_suppressed_violations}}, $violation; | ||
463 | 3 | 7µs | return $self; | ||
464 | } | ||||
465 | |||||
466 | #----------------------------------------------------------------------------- | ||||
467 | |||||
468 | sub suppressed_violations { | ||||
469 | my ($self) = @_; | ||||
470 | return @{ $self->{_suppressed_violations} }; | ||||
471 | } | ||||
472 | |||||
473 | #----------------------------------------------------------------------------- | ||||
474 | |||||
475 | sub 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 | ||||
484 | 144 | 47µs | my ($self) = @_; | ||
485 | |||||
486 | 144 | 432µ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 | ||||
493 | 110552 | 25.1ms | my (undef, $element) = @_; | ||
494 | |||||
495 | 110552 | 579ms | 110552 | 109ms | 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 |
496 | 982 | 1.27ms | 982 | 29.8ms | return 1 if $element->version(); # spent 29.8ms making 982 calls to PPI::Statement::Include::version, avg 30µs/call |
497 | 840 | 1.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 | ||||
503 | 144 | 60µs | my $cache_ref = shift; # These vars will persist for the life | ||
504 | 144 | 87µ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 | ||||
513 | 110552 | 27.9ms | my (undef, $element) = @_; | ||
514 | 110552 | 37.2ms | my $classes = $isa_cache{ref $element}; | ||
515 | 110552 | 10.8ms | if ( !$classes ) { | ||
516 | 4230 | 2.71ms | $classes = [ ref $element ]; | ||
517 | # Use a C-style loop because we append to the classes array inside | ||||
518 | 4230 | 9.88ms | for ( my $i = 0; $i < @{$classes}; $i++ ) { ## no critic(ProhibitCStyleForLoops) | ||
519 | 2 | 462µs | 2 | 34µ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 # spent 21µs making 1 call to Perl::Critic::Document::BEGIN@519
# spent 13µs making 1 call to strict::unimport |
520 | 16695 | 21.6ms | push @{$classes}, @{"$classes->[$i]::ISA"}; | ||
521 | 16695 | 7.14ms | $cache_ref->{$classes->[$i]} ||= []; | ||
522 | } | ||||
523 | 4230 | 1.83ms | $isa_cache{$classes->[0]} = $classes; | ||
524 | } | ||||
525 | |||||
526 | 110552 | 47.5ms | for my $class ( @{$classes} ) { | ||
527 | 356657 | 160ms | push @{$cache_ref->{$class}}, $element; | ||
528 | } | ||||
529 | |||||
530 | 110552 | 427ms | return 0; # 0 tells find() to keep traversing, but not to store this $element | ||
531 | 144 | 1.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 | ||||
537 | 144 | 64µ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 | |||||
545 | 144 | 1.37ms | 288 | 6.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 | |||||
551 | 144 | 720µs | 144 | 372µ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 |
552 | 144 | 3.61ms | 432 | 6.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 | |||||
558 | 144 | 469µ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 | ||||
564 | 144 | 64µs | my ($self, $args) = @_; | ||
565 | |||||
566 | 144 | 388µs | 144 | 1.90ms | my $file_name = $self->filename(); # spent 1.90ms making 144 calls to Perl::Critic::Document::filename, avg 13µs/call |
567 | 144 | 250µs | if ( | ||
568 | defined $file_name | ||||
569 | and ref $args->{'-program-extensions'} eq 'ARRAY' | ||||
570 | ) { | ||||
571 | 144 | 173µs | foreach my $ext ( @{ $args->{'-program-extensions'} } ) { | ||
572 | my $regex = | ||||
573 | ref $ext eq 'Regexp' | ||||
574 | ? $ext | ||||
575 | 144 | 139µs | : qr< @{ [ quotemeta $ext ] } \z >xms; | ||
576 | |||||
577 | 144 | 986µs | 288 | 375µ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 | |||||
581 | 144 | 417µs | 144 | 4.02ms | return $FALSE if shebang_line($self); # spent 4.02ms making 144 calls to Perl::Critic::Utils::shebang_line, avg 28µs/call |
582 | 144 | 393µs | 144 | 123µ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 | |||||
584 | 144 | 698µs | return $TRUE; | ||
585 | } | ||||
586 | |||||
587 | #----------------------------------------------------------------------------- | ||||
588 | |||||
589 | sub _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(). | ||||
618 | sub _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 | |||||
643 | 1 | 3µs | 1; | ||
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 | |||||
# 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:regcomp; # opcode |