← 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/CodeLayout/ProhibitParensWithBuiltins.pm
StatementsExecuted 26 statements in 806µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs16µsPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::BEGIN@10Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@10
11110µs30µsPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::BEGIN@13Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@13
1117µs18µsPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::BEGIN@11Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@11
1117µs145µsPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::BEGIN@15Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@15
1117µs58µsPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::BEGIN@20Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@20
1117µs11µsPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::BEGIN@12Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@12
1117µs498µsPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::BEGIN@17Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@17
1116µs7µsPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::default_severityPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::default_severity
1112µs2µsPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::supported_parametersPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::supported_parameters
0000s0sPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::_contains_operatorsPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::_contains_operators
0000s0sPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::_is_equals_exemptionPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::_is_equals_exemption
0000s0sPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::_is_named_unaryPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::_is_named_unary
0000s0sPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::_is_named_unary_with_operator_following_parens_exemptionPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::_is_named_unary_with_operator_following_parens_exemption
0000s0sPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::_is_named_unary_with_operator_inside_parens_exemptionPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::_is_named_unary_with_operator_inside_parens_exemption
0000s0sPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::_is_precedence_exemptionPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::_is_precedence_exemption
0000s0sPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::_is_sort_exemptionPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::_is_sort_exemption
0000s0sPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::applies_toPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::applies_to
0000s0sPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::default_themesPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::default_themes
0000s0sPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::::violatesPerl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::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::CodeLayout::ProhibitParensWithBuiltins;
9
10239µs116µs
# spent 16µs within Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@10 which was called: # once (16µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11220µs229µs
# spent 18µs (7+11) within Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::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::CodeLayout::ProhibitParensWithBuiltins::BEGIN@11 # spent 11µs making 1 call to strict::import
12218µs214µs
# spent 11µs (7+4) within Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::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::CodeLayout::ProhibitParensWithBuiltins::BEGIN@12 # spent 4µs making 1 call to warnings::import
13222µs250µs
# spent 30µs (10+20) within Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@13 which was called: # once (10µs+20µs) by Module::Pluggable::Object::_require at line 13
use Readonly;
# spent 30µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@13 # spent 20µs making 1 call to Exporter::import
14
15227µs2284µs
# spent 145µs (7+138) within Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@15 which was called: # once (7µs+138µs) by Module::Pluggable::Object::_require at line 15
use List::MoreUtils qw{any};
# spent 145µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@15 # spent 138µs making 1 call to Exporter::Tiny::import
16
171200ns
# spent 498µs (7+491) within Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@17 which was called: # once (7µs+491µs) by Module::Pluggable::Object::_require at line 19
use Perl::Critic::Utils qw{
18 :booleans :severities :data_conversion :classification :language
19125µs2988µs};
# spent 498µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@17 # spent 491µs making 1 call to Exporter::import
202578µs2109µs
# spent 58µs (7+51) within Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@20 which was called: # once (7µs+51µs) by Module::Pluggable::Object::_require at line 20
use base 'Perl::Critic::Policy';
# spent 58µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::BEGIN@20 # spent 51µs making 1 call to base::import
21
221600nsour $VERSION = '1.121';
23
24#-----------------------------------------------------------------------------
25
2612µs128µsReadonly::Array my @ALLOW => qw( my our local return state );
# spent 28µs making 1 call to Readonly::Array
27116µs350µsReadonly::Hash my %ALLOW => hashify( @ALLOW );
# spent 26µs making 1 call to Readonly::Hash # spent 23µs making 1 call to Perl::Critic::Utils::hashify # spent 1µs making 1 call to Readonly::Array::FETCHSIZE
28
2911µs124µsReadonly::Scalar my $DESC => q{Builtin function called with parentheses};
# spent 24µs making 1 call to Readonly::Scalar
3012µs152µsReadonly::Scalar my $EXPL => [ 13 ];
# spent 52µs making 1 call to Readonly::Scalar
31
3214µs242µsReadonly::Scalar my $PRECENDENCE_OF_LIST => precedence_of(q{>>}) + 1;
# spent 33µs making 1 call to Readonly::Scalar # spent 9µs making 1 call to Perl::Critic::Utils::precedence_of
3313µs228µsReadonly::Scalar my $PRECEDENCE_OF_COMMA => precedence_of(q{,});
# spent 21µs making 1 call to Readonly::Scalar # spent 7µs making 1 call to Perl::Critic::Utils::precedence_of
34
35#-----------------------------------------------------------------------------
36# These are all the functions that are considered named unary
37# operators. These frequently require parentheses because they have lower
38# precedence than ordinary function calls.
39
4012µs148µsReadonly::Array my @NAMED_UNARY_OPS => qw(
# spent 48µs making 1 call to Readonly::Array
41 alarm glob rand
42 caller gmtime readlink
43 chdir hex ref
44 chroot int require
45 cos lc return
46 defined lcfirst rmdir
47 delete length scalar
48 do localtime sin
49 eval lock sleep
50 exists log sqrt
51 exit lstat srand
52 getgrp my stat
53 gethostbyname oct uc
54 getnetbyname ord ucfirst
55 getprotobyname quotemeta umask
56 undef
57);
58125µs33.25msReadonly::Hash my %NAMED_UNARY_OPS => hashify( @NAMED_UNARY_OPS );
# spent 3.16ms making 1 call to Perl::Critic::Utils::hashify # spent 91µs making 1 call to Readonly::Hash # spent 1µs making 1 call to Readonly::Array::FETCHSIZE
59
60#-----------------------------------------------------------------------------
61
6214µs
# spent 2µs within Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::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 () }
6312µs
# spent 7µs (6+1) within Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins::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_LOWEST }
64sub default_themes { return qw( core pbp cosmetic ) }
65sub applies_to { return 'PPI::Token::Word' }
66
67#-----------------------------------------------------------------------------
68
69sub violates {
70 my ( $self, $elem, undef ) = @_;
71
72 return if exists $ALLOW{$elem};
73 return if not is_perl_builtin($elem);
74 return if not is_function_call($elem);
75
76 my $sibling = $elem->snext_sibling();
77 return if not $sibling;
78 if ( $sibling->isa('PPI::Structure::List') ) {
79 my $elem_after_parens = $sibling->snext_sibling();
80
81 return if _is_named_unary_with_operator_inside_parens_exemption($elem, $sibling);
82 return if _is_named_unary_with_operator_following_parens_exemption($elem, $elem_after_parens);
83 return if _is_precedence_exemption($elem_after_parens);
84 return if _is_equals_exemption($sibling);
85 return if _is_sort_exemption($elem, $sibling);
86
87 # If we get here, it must be a violation
88 return $self->violation( $DESC, $EXPL, $elem );
89 }
90 return; #ok!
91}
92
93#-----------------------------------------------------------------------------
94# EXCEPTION 1: If the function is a named unary and there is an
95# operator with higher precedence right after the parentheses.
96# Example: int( 1.5 ) + 0.5;
97
98sub _is_named_unary_with_operator_following_parens_exemption {
99 my ($elem, $elem_after_parens) = @_;
100
101 if ( _is_named_unary( $elem ) && $elem_after_parens ){
102 # Smaller numbers mean higher precedence
103 my $precedence = precedence_of( $elem_after_parens );
104 return $TRUE if defined $precedence && $precedence < $PRECENDENCE_OF_LIST;
105 }
106
107 return $FALSE;
108}
109
110sub _is_named_unary {
111 my ($elem) = @_;
112
113 return exists $NAMED_UNARY_OPS{$elem->content};
114}
115
116#-----------------------------------------------------------------------------
117# EXCEPTION 2, If there is an operator immediately after the
118# parentheses, and that operator has precedence greater than
119# or equal to a comma.
120# Example: join($delim, @list) . "\n";
121
122sub _is_precedence_exemption {
123 my ($elem_after_parens) = @_;
124
125 if ( $elem_after_parens ){
126 # Smaller numbers mean higher precedence
127 my $precedence = precedence_of( $elem_after_parens );
128 return $TRUE if defined $precedence && $precedence <= $PRECEDENCE_OF_COMMA;
129 }
130
131 return $FALSE;
132}
133
134#-----------------------------------------------------------------------------
135# EXCEPTION 3: If the first operator within the parentheses is '='
136# Example: chomp( my $foo = <STDIN> );
137
138sub _is_equals_exemption {
139 my ($sibling) = @_;
140
141 if ( my $first_op = $sibling->find_first('PPI::Token::Operator') ){
142 return $TRUE if $first_op eq q{=};
143 }
144
145 return $FALSE;
146}
147
148#-----------------------------------------------------------------------------
149# EXCEPTION 4: sort with default comparator but a function for the list data
150# Example: sort(foo(@x))
151
152sub _is_sort_exemption {
153 my ($elem, $sibling) = @_;
154
155 if ( $elem eq 'sort' ) {
156 my $first_arg = $sibling->schild(0);
157 if ( $first_arg && $first_arg->isa('PPI::Statement::Expression') ) {
158 $first_arg = $first_arg->schild(0);
159 }
160 if ( $first_arg && $first_arg->isa('PPI::Token::Word') ) {
161 my $next_arg = $first_arg->snext_sibling;
162 return $TRUE if $next_arg && $next_arg->isa('PPI::Structure::List');
163 }
164 }
165
166 return $FALSE;
167}
168
169#-----------------------------------------------------------------------------
170# EXCEPTION 5: If the function is a named unary and there is an operator
171# inside the parentheses.
172# Example: length($foo || $bar);
173
174sub _is_named_unary_with_operator_inside_parens_exemption {
175 my ($elem, $parens) = @_;
176 return _is_named_unary($elem) && _contains_operators($parens);
177}
178
179sub _contains_operators {
180 my ($parens) = @_;
181 return $TRUE if $parens->find_first('PPI::Token::Operator');
182 return $FALSE;
183}
184
185#-----------------------------------------------------------------------------
186117µs1;
187
188__END__