Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/BuiltinFunctions/ProhibitStringyEval.pm |
Statements | Executed 27166 statements in 52.9ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
13481 | 1 | 1 | 43.5ms | 293ms | violates | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
144 | 1 | 1 | 276µs | 276µs | applies_to | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
1 | 1 | 1 | 16µs | 16µs | BEGIN@10 | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
1 | 1 | 1 | 10µs | 10µs | BEGIN@16 | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
1 | 1 | 1 | 7µs | 61µs | BEGIN@19 | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
1 | 1 | 1 | 7µs | 12µs | BEGIN@12 | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
1 | 1 | 1 | 7µs | 28µs | BEGIN@14 | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
1 | 1 | 1 | 7µs | 478µs | BEGIN@18 | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
1 | 1 | 1 | 7µs | 18µs | BEGIN@11 | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
1 | 1 | 1 | 6µs | 8µs | default_severity | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
1 | 1 | 1 | 5µs | 5µs | supported_parameters | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
0 | 0 | 0 | 0s | 0s | _string_eval_is_an_include | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::
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::BuiltinFunctions::ProhibitStringyEval; | ||||
9 | |||||
10 | 2 | 39µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::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::BuiltinFunctions::ProhibitStringyEval::BEGIN@10 |
11 | 2 | 20µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::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::BuiltinFunctions::ProhibitStringyEval::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 22µs | 2 | 16µs | # spent 12µs (7+5) within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::BEGIN@12 which was called:
# once (7µs+5µs) by Module::Pluggable::Object::_require at line 12 # spent 12µs making 1 call to Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 20µs | 2 | 49µs | # spent 28µs (7+21) within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::BEGIN@14 which was called:
# once (7µs+21µs) by Module::Pluggable::Object::_require at line 14 # spent 28µs making 1 call to Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::BEGIN@14
# spent 21µs making 1 call to Exporter::import |
15 | |||||
16 | 2 | 28µs | 1 | 10µs | # spent 10µs within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::BEGIN@16 which was called:
# once (10µs+0s) by Module::Pluggable::Object::_require at line 16 # spent 10µs making 1 call to Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::BEGIN@16 |
17 | |||||
18 | 2 | 25µs | 2 | 950µs | # spent 478µs (7+471) within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::BEGIN@18 which was called:
# once (7µs+471µs) by Module::Pluggable::Object::_require at line 18 # spent 478µs making 1 call to Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::BEGIN@18
# spent 471µs making 1 call to Exporter::import |
19 | 2 | 328µs | 2 | 114µs | # spent 61µs (7+54) within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::BEGIN@19 which was called:
# once (7µs+54µs) by Module::Pluggable::Object::_require at line 19 # spent 61µs making 1 call to Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::BEGIN@19
# spent 54µs making 1 call to base::import |
20 | |||||
21 | 1 | 600ns | our $VERSION = '1.121'; | ||
22 | |||||
23 | #----------------------------------------------------------------------------- | ||||
24 | |||||
25 | 1 | 2µs | 1 | 2.85ms | Readonly::Scalar my $DESC => q{Expression form of "eval"}; # spent 2.85ms making 1 call to Readonly::Scalar |
26 | 1 | 2µs | 1 | 47µs | Readonly::Scalar my $EXPL => [ 161 ]; # spent 47µs making 1 call to Readonly::Scalar |
27 | |||||
28 | #----------------------------------------------------------------------------- | ||||
29 | |||||
30 | # spent 5µs within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::supported_parameters which was called:
# once (5µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
31 | return ( | ||||
32 | { | ||||
33 | 1 | 8µs | name => 'allow_includes', | ||
34 | description => q<Allow eval of "use" and "require" strings.>, | ||||
35 | default_string => '0', | ||||
36 | behavior => 'boolean', | ||||
37 | }, | ||||
38 | ); | ||||
39 | } | ||||
40 | 1 | 2µs | # spent 8µs (6+1) within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
41 | sub default_themes { return qw( core pbp bugs certrule ) } | ||||
42 | 144 | 374µs | # spent 276µs within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::applies_to which was called 144 times, avg 2µs/call:
# 144 times (276µs+0s) by Perl::Critic::_critique at line 165 of Perl/Critic.pm, avg 2µs/call | ||
43 | |||||
44 | #----------------------------------------------------------------------------- | ||||
45 | |||||
46 | # spent 293ms (43.5+250) within Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval::violates which was called 13481 times, avg 22µs/call:
# 13481 times (43.5ms+250ms) by Perl::Critic::_critique at line 183 of Perl/Critic.pm, avg 22µs/call | ||||
47 | 13481 | 3.00ms | my ( $self, $elem, undef ) = @_; | ||
48 | |||||
49 | 13481 | 48.8ms | 13481 | 245ms | return if $elem ne 'eval'; # spent 245ms making 13481 calls to PPI::Element::__ne, avg 18µs/call |
50 | 10 | 23µs | 10 | 4.15ms | return if not is_function_call($elem); # spent 4.15ms making 10 calls to Perl::Critic::Utils::is_function_call, avg 415µs/call |
51 | |||||
52 | 10 | 21µs | 10 | 339µs | my $argument = first_arg($elem); # spent 339µs making 10 calls to Perl::Critic::Utils::first_arg, avg 34µs/call |
53 | 10 | 30µs | 10 | 5µs | return if not $argument; # spent 5µs making 10 calls to PPI::Util::TRUE, avg 510ns/call |
54 | 10 | 53µs | 10 | 8µs | return if $argument->isa('PPI::Structure::Block'); # spent 8µs making 10 calls to UNIVERSAL::isa, avg 800ns/call |
55 | return if | ||||
56 | $self->{_allow_includes} and _string_eval_is_an_include($argument); | ||||
57 | |||||
58 | return $self->violation( $DESC, $EXPL, $elem ); | ||||
59 | } | ||||
60 | |||||
61 | sub _string_eval_is_an_include { | ||||
62 | my ($eval_argument) = @_; | ||||
63 | |||||
64 | return if not $eval_argument->isa('PPI::Token::Quote'); | ||||
65 | |||||
66 | my $string = $eval_argument->string(); | ||||
67 | my $document; | ||||
68 | |||||
69 | eval { $document = PPI::Document->new(\$string); 1 } | ||||
70 | or return; | ||||
71 | |||||
72 | my @statements = $document->schildren; | ||||
73 | |||||
74 | return if @statements > 2; | ||||
75 | my $include = $statements[0]; | ||||
76 | return if not defined $include; # RT 60179 | ||||
77 | return if not $include->isa('PPI::Statement::Include'); | ||||
78 | return if $include->type() eq 'no'; | ||||
79 | |||||
80 | if ( | ||||
81 | $eval_argument->isa('PPI::Token::Quote::Single') | ||||
82 | or $eval_argument->isa('PPI::Token::Quote::Literal') | ||||
83 | ) { | ||||
84 | # Don't allow funky inclusion of arbitrary code (note we do allow | ||||
85 | # interpolated values in interpolating strings because they can't | ||||
86 | # entirely screw with the syntax). | ||||
87 | return if $include->find('PPI::Token::Symbol'); | ||||
88 | } | ||||
89 | |||||
90 | return $TRUE if @statements == 1; | ||||
91 | |||||
92 | my $follow_on = $statements[1]; | ||||
93 | return if not $follow_on->isa('PPI::Statement'); | ||||
94 | |||||
95 | my @follow_on_components = $follow_on->schildren(); | ||||
96 | |||||
97 | return if @follow_on_components > 2; | ||||
98 | return if not $follow_on_components[0]->isa('PPI::Token::Number'); | ||||
99 | return $TRUE if @follow_on_components == 1; | ||||
100 | |||||
101 | return $follow_on_components[1]->content() eq $SCOLON; | ||||
102 | } | ||||
103 | |||||
104 | |||||
105 | 1 | 4µs | 1; | ||
106 | |||||
107 | __END__ |