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

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/BuiltinFunctions/ProhibitBooleanGrep.pm
StatementsExecuted 20 statements in 505µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11119µs19µsPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::BEGIN@10Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@10
1118µs58µsPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::BEGIN@16Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@16
1117µs28µsPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::BEGIN@13Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@13
1117µs411µsPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::BEGIN@15Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@15
1117µs11µsPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::BEGIN@12Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@12
1117µs18µsPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::BEGIN@11Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@11
1116µs8µsPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::default_severityPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::default_severity
1111µs1µsPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::supported_parametersPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::supported_parameters
0000s0sPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::_does_parent_cause_booleanPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::_does_parent_cause_boolean
0000s0sPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::_does_prev_sibling_cause_booleanPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::_does_prev_sibling_cause_boolean
0000s0sPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::_is_in_boolean_contextPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::_is_in_boolean_context
0000s0sPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::applies_toPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::applies_to
0000s0sPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::default_themesPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::default_themes
0000s0sPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::::violatesPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::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::BuiltinFunctions::ProhibitBooleanGrep;
9
10244µs119µs
# spent 19µs within Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@10 which was called: # once (19µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11220µs228µs
# spent 18µs (7+11) within Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@11 which was called: # once (7µs+11µs) by Module::Pluggable::Object::_require at line 11
use strict;
# spent 18µs making 1 call to Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@11 # spent 11µs making 1 call to strict::import
12218µs216µs
# spent 11µs (7+4) within Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@12 which was called: # once (7µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
# spent 11µs making 1 call to Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@12 # spent 4µs making 1 call to warnings::import
13227µs248µs
# spent 28µs (7+20) within Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@13 which was called: # once (7µs+20µs) by Module::Pluggable::Object::_require at line 13
use Readonly;
# spent 28µs making 1 call to Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@13 # spent 20µs making 1 call to Exporter::import
14
15224µs2816µs
# spent 411µs (7+404) within Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@15 which was called: # once (7µs+404µs) by Module::Pluggable::Object::_require at line 15
use Perl::Critic::Utils qw{ :severities :classification hashify };
# spent 411µs making 1 call to Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@15 # spent 404µs making 1 call to Exporter::import
162351µs2108µs
# spent 58µs (8+50) within Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@16 which was called: # once (8µs+50µs) by Module::Pluggable::Object::_require at line 16
use base 'Perl::Critic::Policy';
# spent 58µs making 1 call to Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::BEGIN@16 # spent 50µs making 1 call to base::import
17
181600nsour $VERSION = '1.121';
19
20#-----------------------------------------------------------------------------
21
2212µs129µsReadonly::Scalar my $DESC => q{"grep" used in boolean context};
# spent 29µs making 1 call to Readonly::Scalar
2312µs143µsReadonly::Scalar my $EXPL => [71,72];
# spent 43µs making 1 call to Readonly::Scalar
24
2513µs236µsReadonly::Hash my %POSTFIX_CONDITIONALS => hashify( qw(if unless while until) );
# spent 33µs making 1 call to Readonly::Hash # spent 4µs making 1 call to Perl::Critic::Utils::hashify
2612µs226µsReadonly::Hash my %BOOLEAN_OPERATORS => hashify( qw(&& || ! not or and));
# spent 24µs making 1 call to Readonly::Hash # spent 3µs making 1 call to Perl::Critic::Utils::hashify
27
28#-----------------------------------------------------------------------------
29
3014µs
# spent 1µs within Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::supported_parameters which was called: # once (1µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters { return () }
3112µs
# spent 8µs (6+1) within Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep::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_LOW }
32sub default_themes { return qw( core pbp performance certrec ) }
33sub applies_to { return 'PPI::Token::Word' }
34
35#-----------------------------------------------------------------------------
36
37sub violates {
38 my ( $self, $elem, undef ) = @_;
39
40 return if $elem ne 'grep';
41 return if not is_function_call($elem);
42 return if not _is_in_boolean_context($elem);
43
44 return $self->violation( $DESC, $EXPL, $elem );
45}
46
47#-----------------------------------------------------------------------------
48
49sub _is_in_boolean_context {
50 my ($token) = @_;
51
52 return _does_prev_sibling_cause_boolean($token) || _does_parent_cause_boolean($token);
53}
54
55sub _does_prev_sibling_cause_boolean {
56 my ($token) = @_;
57
58 my $prev = $token->sprevious_sibling;
59 return if !$prev;
60 return 1 if $prev->isa('PPI::Token::Word') and $POSTFIX_CONDITIONALS{$prev};
61 return if not ($prev->isa('PPI::Token::Operator') and $BOOLEAN_OPERATORS{$prev});
62 my $next = $token->snext_sibling;
63 return 1 if not $next; # bizarre: grep with no arguments
64
65 # loose heuristic: unparenthesized grep has no following non-boolean operators
66 return 1 if not $next->isa('PPI::Structure::List');
67
68 $next = $next->snext_sibling;
69 return 1 if not $next;
70 return 1 if $next->isa('PPI::Token::Operator') and $BOOLEAN_OPERATORS{$next};
71 return;
72}
73
74sub _does_parent_cause_boolean {
75 my ($token) = @_;
76
77 my $prev = $token->sprevious_sibling;
78 return if $prev;
79 my $parent = $token->statement->parent;
80 for (my $node = $parent; $node; $node = $node->parent) { ## no critic (CStyleForLoop)
81 next if $node->isa('PPI::Structure::List');
82 return 1 if $node->isa('PPI::Structure::Condition');
83 }
84
85 return;
86}
87
8816µs1;
89
90__END__