Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Modules/ProhibitConditionalUseStatements.pm |
Statements | Executed 19 statements in 506µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 16µs | 16µs | BEGIN@10 | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
1 | 1 | 1 | 10µs | 14µs | BEGIN@12 | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
1 | 1 | 1 | 7µs | 61µs | BEGIN@16 | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
1 | 1 | 1 | 7µs | 28µs | BEGIN@13 | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
1 | 1 | 1 | 7µs | 9µs | default_severity | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
1 | 1 | 1 | 7µs | 191µs | BEGIN@15 | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
1 | 1 | 1 | 7µs | 18µs | BEGIN@11 | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
1 | 1 | 1 | 2µs | 2µs | supported_parameters | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
0 | 0 | 0 | 0s | 0s | _is_compound_statement | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
0 | 0 | 0 | 0s | 0s | _is_eval | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
0 | 0 | 0 | 0s | 0s | _is_in_conditional_logic | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
0 | 0 | 0 | 0s | 0s | _is_in_do_conditional_block | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::
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::Modules::ProhibitConditionalUseStatements; | ||||
9 | |||||
10 | 2 | 39µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::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::Modules::ProhibitConditionalUseStatements::BEGIN@10 |
11 | 2 | 23µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::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::Modules::ProhibitConditionalUseStatements::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 19µs | 2 | 18µs | # spent 14µs (10+4) within Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::BEGIN@12 which was called:
# once (10µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 14µs making 1 call to Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 22µs | 2 | 48µs | # spent 28µs (7+21) within Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::BEGIN@13 which was called:
# once (7µs+21µs) by Module::Pluggable::Object::_require at line 13 # spent 28µs making 1 call to Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::BEGIN@13
# spent 21µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 24µs | 2 | 376µs | # spent 191µs (7+184) within Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::BEGIN@15 which was called:
# once (7µs+184µs) by Module::Pluggable::Object::_require at line 15 # spent 191µs making 1 call to Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::BEGIN@15
# spent 184µs making 1 call to Exporter::import |
16 | 2 | 362µs | 2 | 114µs | # spent 61µs (7+53) within Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::BEGIN@16 which was called:
# once (7µs+53µs) by Module::Pluggable::Object::_require at line 16 # spent 61µs making 1 call to Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::BEGIN@16
# spent 53µs making 1 call to base::import |
17 | |||||
18 | 1 | 600ns | our $VERSION = '1.121'; | ||
19 | |||||
20 | #----------------------------------------------------------------------------- | ||||
21 | |||||
22 | 1 | 2µs | 1 | 28µs | Readonly::Scalar my $DESC => q{Conditional "use" statement}; # spent 28µs making 1 call to Readonly::Scalar |
23 | 1 | 1µs | 1 | 21µs | Readonly::Scalar my $EXPL => q{Use "require" to conditionally include a module.}; # spent 21µs making 1 call to Readonly::Scalar |
24 | |||||
25 | # operators | ||||
26 | |||||
27 | 1 | 3µs | 1 | 25µs | Readonly::Hash my %OPS => map { $_ => 1 } qw( || && or and ); # spent 25µs making 1 call to Readonly::Hash |
28 | |||||
29 | #----------------------------------------------------------------------------- | ||||
30 | |||||
31 | 1 | 5µs | # spent 2µs within Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::supported_parameters which was called:
# once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
32 | 1 | 2µs | # spent 9µs (7+2) within Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements::default_severity which was called:
# once (7µs+2µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
33 | sub default_themes { return qw( core bugs ) } | ||||
34 | sub applies_to { return 'PPI::Statement::Include' } | ||||
35 | |||||
36 | #----------------------------------------------------------------------------- | ||||
37 | |||||
38 | sub violates { | ||||
39 | my ( $self, $elem, $doc ) = @_; | ||||
40 | return $self->violation( $DESC, $EXPL, $elem ) if $elem->type() eq 'use' | ||||
41 | && !$elem->pragma() | ||||
42 | && $elem->module() | ||||
43 | && $self->_is_in_conditional_logic($elem); | ||||
44 | return; | ||||
45 | } | ||||
46 | |||||
47 | #----------------------------------------------------------------------------- | ||||
48 | |||||
49 | # is this a non-string eval statement | ||||
50 | |||||
51 | sub _is_eval { | ||||
52 | my ( $self, $elem ) = @_; | ||||
53 | $elem->isa('PPI::Statement') or return; | ||||
54 | my $first_elem = $elem->first_element(); | ||||
55 | return $TRUE if $first_elem->isa('PPI::Token::Word') | ||||
56 | && $first_elem eq 'eval'; | ||||
57 | return; | ||||
58 | } | ||||
59 | |||||
60 | #----------------------------------------------------------------------------- | ||||
61 | |||||
62 | # is this in a conditional do block | ||||
63 | |||||
64 | sub _is_in_do_conditional_block { | ||||
65 | my ( $self, $elem ) = @_; | ||||
66 | return if !$elem->isa('PPI::Structure::Block'); | ||||
67 | my $prev_sibling = $elem->sprevious_sibling() or return; | ||||
68 | if ($prev_sibling->isa('PPI::Token::Word') && $prev_sibling eq 'do') { | ||||
69 | my $next_sibling = $elem->snext_sibling(); | ||||
70 | return $TRUE if $next_sibling | ||||
71 | && $next_sibling->isa('PPI::Token::Word'); | ||||
72 | $prev_sibling = $prev_sibling->sprevious_sibling() or return; | ||||
73 | return $TRUE if $prev_sibling->isa('PPI::Token::Operator') | ||||
74 | && $OPS{$prev_sibling->content()}; | ||||
75 | } | ||||
76 | return; | ||||
77 | } | ||||
78 | |||||
79 | #----------------------------------------------------------------------------- | ||||
80 | |||||
81 | # is this a compound statement | ||||
82 | |||||
83 | sub _is_compound_statement { | ||||
84 | my ( $self, $elem ) = @_; | ||||
85 | return if !$elem->isa('PPI::Statement::Compound'); | ||||
86 | return $TRUE if $elem->type() ne 'continue'; # exclude bare blocks | ||||
87 | return; | ||||
88 | } | ||||
89 | |||||
90 | #----------------------------------------------------------------------------- | ||||
91 | |||||
92 | # is this contained in conditional logic | ||||
93 | |||||
94 | sub _is_in_conditional_logic { | ||||
95 | my ( $self, $elem ) = @_; | ||||
96 | while ($elem = $elem->parent()) { | ||||
97 | last if $elem->isa('PPI::Document'); | ||||
98 | return $TRUE if $self->_is_compound_statement($elem) | ||||
99 | || $self->_is_eval($elem) | ||||
100 | || $self->_is_in_do_conditional_block($elem); | ||||
101 | } | ||||
102 | return; | ||||
103 | } | ||||
104 | |||||
105 | 1 | 5µs | 1; | ||
106 | |||||
107 | __END__ |