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

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/ValuesAndExpressions/RequireInterpolationOfMetachars.pm
StatementsExecuted 20 statements in 695µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1112.07ms18.3msPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::BEGIN@16Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@16
11116µs16µsPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::BEGIN@10Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@10
11116µs18µsPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::supported_parametersPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::supported_parameters
1119µs412µsPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::BEGIN@18Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@18
1118µs69µsPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::BEGIN@19Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@19
1118µs28µsPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::BEGIN@14Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@14
1118µs11µsPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::BEGIN@12Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@12
1117µs18µsPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::BEGIN@11Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@11
1116µs7µsPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::default_severityPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::default_severity
0000s0sPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::_contains_rcs_variablePerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::_contains_rcs_variable
0000s0sPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::_looks_like_email_addressPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::_looks_like_email_address
0000s0sPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::_looks_like_use_varsPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::_looks_like_use_vars
0000s0sPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::_needs_interpolationPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::_needs_interpolation
0000s0sPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::applies_toPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::applies_to
0000s0sPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::default_themesPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::default_themes
0000s0sPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::initialize_if_enabledPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::initialize_if_enabled
0000s0sPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::::violatesPerl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::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::ValuesAndExpressions::RequireInterpolationOfMetachars;
9
10239µs116µs
# spent 16µs within Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@10 which was called: # once (16µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11223µs229µs
# spent 18µs (7+11) within Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::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::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@11 # spent 11µs making 1 call to strict::import
12219µs215µs
# spent 11µs (8+4) within Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@12 which was called: # once (8µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
13
14220µs249µs
# spent 28µs (8+20) within Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@14 which was called: # once (8µs+20µs) by Module::Pluggable::Object::_require at line 14
use Readonly;
15
16291µs118.3ms
# spent 18.3ms (2.07+16.2) within Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@16 which was called: # once (2.07ms+16.2ms) by Module::Pluggable::Object::_require at line 16
use Email::Address;
17
18228µs2815µs
# spent 412µs (9+403) within Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@18 which was called: # once (9µs+403µs) by Module::Pluggable::Object::_require at line 18
use Perl::Critic::Utils qw< :booleans :characters :severities >;
# spent 412µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@18 # spent 403µs making 1 call to Exporter::import
192453µs2130µs
# spent 69µs (8+61) within Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@19 which was called: # once (8µs+61µs) by Module::Pluggable::Object::_require at line 19
use base 'Perl::Critic::Policy';
# spent 69µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@19 # spent 61µs making 1 call to base::import
20
21#-----------------------------------------------------------------------------
22
231600nsour $VERSION = '1.121';
24
25#-----------------------------------------------------------------------------
26
2712µs144µsReadonly::Scalar my $DESC => q<String *may* require interpolation>;
# spent 44µs making 1 call to Readonly::Scalar
2812µs153µsReadonly::Scalar my $EXPL => [ 51 ];
# spent 53µs making 1 call to Readonly::Scalar
29
30#-----------------------------------------------------------------------------
31
32
# spent 18µs (16+3) within Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::supported_parameters which was called: # once (16µs+3µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
33 return (
34 {
35113µs23µs name => 'rcs_keywords',
# spent 3µs making 2 calls to Readonly::Scalar::FETCH, avg 1µs/call
36 description => 'RCS keywords to ignore in potential interpolation.',
37 default_string => $EMPTY,
38 behavior => 'string list',
39 },
40 );
41}
42
4312µs
# spent 7µs (6+1) within Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::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 }
44sub default_themes { return qw(core pbp cosmetic) }
45
46sub applies_to {
47 return qw< PPI::Token::Quote::Single PPI::Token::Quote::Literal >;
48}
49
50#-----------------------------------------------------------------------------
51
52sub initialize_if_enabled {
53 my ($self, $config) = @_;
54
55 my $rcs_keywords = $self->{_rcs_keywords};
56 my @rcs_keywords = keys %{$rcs_keywords};
57
58 if (@rcs_keywords) {
59 my $rcs_regexes = [ map { qr/ \$ $_ [^\n\$]* \$ /xms } @rcs_keywords ];
60 $self->{_rcs_regexes} = $rcs_regexes;
61 }
62
63 return $TRUE;
64}
65
66sub violates {
67 my ( $self, $elem, undef ) = @_;
68
69 # The string() method strips off the quotes
70 my $string = $elem->string();
71 return if not _needs_interpolation($string);
72 return if _looks_like_email_address($string);
73 return if _looks_like_use_vars($elem);
74
75 my $rcs_regexes = $self->{_rcs_regexes};
76 return if $rcs_regexes and _contains_rcs_variable($string, $rcs_regexes);
77
78 return $self->violation( $DESC, $EXPL, $elem );
79}
80
81#-----------------------------------------------------------------------------
82
83sub _needs_interpolation {
84 my ($string) = @_;
85
86 return
87 # Contains a $ or @ not followed by "{}".
88 $string =~ m< [\$\@] (?! [{] [}] ) \S+ >xms
89 # Contains metachars
90 # Note that \1 ... are not documented (that I can find), but are
91 # treated the same way as \0 by S_scan_const in toke.c, at least
92 # for regular double-quotish strings. Not, obviously, where
93 # regexes are involved.
94 || $string =~ m<
95 (?: \A | [^\\] )
96 (?: \\{2} )*
97 \\ [tnrfbae01234567xcNluLUEQ]
98 >xms;
99}
100
101#-----------------------------------------------------------------------------
102
103sub _looks_like_email_address {
104 my ($string) = @_;
105
106 return if index ($string, q<@>) < 0;
107 return if $string =~ m< \W \@ >xms;
108 return if $string =~ m< \A \@ \w+ \b >xms;
109
110 return $string =~ $Email::Address::addr_spec;
111}
112
113#-----------------------------------------------------------------------------
114
115sub _contains_rcs_variable {
116 my ($string, $rcs_regexes) = @_;
117
118 foreach my $regex ( @{$rcs_regexes} ) {
119 return $TRUE if $string =~ m/$regex/xms;
120 }
121
122 return;
123}
124
125#-----------------------------------------------------------------------------
126
127sub _looks_like_use_vars {
128 my ($elem) = @_;
129
130 my $statement = $elem;
131 while ( not $statement->isa('PPI::Statement::Include') ) {
132 $statement = $statement->parent() or return;
133 }
134
135 return if $statement->type() ne q<use>;
136 return $statement->module() eq q<vars>;
137}
138
13914µs1;
140
141__END__