Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/ControlStructures/ProhibitUnreachableCode.pm |
Statements | Executed 24 statements in 523µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 15µs | 15µs | BEGIN@10 | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
1 | 1 | 1 | 7µs | 27µs | BEGIN@13 | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
1 | 1 | 1 | 7µs | 63µs | BEGIN@16 | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
1 | 1 | 1 | 7µs | 10µs | BEGIN@12 | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
1 | 1 | 1 | 7µs | 430µs | BEGIN@15 | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
1 | 1 | 1 | 6µs | 17µs | BEGIN@11 | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
1 | 1 | 1 | 2µs | 2µs | supported_parameters | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
0 | 0 | 0 | 0s | 0s | _gather_violations | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::
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::ControlStructures::ProhibitUnreachableCode; | ||||
9 | |||||
10 | 2 | 37µs | 1 | 15µs | # spent 15µs within Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@10 which was called:
# once (15µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 15µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@10 |
11 | 2 | 19µs | 2 | 28µs | # spent 17µs (6+11) within Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@11 which was called:
# once (6µs+11µs) by Module::Pluggable::Object::_require at line 11 # spent 17µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 21µs | 2 | 14µs | # spent 10µs (7+3) within Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@12 which was called:
# once (7µs+3µs) by Module::Pluggable::Object::_require at line 12 # spent 10µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 27µs | 2 | 48µs | # spent 27µs (7+20) within Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@13 which was called:
# once (7µs+20µs) by Module::Pluggable::Object::_require at line 13 # spent 27µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@13
# spent 20µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 23µs | 2 | 853µs | # spent 430µs (7+423) within Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@15 which was called:
# once (7µs+423µs) by Module::Pluggable::Object::_require at line 15 # spent 430µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@15
# spent 423µs making 1 call to Exporter::import |
16 | 2 | 352µs | 2 | 119µs | # spent 63µs (7+56) within Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@16 which was called:
# once (7µs+56µs) by Module::Pluggable::Object::_require at line 16 # spent 63µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@16
# spent 56µs making 1 call to base::import |
17 | |||||
18 | 1 | 500ns | our $VERSION = '1.121'; | ||
19 | |||||
20 | 1 | 2µs | 1 | 27µs | Readonly::Array my @TERMINALS => qw( die exit croak confess ); # spent 27µs making 1 call to Readonly::Array |
21 | 1 | 6µs | 3 | 45µs | Readonly::Hash my %TERMINALS => hashify( @TERMINALS ); # spent 24µs making 1 call to Readonly::Hash
# spent 19µs making 1 call to Perl::Critic::Utils::hashify
# spent 1µs making 1 call to Readonly::Array::FETCHSIZE |
22 | |||||
23 | 1 | 1µs | 1 | 21µs | Readonly::Array my @CONDITIONALS => qw( if unless foreach while until for ); # spent 21µs making 1 call to Readonly::Array |
24 | 1 | 6µs | 3 | 51µs | Readonly::Hash my %CONDITIONALS => hashify( @CONDITIONALS ); # spent 26µs making 1 call to Perl::Critic::Utils::hashify
# spent 24µs making 1 call to Readonly::Hash
# spent 1µs making 1 call to Readonly::Array::FETCHSIZE |
25 | |||||
26 | 1 | 1µs | 1 | 21µs | Readonly::Array my @OPERATORS => qw( && || // and or err ? ); # spent 21µs making 1 call to Readonly::Array |
27 | 1 | 7µs | 3 | 56µs | Readonly::Hash my %OPERATORS => hashify( @OPERATORS ); # spent 29µs making 1 call to Perl::Critic::Utils::hashify
# spent 26µs making 1 call to Readonly::Hash
# spent 1µs making 1 call to Readonly::Array::FETCHSIZE |
28 | |||||
29 | #----------------------------------------------------------------------------- | ||||
30 | |||||
31 | 1 | 1µs | 1 | 23µs | Readonly::Scalar my $DESC => q{Unreachable code}; # spent 23µs making 1 call to Readonly::Scalar |
32 | 1 | 900ns | 1 | 20µs | Readonly::Scalar my $EXPL => q{Consider removing it}; # spent 20µs making 1 call to Readonly::Scalar |
33 | |||||
34 | #----------------------------------------------------------------------------- | ||||
35 | |||||
36 | 1 | 5µs | # spent 2µs within Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::supported_parameters which was called:
# once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
37 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
38 | sub default_themes { return qw( core bugs certrec ) } | ||||
39 | sub applies_to { return 'PPI::Token::Word' } | ||||
40 | |||||
41 | #----------------------------------------------------------------------------- | ||||
42 | |||||
43 | sub violates { | ||||
44 | my ( $self, $elem, undef ) = @_; | ||||
45 | |||||
46 | my $statement = $elem->statement(); | ||||
47 | return if not $statement; | ||||
48 | |||||
49 | # We check to see if this is an interesting token before calling | ||||
50 | # is_function_call(). This weeds out most candidate tokens and | ||||
51 | # prevents us from having to make an expensive function call. | ||||
52 | |||||
53 | return if ( !exists $TERMINALS{$elem} ) && | ||||
54 | ( !$statement->isa('PPI::Statement::Break') ); | ||||
55 | |||||
56 | return if not is_function_call($elem); | ||||
57 | |||||
58 | # Scan the enclosing statement for conditional keywords or logical | ||||
59 | # operators. If any are found, then this the following statements | ||||
60 | # could _potentially_ be executed, so this policy is satisfied. | ||||
61 | |||||
62 | # NOTE: When the first operand in an boolean expression is | ||||
63 | # C<croak> or C<die>, etc., the second operand is technically | ||||
64 | # unreachable. But this policy doesn't catch that situation. | ||||
65 | |||||
66 | for my $child ( $statement->schildren() ) { | ||||
67 | return if $child->isa('PPI::Token::Operator') && exists $OPERATORS{$child}; | ||||
68 | return if $child->isa('PPI::Token::Word') && exists $CONDITIONALS{$child}; | ||||
69 | } | ||||
70 | |||||
71 | return $self->_gather_violations($statement); | ||||
72 | } | ||||
73 | |||||
74 | sub _gather_violations { | ||||
75 | my ($self, $statement) = @_; | ||||
76 | |||||
77 | # If we get here, then the statement contained an unconditional | ||||
78 | # die or exit or return. Then all the subsequent sibling | ||||
79 | # statements are unreachable, except for those that have labels, | ||||
80 | # which could be reached from anywhere using C<goto>. Subroutine | ||||
81 | # declarations are also exempt for the same reason. "use" and | ||||
82 | # "our" statements are exempt because they happen at compile time. | ||||
83 | |||||
84 | my @violations = (); | ||||
85 | while ( $statement = $statement->snext_sibling() ) { | ||||
86 | my @children = $statement->schildren(); | ||||
87 | last if @children && $children[0]->isa('PPI::Token::Label'); | ||||
88 | next if $statement->isa('PPI::Statement::Sub'); | ||||
89 | next if $statement->isa('PPI::Statement::End'); | ||||
90 | next if $statement->isa('PPI::Statement::Data'); | ||||
91 | next if $statement->isa('PPI::Statement::Package'); | ||||
92 | |||||
93 | next if $statement->isa('PPI::Statement::Include') && | ||||
94 | $statement->type() ne 'require'; | ||||
95 | |||||
96 | next if $statement->isa('PPI::Statement::Variable') && | ||||
97 | $statement->type() eq 'our'; | ||||
98 | |||||
99 | push @violations, $self->violation( $DESC, $EXPL, $statement ); | ||||
100 | } | ||||
101 | |||||
102 | return @violations; | ||||
103 | } | ||||
104 | |||||
105 | 1 | 10µs | 1; | ||
106 | |||||
107 | __END__ |