← 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:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/ControlStructures/ProhibitUnreachableCode.pm
StatementsExecuted 24 statements in 523µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11115µs15µsPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::BEGIN@10Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@10
1117µs27µsPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::BEGIN@13Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@13
1117µs63µsPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::BEGIN@16Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@16
1117µs10µsPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::BEGIN@12Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@12
1117µs430µsPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::BEGIN@15Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@15
1116µs17µsPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::BEGIN@11Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@11
1116µs7µsPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::default_severityPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::default_severity
1112µs2µsPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::supported_parametersPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::supported_parameters
0000s0sPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::_gather_violationsPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::_gather_violations
0000s0sPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::applies_toPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::applies_to
0000s0sPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::default_themesPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::default_themes
0000s0sPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::::violatesPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::violates
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::Policy::ControlStructures::ProhibitUnreachableCode;
9
10237µs115µ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
use 5.006001;
11219µs228µ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
use strict;
# spent 17µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@11 # spent 11µs making 1 call to strict::import
12221µs214µ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
use warnings;
# spent 10µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@12 # spent 4µs making 1 call to warnings::import
13227µs248µ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
use Readonly;
# spent 27µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@13 # spent 20µs making 1 call to Exporter::import
14
15223µs2853µ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
use Perl::Critic::Utils qw{ :severities :data_conversion :classification };
# spent 430µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@15 # spent 423µs making 1 call to Exporter::import
162352µs2119µ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
use base 'Perl::Critic::Policy';
# spent 63µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode::BEGIN@16 # spent 56µs making 1 call to base::import
17
181500nsour $VERSION = '1.121';
19
2012µs127µsReadonly::Array my @TERMINALS => qw( die exit croak confess );
# spent 27µs making 1 call to Readonly::Array
2116µs345µsReadonly::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
2311µs121µsReadonly::Array my @CONDITIONALS => qw( if unless foreach while until for );
# spent 21µs making 1 call to Readonly::Array
2416µs351µsReadonly::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
2611µs121µsReadonly::Array my @OPERATORS => qw( && || // and or err ? );
# spent 21µs making 1 call to Readonly::Array
2717µs356µsReadonly::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
3111µs123µsReadonly::Scalar my $DESC => q{Unreachable code};
# spent 23µs making 1 call to Readonly::Scalar
321900ns120µsReadonly::Scalar my $EXPL => q{Consider removing it};
# spent 20µs making 1 call to Readonly::Scalar
33
34#-----------------------------------------------------------------------------
35
3615µ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
sub supported_parameters { return () }
3712µ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
sub default_severity { return $SEVERITY_HIGH }
38sub default_themes { return qw( core bugs certrec ) }
39sub applies_to { return 'PPI::Token::Word' }
40
41#-----------------------------------------------------------------------------
42
43sub 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
74sub _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
105110µs1;
106
107__END__