Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Modules/RequireNoMatchVarsWithUseEnglish.pm |
Statements | Executed 18 statements in 571µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 17µs | 17µs | BEGIN@10 | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
1 | 1 | 1 | 8µs | 63µs | BEGIN@17 | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
1 | 1 | 1 | 7µs | 29µs | BEGIN@14 | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
1 | 1 | 1 | 7µs | 339µs | BEGIN@16 | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
1 | 1 | 1 | 7µs | 11µs | BEGIN@12 | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
1 | 1 | 1 | 7µs | 19µs | BEGIN@11 | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
1 | 1 | 1 | 2µs | 2µs | supported_parameters | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
0 | 0 | 0 | 0s | 0s | _descend_into_parenthesized_list_if_present | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
0 | 0 | 0 | 0s | 0s | _skip_version_number | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::
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::Modules::RequireNoMatchVarsWithUseEnglish; | ||||
9 | |||||
10 | 2 | 47µs | 1 | 17µs | # spent 17µs within Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@10 which was called:
# once (17µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 17µs making 1 call to Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@10 |
11 | 2 | 21µs | 2 | 30µs | # spent 19µs (7+12) within Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@11 which was called:
# once (7µs+12µs) by Module::Pluggable::Object::_require at line 11 # spent 19µs making 1 call to Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@11
# spent 12µs making 1 call to strict::import |
12 | 2 | 22µs | 2 | 15µs | # spent 11µs (7+4) within Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@12 which was called:
# once (7µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 11µs making 1 call to Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 24µs | 2 | 51µs | # spent 29µs (7+22) within Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@14 which was called:
# once (7µs+22µs) by Module::Pluggable::Object::_require at line 14 # spent 29µs making 1 call to Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@14
# spent 22µs making 1 call to Exporter::import |
15 | |||||
16 | 2 | 24µs | 2 | 671µs | # spent 339µs (7+332) within Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@16 which was called:
# once (7µs+332µs) by Module::Pluggable::Object::_require at line 16 # spent 339µs making 1 call to Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@16
# spent 332µs making 1 call to Exporter::import |
17 | 2 | 420µs | 2 | 119µs | # spent 63µs (8+55) within Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@17 which was called:
# once (8µs+55µs) by Module::Pluggable::Object::_require at line 17 # spent 63µs making 1 call to Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::BEGIN@17
# spent 55µs making 1 call to base::import |
18 | |||||
19 | 1 | 500ns | our $VERSION = '1.121'; | ||
20 | |||||
21 | #----------------------------------------------------------------------------- | ||||
22 | |||||
23 | 1 | 2µs | 1 | 29µs | Readonly::Scalar my $EXPL => # spent 29µs making 1 call to Readonly::Scalar |
24 | q{"use English" without the '-no_match_vars' argument degrades performance.'}; | ||||
25 | 1 | 900ns | 1 | 21µs | Readonly::Scalar my $DESC => q{"use English" without '-no_match_vars' argument}; # spent 21µs making 1 call to Readonly::Scalar |
26 | |||||
27 | #----------------------------------------------------------------------------- | ||||
28 | |||||
29 | 1 | 4µs | # spent 2µs within Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::supported_parameters which was called:
# once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
30 | 1 | 1µs | # spent 7µs (6+1) within Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
31 | sub default_themes { return qw( core performance ) } | ||||
32 | sub applies_to { return 'PPI::Statement::Include' } | ||||
33 | |||||
34 | #----------------------------------------------------------------------------- | ||||
35 | |||||
36 | sub violates { | ||||
37 | my ( $self, $elem, $doc ) = @_; | ||||
38 | |||||
39 | # "require"ing English is kind of useless. | ||||
40 | return if $elem->type() ne 'use'; | ||||
41 | return if $elem->module() ne 'English'; | ||||
42 | |||||
43 | my @elements = $elem->schildren(); | ||||
44 | shift @elements; # dump "use" | ||||
45 | shift @elements; # dump "English" | ||||
46 | |||||
47 | if (not @elements) { | ||||
48 | return $self->violation($DESC, $EXPL, $elem); | ||||
49 | } | ||||
50 | |||||
51 | _skip_version_number( \@elements ); | ||||
52 | |||||
53 | @elements = _descend_into_parenthesized_list_if_present(@elements); | ||||
54 | |||||
55 | if (not @elements) { | ||||
56 | return $self->violation($DESC, $EXPL, $elem); | ||||
57 | } | ||||
58 | |||||
59 | my $current_element = $elements[0]; | ||||
60 | |||||
61 | while ( $current_element ) { | ||||
62 | if ( $current_element->isa('PPI::Token::Quote') ) { | ||||
63 | return if $current_element->string() eq '-no_match_vars'; | ||||
64 | } | ||||
65 | elsif ( $current_element->isa('PPI::Token::QuoteLike::Words') ) { | ||||
66 | return if $current_element->content() =~ m/-no_match_vars \b/xms; | ||||
67 | } | ||||
68 | elsif ( | ||||
69 | not $current_element->isa('PPI::Token::Operator') | ||||
70 | or $current_element->content() ne $COMMA | ||||
71 | and $current_element->content() ne $FATCOMMA | ||||
72 | ) { | ||||
73 | return $self->violation($DESC, $EXPL, $elem); | ||||
74 | } | ||||
75 | |||||
76 | shift @elements; | ||||
77 | $current_element = $elements[0]; | ||||
78 | } | ||||
79 | |||||
80 | return $self->violation($DESC, $EXPL, $elem); | ||||
81 | } | ||||
82 | |||||
83 | |||||
84 | sub _skip_version_number { | ||||
85 | my ($elements_ref) = @_; | ||||
86 | |||||
87 | my $current_element = $elements_ref->[0]; | ||||
88 | |||||
89 | if ( $current_element->isa('PPI::Token::Number') ) { | ||||
90 | shift @{$elements_ref}; | ||||
91 | } | ||||
92 | elsif ( | ||||
93 | @{$elements_ref} >= 2 | ||||
94 | and $current_element->isa('PPI::Token::Word') | ||||
95 | and $current_element->content() =~ m/\A v \d+ \z/xms | ||||
96 | and $elements_ref->[1]->isa('PPI::Token::Number') | ||||
97 | ) { | ||||
98 | # The above messy conditional necessary due to PPI not handling | ||||
99 | # v-strings. | ||||
100 | shift @{$elements_ref}; | ||||
101 | shift @{$elements_ref}; | ||||
102 | } | ||||
103 | |||||
104 | return; | ||||
105 | } | ||||
106 | |||||
107 | sub _descend_into_parenthesized_list_if_present { | ||||
108 | my @elements = @_; | ||||
109 | |||||
110 | return if not @elements; | ||||
111 | |||||
112 | my $current_element = $elements[0]; | ||||
113 | |||||
114 | if ( $current_element->isa('PPI::Structure::List') ) { | ||||
115 | my @grand_children = $current_element->schildren(); | ||||
116 | if (not @grand_children) { | ||||
117 | return; | ||||
118 | } | ||||
119 | |||||
120 | my $grand_child = $grand_children[0]; | ||||
121 | |||||
122 | if ( $grand_child->isa('PPI::Statement::Expression') ) { | ||||
123 | my @great_grand_children = $grand_child->schildren(); | ||||
124 | |||||
125 | if (not @great_grand_children) { | ||||
126 | return; | ||||
127 | } | ||||
128 | |||||
129 | return @great_grand_children; | ||||
130 | } | ||||
131 | else { | ||||
132 | return @grand_children; | ||||
133 | } | ||||
134 | } | ||||
135 | |||||
136 | return @elements; | ||||
137 | } | ||||
138 | |||||
139 | 1 | 4µs | 1; | ||
140 | |||||
141 | __END__ |