Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Variables/ProhibitReusedNames.pm |
Statements | Executed 20 statements in 440µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 16µs | 16µs | BEGIN@10 | Perl::Critic::Policy::Variables::ProhibitReusedNames::
1 | 1 | 1 | 8µs | 29µs | BEGIN@14 | Perl::Critic::Policy::Variables::ProhibitReusedNames::
1 | 1 | 1 | 7µs | 11µs | BEGIN@12 | Perl::Critic::Policy::Variables::ProhibitReusedNames::
1 | 1 | 1 | 7µs | 433µs | BEGIN@16 | Perl::Critic::Policy::Variables::ProhibitReusedNames::
1 | 1 | 1 | 7µs | 59µs | BEGIN@17 | Perl::Critic::Policy::Variables::ProhibitReusedNames::
1 | 1 | 1 | 7µs | 18µs | BEGIN@11 | Perl::Critic::Policy::Variables::ProhibitReusedNames::
1 | 1 | 1 | 7µs | 146µs | BEGIN@13 | Perl::Critic::Policy::Variables::ProhibitReusedNames::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::Variables::ProhibitReusedNames::
1 | 1 | 1 | 5µs | 5µs | supported_parameters | Perl::Critic::Policy::Variables::ProhibitReusedNames::
0 | 0 | 0 | 0s | 0s | __ANON__[:71] | Perl::Critic::Policy::Variables::ProhibitReusedNames::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::Variables::ProhibitReusedNames::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::Variables::ProhibitReusedNames::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::Variables::ProhibitReusedNames::
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::Variables::ProhibitReusedNames; | ||||
9 | |||||
10 | 2 | 40µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::Variables::ProhibitReusedNames::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::Variables::ProhibitReusedNames::BEGIN@10 |
11 | 2 | 20µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::Variables::ProhibitReusedNames::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::Variables::ProhibitReusedNames::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 20µs | 2 | 15µs | # spent 11µs (7+4) within Perl::Critic::Policy::Variables::ProhibitReusedNames::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::Variables::ProhibitReusedNames::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 22µs | 2 | 285µs | # spent 146µs (7+139) within Perl::Critic::Policy::Variables::ProhibitReusedNames::BEGIN@13 which was called:
# once (7µs+139µs) by Module::Pluggable::Object::_require at line 13 # spent 146µs making 1 call to Perl::Critic::Policy::Variables::ProhibitReusedNames::BEGIN@13
# spent 139µs making 1 call to Exporter::Tiny::import |
14 | 2 | 23µs | 2 | 50µs | # spent 29µs (8+21) within Perl::Critic::Policy::Variables::ProhibitReusedNames::BEGIN@14 which was called:
# once (8µs+21µs) by Module::Pluggable::Object::_require at line 14 # spent 29µs making 1 call to Perl::Critic::Policy::Variables::ProhibitReusedNames::BEGIN@14
# spent 21µs making 1 call to Exporter::import |
15 | |||||
16 | 2 | 24µs | 2 | 858µs | # spent 433µs (7+426) within Perl::Critic::Policy::Variables::ProhibitReusedNames::BEGIN@16 which was called:
# once (7µs+426µs) by Module::Pluggable::Object::_require at line 16 # spent 433µs making 1 call to Perl::Critic::Policy::Variables::ProhibitReusedNames::BEGIN@16
# spent 426µs making 1 call to Exporter::import |
17 | 2 | 276µs | 2 | 110µs | # spent 59µs (7+52) within Perl::Critic::Policy::Variables::ProhibitReusedNames::BEGIN@17 which was called:
# once (7µs+52µs) by Module::Pluggable::Object::_require at line 17 # spent 59µs making 1 call to Perl::Critic::Policy::Variables::ProhibitReusedNames::BEGIN@17
# spent 52µs making 1 call to base::import |
18 | |||||
19 | 1 | 600ns | our $VERSION = '1.121'; | ||
20 | |||||
21 | #----------------------------------------------------------------------------- | ||||
22 | |||||
23 | 1 | 2µs | 1 | 29µs | Readonly::Scalar my $DESC => q{Reused variable name in lexical scope: }; # spent 29µs making 1 call to Readonly::Scalar |
24 | 1 | 1µs | 1 | 21µs | Readonly::Scalar my $EXPL => q{Invent unique variable names}; # spent 21µs making 1 call to Readonly::Scalar |
25 | |||||
26 | #----------------------------------------------------------------------------- | ||||
27 | |||||
28 | # spent 5µs within Perl::Critic::Policy::Variables::ProhibitReusedNames::supported_parameters which was called:
# once (5µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
29 | return ( | ||||
30 | { | ||||
31 | 1 | 7µs | name => 'allow', | ||
32 | description => 'The variables to not consider as duplicates.', | ||||
33 | default_string => '$self $class', ## no critic (RequireInterpolationOfMetachars) | ||||
34 | behavior => 'string list', | ||||
35 | }, | ||||
36 | ); | ||||
37 | } | ||||
38 | |||||
39 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::Variables::ProhibitReusedNames::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
40 | sub default_themes { return qw( core bugs ) } | ||||
41 | sub applies_to { return 'PPI::Statement::Variable' } | ||||
42 | |||||
43 | #----------------------------------------------------------------------------- | ||||
44 | |||||
45 | sub violates { | ||||
46 | my ( $self, $elem, undef ) = @_; | ||||
47 | return if 'local' eq $elem->type; | ||||
48 | |||||
49 | my $allow = $self->{_allow}; | ||||
50 | my @names = grep { not $allow->{$_} } $elem->variables(); | ||||
51 | my $names = [ @names ]; | ||||
52 | # Assert: it is impossible for @$names to be empty in valid Perl syntax | ||||
53 | # But if it IS empty, this code should still work but will be inefficient | ||||
54 | |||||
55 | # walk up the PDOM looking for declared variables in the same | ||||
56 | # scope or outer scopes quit when we hit the root or when we find | ||||
57 | # violations for all vars (the latter is a shortcut) | ||||
58 | my $outer = $elem; | ||||
59 | my @violations; | ||||
60 | while (1) { | ||||
61 | my $up = $outer->sprevious_sibling; | ||||
62 | if (not $up) { | ||||
63 | $up = $outer->parent; | ||||
64 | } | ||||
65 | last if !$up; # top of PDOM, we're done | ||||
66 | $outer = $up; | ||||
67 | |||||
68 | if ($outer->isa('PPI::Statement::Variable') && 'local' ne $outer->type) { | ||||
69 | my %vars = map {$_ => undef} $outer->variables; | ||||
70 | my $hits; | ||||
71 | ($hits, $names) = part { exists $vars{$_} ? 0 : 1 } @{$names}; | ||||
72 | if ($hits) { | ||||
73 | push @violations, map { $self->violation( $DESC . $_, $EXPL, $elem ) } @{$hits}; | ||||
74 | last if not $names; # found violations for ALL variables, we're done | ||||
75 | } | ||||
76 | } | ||||
77 | } | ||||
78 | return @violations; | ||||
79 | } | ||||
80 | |||||
81 | 1 | 3µs | 1; | ||
82 | |||||
83 | __END__ |