Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm |
Statements | Executed 96840 statements in 241ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
144 | 1 | 1 | 78.2ms | 431ms | violates | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
10538 | 1 | 1 | 67.7ms | 85.8ms | _statement_isnt_include_or_package | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
144 | 1 | 1 | 39.0ms | 128ms | _find_isnt_include_or_package | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
2011 | 1 | 1 | 18.1ms | 51.9ms | __ANON__[:116] | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
144 | 1 | 1 | 902µs | 902µs | _generate_is_use_strict | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
144 | 1 | 1 | 279µs | 279µs | default_maximum_violations_per_document | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
144 | 1 | 1 | 267µs | 267µs | applies_to | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
1 | 1 | 1 | 16µs | 16µs | BEGIN@10 | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
1 | 1 | 1 | 15µs | 40µs | BEGIN@14 | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
1 | 1 | 1 | 14µs | 16µs | supported_parameters | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
1 | 1 | 1 | 8µs | 29µs | BEGIN@16 | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
1 | 1 | 1 | 8µs | 28µs | BEGIN@15 | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
1 | 1 | 1 | 7µs | 11µs | BEGIN@12 | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
1 | 1 | 1 | 7µs | 18µs | BEGIN@11 | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
1 | 1 | 1 | 7µs | 56µs | BEGIN@19 | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
1 | 1 | 1 | 7µs | 169µs | BEGIN@18 | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::
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::Policy::TestingAndDebugging::RequireUseStrict; | ||||
9 | |||||
10 | 2 | 43µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@10 which was called:
# once (16µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 16µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@10 |
11 | 2 | 20µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@11 which was called:
# once (7µs+11µs) by Module::Pluggable::Object::_require at line 11 # spent 18µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 22µs | 2 | 15µs | # spent 11µs (7+4) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@12 which was called:
# once (7µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 11µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | 3 | 37µs | 3 | 66µs | # spent 40µs (15+26) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@14 which was called:
# once (15µs+26µs) by Module::Pluggable::Object::_require at line 14 # spent 40µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@14
# spent 17µs making 1 call to version::import
# spent 8µs making 1 call to UNIVERSAL::VERSION |
15 | 2 | 22µs | 2 | 48µs | # spent 28µs (8+20) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@15 which was called:
# once (8µs+20µs) by Module::Pluggable::Object::_require at line 15 # spent 28µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@15
# spent 20µs making 1 call to Exporter::import |
16 | 2 | 22µs | 2 | 50µs | # spent 29µs (8+21) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@16 which was called:
# once (8µs+21µs) by Module::Pluggable::Object::_require at line 16 # spent 29µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@16
# spent 21µs making 1 call to Exporter::import |
17 | |||||
18 | 2 | 23µs | 2 | 331µs | # spent 169µs (7+162) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@18 which was called:
# once (7µs+162µs) by Module::Pluggable::Object::_require at line 18 # spent 169µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@18
# spent 162µs making 1 call to Exporter::import |
19 | 2 | 460µs | 2 | 106µs | # spent 56µs (7+49) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@19 which was called:
# once (7µs+49µs) by Module::Pluggable::Object::_require at line 19 # spent 56µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::BEGIN@19
# spent 49µs making 1 call to base::import |
20 | |||||
21 | 1 | 500ns | our $VERSION = '1.121'; | ||
22 | |||||
23 | #----------------------------------------------------------------------------- | ||||
24 | |||||
25 | 1 | 2µs | 1 | 28µs | Readonly::Scalar my $DESC => q{Code before strictures are enabled}; # spent 28µs making 1 call to Readonly::Scalar |
26 | 1 | 2µs | 1 | 42µs | Readonly::Scalar my $EXPL => [ 429 ]; # spent 42µs making 1 call to Readonly::Scalar |
27 | |||||
28 | 1 | 2µs | 2 | 32µs | Readonly::Scalar my $PERL_VERSION_WHICH_IMPLIES_STRICTURE => qv('v5.11.0'); # spent 21µs making 1 call to Readonly::Scalar
# spent 11µs making 1 call to version::__ANON__[version.pm:151] |
29 | |||||
30 | #----------------------------------------------------------------------------- | ||||
31 | |||||
32 | # spent 16µs (14+2) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::supported_parameters which was called:
# once (14µs+2µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
33 | return ( | ||||
34 | { | ||||
35 | 1 | 11µs | 2 | 2µs | name => 'equivalent_modules', # spent 2µs making 2 calls to Readonly::Scalar::FETCH, avg 1µs/call |
36 | description => | ||||
37 | q<The additional modules to treat as equivalent to "strict".>, | ||||
38 | default_string => $EMPTY, | ||||
39 | behavior => 'string list', | ||||
40 | list_always_present_values => | ||||
41 | [ qw< strict Moose Moose::Role Moose::Util::TypeConstraints > ], | ||||
42 | }, | ||||
43 | ); | ||||
44 | } | ||||
45 | |||||
46 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
47 | sub default_themes { return qw( core pbp bugs certrule certrec ) } | ||||
48 | 144 | 1.97ms | # spent 267µs within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::applies_to which was called 144 times, avg 2µs/call:
# 144 times (267µs+0s) by Perl::Critic::_critique at line 165 of Perl/Critic.pm, avg 2µs/call | ||
49 | |||||
50 | 144 | 2.08ms | # spent 279µs within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::default_maximum_violations_per_document which was called 144 times, avg 2µs/call:
# 144 times (279µs+0s) by Perl::Critic::Policy::get_maximum_violations_per_document at line 308 of Perl/Critic/Policy.pm, avg 2µs/call | ||
51 | |||||
52 | #----------------------------------------------------------------------------- | ||||
53 | |||||
54 | # spent 431ms (78.2+353) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::violates which was called 144 times, avg 3.00ms/call:
# 144 times (78.2ms+353ms) by Perl::Critic::_critique at line 183 of Perl/Critic.pm, avg 3.00ms/call | ||||
55 | 144 | 104µs | my ( $self, undef, $doc ) = @_; | ||
56 | |||||
57 | # Find the first 'use strict' statement | ||||
58 | 144 | 1.31ms | 288 | 81.2ms | my $strict_stmnt = $doc->find_first( $self->_generate_is_use_strict() ); # spent 80.3ms making 144 calls to Perl::Critic::Document::find_first, avg 558µs/call
# spent 902µs making 144 calls to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::_generate_is_use_strict, avg 6µs/call |
59 | 144 | 832µs | 288 | 2.54ms | my $strict_line = $strict_stmnt ? $strict_stmnt->location()->[0] : undef; # spent 2.44ms making 144 calls to PPI::Node::location, avg 17µs/call
# spent 104µs making 144 calls to PPI::Util::TRUE, avg 725ns/call |
60 | |||||
61 | # Find all statements that aren't 'use', 'require', or 'package' | ||||
62 | 144 | 352µs | 144 | 128ms | my $stmnts_ref = $self->_find_isnt_include_or_package($doc); # spent 128ms making 144 calls to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::_find_isnt_include_or_package, avg 892µs/call |
63 | 144 | 34µs | return if not $stmnts_ref; | ||
64 | |||||
65 | # If the 'use strict' statement is not defined, or the other | ||||
66 | # statement appears before the 'use strict', then it violates. | ||||
67 | |||||
68 | 144 | 74µs | my @viols = (); | ||
69 | 144 | 138µs | for my $stmnt ( @{ $stmnts_ref } ) { | ||
70 | 9412 | 36.8ms | 9412 | 10.9ms | last if $stmnt->isa('PPI::Statement::End'); # spent 10.9ms making 9412 calls to UNIVERSAL::isa, avg 1µs/call |
71 | 9268 | 28.1ms | 9268 | 8.83ms | last if $stmnt->isa('PPI::Statement::Data'); # spent 8.83ms making 9268 calls to UNIVERSAL::isa, avg 953ns/call |
72 | |||||
73 | 9268 | 11.8ms | 9268 | 121ms | my $stmnt_line = $stmnt->location()->[0]; # spent 121ms making 9268 calls to PPI::Node::location, avg 13µs/call |
74 | 9268 | 3.86ms | if ( (! defined $strict_line) || ($stmnt_line < $strict_line) ) { | ||
75 | push @viols, $self->violation( $DESC, $EXPL, $stmnt ); | ||||
76 | } | ||||
77 | } | ||||
78 | 144 | 706µs | return @viols; | ||
79 | } | ||||
80 | |||||
81 | #----------------------------------------------------------------------------- | ||||
82 | |||||
83 | # spent 902µs within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::_generate_is_use_strict which was called 144 times, avg 6µs/call:
# 144 times (902µs+0s) by Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::violates at line 58, avg 6µs/call | ||||
84 | 144 | 51µs | my ($self) = @_; | ||
85 | |||||
86 | # spent 51.9ms (18.1+33.8) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/TestingAndDebugging/RequireUseStrict.pm:116] which was called 2011 times, avg 26µs/call:
# 2011 times (18.1ms+33.8ms) by PPI::Node::find_first at line 438 of PPI/Node.pm, avg 26µs/call | ||||
87 | 2011 | 562µs | my (undef, $elem) = @_; | ||
88 | |||||
89 | 2011 | 20.8ms | 2011 | 2.01ms | return 0 if !$elem->isa('PPI::Statement::Include'); # spent 2.01ms making 2011 calls to UNIVERSAL::isa, avg 998ns/call |
90 | 286 | 364µs | 286 | 5.09ms | return 0 if $elem->type() ne 'use'; # spent 5.09ms making 286 calls to PPI::Statement::Include::type, avg 18µs/call |
91 | |||||
92 | # We only want file-scoped pragmas | ||||
93 | 286 | 409µs | 286 | 1.21ms | my $parent = $elem->parent(); # spent 1.21ms making 286 calls to PPI::Element::parent, avg 4µs/call |
94 | 286 | 1.02ms | 286 | 324µs | return 0 if !$parent->isa('PPI::Document'); # spent 324µs making 286 calls to UNIVERSAL::isa, avg 1µs/call |
95 | |||||
96 | 286 | 1.73ms | 570 | 22.6ms | if ( my $pragma = $elem->pragma() ) { # spent 10.7ms making 286 calls to PPI::Statement::Include::pragma, avg 37µs/call
# spent 6.43ms making 142 calls to PPI::Statement::Include::version, avg 45µs/call
# spent 5.44ms making 142 calls to PPI::Statement::Include::module, avg 38µs/call |
97 | return 1 if $self->{_equivalent_modules}{$pragma}; | ||||
98 | } | ||||
99 | elsif ( my $module = $elem->module() ) { | ||||
100 | return 1 if $self->{_equivalent_modules}{$module}; | ||||
101 | } | ||||
102 | elsif ( my $version = $elem->version() ) { | ||||
103 | # Currently Adam returns a string here. He has said he may return | ||||
104 | # a version object in the future, so best be prepared. | ||||
105 | 142 | 659µs | 142 | 162µs | if ( not blessed( $version ) or not $version->isa( 'version' ) ) { # spent 162µs making 142 calls to Scalar::Util::blessed, avg 1µs/call |
106 | 142 | 395µs | if ( 'v' ne substr $version, 0, 1 | ||
107 | and ( $version =~ tr/././ ) > 1 ) { | ||||
108 | $version = 'v' . $version; | ||||
109 | } | ||||
110 | 142 | 1.52ms | 142 | 732µs | $version = version->parse( $version ); # spent 732µs making 142 calls to version::parse, avg 5µs/call |
111 | } | ||||
112 | 142 | 4.88ms | 568 | 1.97ms | return 1 if $PERL_VERSION_WHICH_IMPLIES_STRICTURE <= $version; # spent 1.46ms making 142 calls to version::(<=>, avg 10µs/call
# spent 502µs making 426 calls to Readonly::Scalar::FETCH, avg 1µs/call |
113 | } | ||||
114 | |||||
115 | 142 | 611µs | return 0; | ||
116 | 144 | 1.01ms | }; | ||
117 | } | ||||
118 | |||||
119 | #----------------------------------------------------------------------------- | ||||
120 | # Here, we're using the fact that Perl::Critic::Document::find() is optimized | ||||
121 | # to search for elements based on their type. This is faster than using the | ||||
122 | # native PPI::Node::find() method with a custom callback function. | ||||
123 | |||||
124 | # spent 128ms (39.0+89.5) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::_find_isnt_include_or_package which was called 144 times, avg 892µs/call:
# 144 times (39.0ms+89.5ms) by Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::violates at line 62, avg 892µs/call | ||||
125 | 144 | 73µs | my ($self, $doc) = @_; | ||
126 | 144 | 242µs | 144 | 3.63ms | my $all_statements = $doc->find('PPI::Statement') or return; # spent 3.63ms making 144 calls to Perl::Critic::Document::find, avg 25µs/call |
127 | 10682 | 10.9ms | 10538 | 85.8ms | my @wanted_statements = grep { _statement_isnt_include_or_package($_) } @{$all_statements}; # spent 85.8ms making 10538 calls to Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::_statement_isnt_include_or_package, avg 8µs/call |
128 | 144 | 474µs | return @wanted_statements ? \@wanted_statements : (); | ||
129 | } | ||||
130 | |||||
131 | #----------------------------------------------------------------------------- | ||||
132 | |||||
133 | # spent 85.8ms (67.7+18.1) within Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::_statement_isnt_include_or_package which was called 10538 times, avg 8µs/call:
# 10538 times (67.7ms+18.1ms) by Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict::_find_isnt_include_or_package at line 127, avg 8µs/call | ||||
134 | 10538 | 1.79ms | my ($elem) = @_; | ||
135 | 10538 | 35.7ms | 10538 | 9.42ms | return 0 if $elem->isa('PPI::Statement::Package'); # spent 9.42ms making 10538 calls to UNIVERSAL::isa, avg 894ns/call |
136 | 10394 | 39.8ms | 10394 | 8.71ms | return 0 if $elem->isa('PPI::Statement::Include'); # spent 8.71ms making 10394 calls to UNIVERSAL::isa, avg 838ns/call |
137 | 9412 | 29.5ms | return 1; | ||
138 | } | ||||
139 | |||||
140 | 1 | 4µs | 1; | ||
141 | |||||
142 | __END__ |