← 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/Perl/Critic/Utils/PPI.pm
StatementsExecuted 17 statements in 773µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11114µs14µsPerl::Critic::Utils::PPI::::BEGIN@10Perl::Critic::Utils::PPI::BEGIN@10
1117µs28µsPerl::Critic::Utils::PPI::::BEGIN@14Perl::Critic::Utils::PPI::BEGIN@14
1117µs12µsPerl::Critic::Utils::PPI::::BEGIN@18Perl::Critic::Utils::PPI::BEGIN@18
1117µs35µsPerl::Critic::Utils::PPI::::BEGIN@16Perl::Critic::Utils::PPI::BEGIN@16
1117µs10µsPerl::Critic::Utils::PPI::::BEGIN@12Perl::Critic::Utils::PPI::BEGIN@12
1116µs17µsPerl::Critic::Utils::PPI::::BEGIN@11Perl::Critic::Utils::PPI::BEGIN@11
0000s0sPerl::Critic::Utils::PPI::::_constant_name_from_constant_pragmaPerl::Critic::Utils::PPI::_constant_name_from_constant_pragma
0000s0sPerl::Critic::Utils::PPI::::get_constant_name_element_from_declaring_statementPerl::Critic::Utils::PPI::get_constant_name_element_from_declaring_statement
0000s0sPerl::Critic::Utils::PPI::::get_next_element_in_same_simple_statementPerl::Critic::Utils::PPI::get_next_element_in_same_simple_statement
0000s0sPerl::Critic::Utils::PPI::::get_previous_module_used_on_same_linePerl::Critic::Utils::PPI::get_previous_module_used_on_same_line
0000s0sPerl::Critic::Utils::PPI::::is_in_subroutinePerl::Critic::Utils::PPI::is_in_subroutine
0000s0sPerl::Critic::Utils::PPI::::is_ppi_constant_elementPerl::Critic::Utils::PPI::is_ppi_constant_element
0000s0sPerl::Critic::Utils::PPI::::is_ppi_expression_or_generic_statementPerl::Critic::Utils::PPI::is_ppi_expression_or_generic_statement
0000s0sPerl::Critic::Utils::PPI::::is_ppi_generic_statementPerl::Critic::Utils::PPI::is_ppi_generic_statement
0000s0sPerl::Critic::Utils::PPI::::is_ppi_simple_statementPerl::Critic::Utils::PPI::is_ppi_simple_statement
0000s0sPerl::Critic::Utils::PPI::::is_ppi_statement_subclassPerl::Critic::Utils::PPI::is_ppi_statement_subclass
0000s0sPerl::Critic::Utils::PPI::::is_subroutine_declarationPerl::Critic::Utils::PPI::is_subroutine_declaration
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::Utils::PPI;
9
10236µs114µs
# spent 14µs within Perl::Critic::Utils::PPI::BEGIN@10 which was called: # once (14µs+0s) by Perl::Critic::Utils::BEGIN@26 at line 10
use 5.006001;
# spent 14µs making 1 call to Perl::Critic::Utils::PPI::BEGIN@10
11217µs228µs
# spent 17µs (6+11) within Perl::Critic::Utils::PPI::BEGIN@11 which was called: # once (6µs+11µs) by Perl::Critic::Utils::BEGIN@26 at line 11
use strict;
# spent 17µs making 1 call to Perl::Critic::Utils::PPI::BEGIN@11 # spent 11µs making 1 call to strict::import
12217µs214µs
# spent 10µs (7+4) within Perl::Critic::Utils::PPI::BEGIN@12 which was called: # once (7µs+4µs) by Perl::Critic::Utils::BEGIN@26 at line 12
use warnings;
# spent 10µs making 1 call to Perl::Critic::Utils::PPI::BEGIN@12 # spent 4µs making 1 call to warnings::import
13
14221µs248µs
# spent 28µs (7+21) within Perl::Critic::Utils::PPI::BEGIN@14 which was called: # once (7µs+21µs) by Perl::Critic::Utils::BEGIN@26 at line 14
use Readonly;
# spent 28µs making 1 call to Perl::Critic::Utils::PPI::BEGIN@14 # spent 21µs making 1 call to Exporter::import
15
16221µs263µs
# spent 35µs (7+28) within Perl::Critic::Utils::PPI::BEGIN@16 which was called: # once (7µs+28µs) by Perl::Critic::Utils::BEGIN@26 at line 16
use Scalar::Util qw< blessed readonly >;
# spent 35µs making 1 call to Perl::Critic::Utils::PPI::BEGIN@16 # spent 28µs making 1 call to Exporter::import
17
182644µs217µs
# spent 12µs (7+5) within Perl::Critic::Utils::PPI::BEGIN@18 which was called: # once (7µs+5µs) by Perl::Critic::Utils::BEGIN@26 at line 18
use Exporter 'import';
# spent 12µs making 1 call to Perl::Critic::Utils::PPI::BEGIN@18 # spent 5µs making 1 call to Exporter::import
19
201600nsour $VERSION = '1.121';
21
22#-----------------------------------------------------------------------------
23
2412µsour @EXPORT_OK = qw(
25 is_ppi_expression_or_generic_statement
26 is_ppi_generic_statement
27 is_ppi_statement_subclass
28 is_ppi_simple_statement
29 is_ppi_constant_element
30 is_subroutine_declaration
31 is_in_subroutine
32 get_constant_name_element_from_declaring_statement
33 get_next_element_in_same_simple_statement
34 get_previous_module_used_on_same_line
35);
36
3711µsour %EXPORT_TAGS = (
38 all => \@EXPORT_OK,
39);
40
41#-----------------------------------------------------------------------------
42
43sub is_ppi_expression_or_generic_statement {
44 my $element = shift;
45
46 return if not $element;
47 return if not $element->isa('PPI::Statement');
48 return 1 if $element->isa('PPI::Statement::Expression');
49
50 my $element_class = blessed($element);
51
52 return if not $element_class;
53 return $element_class eq 'PPI::Statement';
54}
55
56#-----------------------------------------------------------------------------
57
58sub is_ppi_generic_statement {
59 my $element = shift;
60
61 my $element_class = blessed($element);
62
63 return if not $element_class;
64 return if not $element->isa('PPI::Statement');
65
66 return $element_class eq 'PPI::Statement';
67}
68
69#-----------------------------------------------------------------------------
70
71sub is_ppi_statement_subclass {
72 my $element = shift;
73
74 my $element_class = blessed($element);
75
76 return if not $element_class;
77 return if not $element->isa('PPI::Statement');
78
79 return $element_class ne 'PPI::Statement';
80}
81
82#-----------------------------------------------------------------------------
83
84# Can not use hashify() here because Perl::Critic::Utils already depends on
85# this module.
8616µs147µsReadonly::Hash my %SIMPLE_STATEMENT_CLASS => map { $_ => 1 } qw<
# spent 47µs making 1 call to Readonly::Hash
87 PPI::Statement
88 PPI::Statement::Break
89 PPI::Statement::Include
90 PPI::Statement::Null
91 PPI::Statement::Package
92 PPI::Statement::Variable
93>;
94
95sub is_ppi_simple_statement {
96 my $element = shift or return;
97
98 my $element_class = blessed( $element ) or return;
99
100 return $SIMPLE_STATEMENT_CLASS{ $element_class };
101}
102
103#-----------------------------------------------------------------------------
104
105sub is_ppi_constant_element {
106 my $element = shift or return;
107
108 blessed( $element ) or return;
109
110 # TODO implement here documents once PPI::Token::HereDoc grows the
111 # necessary PPI::Token::Quote interface.
112 return
113 $element->isa( 'PPI::Token::Number' )
114 || $element->isa( 'PPI::Token::Quote::Literal' )
115 || $element->isa( 'PPI::Token::Quote::Single' )
116 || $element->isa( 'PPI::Token::QuoteLike::Words' )
117 || (
118 $element->isa( 'PPI::Token::Quote::Double' )
119 || $element->isa( 'PPI::Token::Quote::Interpolate' ) )
120 && $element->string() !~ m< (?: \A | [^\\] ) (?: \\\\)* [\$\@] >smx
121 ;
122}
123
124#-----------------------------------------------------------------------------
125
126sub is_subroutine_declaration {
127 my $element = shift;
128
129 return if not $element;
130
131 return 1 if $element->isa('PPI::Statement::Sub');
132
133 if ( is_ppi_generic_statement($element) ) {
134 my $first_element = $element->first_element();
135
136 return 1 if
137 $first_element
138 and $first_element->isa('PPI::Token::Word')
139 and $first_element->content() eq 'sub';
140 }
141
142 return;
143}
144
145#-----------------------------------------------------------------------------
146
147sub is_in_subroutine {
148 my ($element) = @_;
149
150 return if not $element;
151 return 1 if is_subroutine_declaration($element);
152
153 while ( $element = $element->parent() ) {
154 return 1 if is_subroutine_declaration($element);
155 }
156
157 return;
158}
159
160#-----------------------------------------------------------------------------
161
162sub get_constant_name_element_from_declaring_statement {
163 my ($element) = @_;
164
165 warnings::warnif(
166 'deprecated',
167 'Perl::Critic::Utils::PPI::get_constant_name_element_from_declaring_statement() is deprecated. Use PPIx::Utilities::Statement::get_constant_name_elements_from_declaring_statement() instead.',
168 );
169
170 return if not $element;
171 return if not $element->isa('PPI::Statement');
172
173 if ( $element->isa('PPI::Statement::Include') ) {
174 my $pragma;
175 if ( $pragma = $element->pragma() and $pragma eq 'constant' ) {
176 return _constant_name_from_constant_pragma($element);
177 }
178 }
179 elsif (
180 is_ppi_generic_statement($element)
181 and $element->schild(0)->content() =~ m< \A Readonly \b >xms
182 ) {
183 return $element->schild(2);
184 }
185
186 return;
187}
188
189sub _constant_name_from_constant_pragma {
190 my ($include) = @_;
191
192 my @arguments = $include->arguments() or return;
193
194 my $follower = $arguments[0];
195 return if not defined $follower;
196
197 return $follower;
198}
199
200#-----------------------------------------------------------------------------
201
202sub get_next_element_in_same_simple_statement {
203 my $element = shift or return;
204
205 while ( $element and (
206 not is_ppi_simple_statement( $element )
207 or $element->parent()
208 and $element->parent()->isa( 'PPI::Structure::List' ) ) ) {
209 my $next;
210 $next = $element->snext_sibling() and return $next;
211 $element = $element->parent();
212 }
213 return;
214
215}
216
217#-----------------------------------------------------------------------------
218
219sub get_previous_module_used_on_same_line {
220 my $element = shift or return;
221
222 my ( $line ) = @{ $element->location() || []};
223
224 while (not is_ppi_simple_statement( $element )) {
225 $element = $element->parent() or return;
226 }
227
228 while ( $element = $element->sprevious_sibling() ) {
229 ( @{ $element->location() || []} )[0] == $line or return;
230 $element->isa( 'PPI::Statement::Include' )
231 and return $element->schild( 1 );
232 }
233
234 return;
235}
236
237#-----------------------------------------------------------------------------
238
23916µs1;
240
241__END__