Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/TestingAndDebugging/RequireUseWarnings.pm |
Statements | Executed 23 statements in 636µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 16µs | 16µs | BEGIN@10 | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
1 | 1 | 1 | 13µs | 15µs | supported_parameters | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
1 | 1 | 1 | 12µs | 43µs | BEGIN@15 | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
1 | 1 | 1 | 8µs | 12µs | BEGIN@12 | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
1 | 1 | 1 | 8µs | 28µs | BEGIN@13 | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
1 | 1 | 1 | 7µs | 18µs | BEGIN@11 | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
1 | 1 | 1 | 7µs | 58µs | BEGIN@19 | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
1 | 1 | 1 | 7µs | 176µs | BEGIN@18 | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
1 | 1 | 1 | 6µs | 8µs | default_severity | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
1 | 1 | 1 | 3µs | 3µs | BEGIN@16 | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
0 | 0 | 0 | 0s | 0s | __ANON__[:107] | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
0 | 0 | 0 | 0s | 0s | _find_isnt_include_or_package | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
0 | 0 | 0 | 0s | 0s | _generate_is_use_warnings | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
0 | 0 | 0 | 0s | 0s | _statement_isnt_include_or_package | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
0 | 0 | 0 | 0s | 0s | default_maximum_violations_per_document | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::
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::RequireUseWarnings; | ||||
9 | |||||
10 | 2 | 39µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::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::RequireUseWarnings::BEGIN@10 |
11 | 2 | 24µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::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::RequireUseWarnings::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 18µs | 2 | 16µs | # spent 12µs (8+4) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@12 which was called:
# once (8µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 12µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 22µs | 2 | 48µs | # spent 28µs (8+20) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@13 which was called:
# once (8µs+20µs) by Module::Pluggable::Object::_require at line 13 # spent 28µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@13
# spent 20µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 22µs | 2 | 55µs | # spent 43µs (12+30) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@15 which was called:
# once (12µs+30µs) by Module::Pluggable::Object::_require at line 15 # spent 43µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@15
# spent 12µs making 1 call to List::Util::import |
16 | 2 | 19µs | 1 | 3µs | # spent 3µs within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@16 which was called:
# once (3µs+0s) by Module::Pluggable::Object::_require at line 16 # spent 3µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@16 |
17 | |||||
18 | 2 | 27µs | 2 | 345µs | # spent 176µs (7+169) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@18 which was called:
# once (7µs+169µs) by Module::Pluggable::Object::_require at line 18 # spent 176µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@18
# spent 169µs making 1 call to Exporter::import |
19 | 2 | 435µs | 2 | 110µs | # spent 58µs (7+51) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@19 which was called:
# once (7µs+51µs) by Module::Pluggable::Object::_require at line 19 # spent 58µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@19
# spent 51µs making 1 call to base::import |
20 | |||||
21 | 1 | 600ns | our $VERSION = '1.121'; | ||
22 | |||||
23 | #----------------------------------------------------------------------------- | ||||
24 | |||||
25 | 1 | 2µs | 1 | 30µs | Readonly::Scalar my $DESC => q{Code before warnings are enabled}; # spent 30µs making 1 call to Readonly::Scalar |
26 | 1 | 2µs | 1 | 44µs | Readonly::Scalar my $EXPL => [431]; # spent 44µs making 1 call to Readonly::Scalar |
27 | |||||
28 | 1 | 10µs | 2 | 28µs | Readonly::Scalar my $MINIMUM_VERSION => version->new(5.006); # spent 22µs making 1 call to Readonly::Scalar
# spent 6µs making 1 call to version::new |
29 | |||||
30 | #----------------------------------------------------------------------------- | ||||
31 | |||||
32 | # spent 15µs (13+2) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::supported_parameters which was called:
# once (13µ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 "warnings".>, | ||||
38 | default_string => $EMPTY, | ||||
39 | behavior => 'string list', | ||||
40 | list_always_present_values => | ||||
41 | [ qw< warnings Moose Moose::Role Moose::Util::TypeConstraints > ], | ||||
42 | }, | ||||
43 | ); | ||||
44 | } | ||||
45 | |||||
46 | 1 | 2µs | # spent 8µs (6+1) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::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 ) } | ||||
48 | sub applies_to { return 'PPI::Document' } | ||||
49 | |||||
50 | sub default_maximum_violations_per_document { return 1; } | ||||
51 | |||||
52 | #----------------------------------------------------------------------------- | ||||
53 | |||||
54 | sub violates { | ||||
55 | my ( $self, undef, $document ) = @_; | ||||
56 | |||||
57 | my $version = $document->highest_explicit_perl_version(); | ||||
58 | return if $version and $version < $MINIMUM_VERSION; | ||||
59 | |||||
60 | # Find the first 'use warnings' statement | ||||
61 | my $warn_stmnt = $document->find_first( $self->_generate_is_use_warnings() ); | ||||
62 | my $warn_line = $warn_stmnt ? $warn_stmnt->location()->[0] : undef; | ||||
63 | |||||
64 | # Find all statements that aren't 'use', 'require', or 'package' | ||||
65 | my $stmnts_ref = $self->_find_isnt_include_or_package($document); | ||||
66 | return if !$stmnts_ref; | ||||
67 | |||||
68 | # If the 'use warnings' statement is not defined, or the other | ||||
69 | # statement appears before the 'use warnings', then it violates. | ||||
70 | |||||
71 | my @viols = (); | ||||
72 | for my $stmnt ( @{ $stmnts_ref } ) { | ||||
73 | last if $stmnt->isa('PPI::Statement::End'); | ||||
74 | last if $stmnt->isa('PPI::Statement::Data'); | ||||
75 | |||||
76 | my $stmnt_line = $stmnt->location()->[0]; | ||||
77 | if ( (! defined $warn_line) || ($stmnt_line < $warn_line) ) { | ||||
78 | push @viols, $self->violation( $DESC, $EXPL, $stmnt ); | ||||
79 | } | ||||
80 | } | ||||
81 | return @viols; | ||||
82 | } | ||||
83 | |||||
84 | #----------------------------------------------------------------------------- | ||||
85 | |||||
86 | sub _generate_is_use_warnings { | ||||
87 | my ($self) = @_; | ||||
88 | |||||
89 | return sub { | ||||
90 | my (undef, $elem) = @_; | ||||
91 | |||||
92 | return 0 if !$elem->isa('PPI::Statement::Include'); | ||||
93 | return 0 if $elem->type() ne 'use'; | ||||
94 | |||||
95 | # We only want file-scoped pragmas | ||||
96 | my $parent = $elem->parent(); | ||||
97 | return 0 if !$parent->isa('PPI::Document'); | ||||
98 | |||||
99 | if ( my $pragma = $elem->pragma() ) { | ||||
100 | return 1 if $self->{_equivalent_modules}{$pragma}; | ||||
101 | } | ||||
102 | elsif ( my $module = $elem->module() ) { | ||||
103 | return 1 if $self->{_equivalent_modules}{$module}; | ||||
104 | } | ||||
105 | |||||
106 | return 0; | ||||
107 | }; | ||||
108 | } | ||||
109 | |||||
110 | #----------------------------------------------------------------------------- | ||||
111 | # Here, we're using the fact that Perl::Critic::Document::find() is optimized | ||||
112 | # to search for elements based on their type. This is faster than using the | ||||
113 | # native PPI::Node::find() method with a custom callback function. | ||||
114 | |||||
115 | sub _find_isnt_include_or_package { | ||||
116 | my ($self, $doc) = @_; | ||||
117 | my $all_statements = $doc->find('PPI::Statement') or return; | ||||
118 | my @wanted_statements = grep { _statement_isnt_include_or_package($_) } @{$all_statements}; | ||||
119 | return @wanted_statements ? \@wanted_statements : (); | ||||
120 | } | ||||
121 | |||||
122 | #----------------------------------------------------------------------------- | ||||
123 | |||||
124 | sub _statement_isnt_include_or_package { | ||||
125 | my ($elem) = @_; | ||||
126 | return 0 if $elem->isa('PPI::Statement::Package'); | ||||
127 | return 0 if $elem->isa('PPI::Statement::Include'); | ||||
128 | return 1; | ||||
129 | } | ||||
130 | |||||
131 | 1 | 4µs | 1; | ||
132 | |||||
133 | __END__ |