Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Subroutines/ProhibitAmpersandSigils.pm |
Statements | Executed 20 statements in 438µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 16µs | 16µs | BEGIN@10 | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
1 | 1 | 1 | 8µs | 12µs | BEGIN@12 | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
1 | 1 | 1 | 8µs | 29µs | BEGIN@14 | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
1 | 1 | 1 | 8µs | 174µs | BEGIN@16 | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
1 | 1 | 1 | 7µs | 19µs | BEGIN@11 | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
1 | 1 | 1 | 7µs | 59µs | BEGIN@17 | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
1 | 1 | 1 | 3µs | 3µs | supported_parameters | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::
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::Subroutines::ProhibitAmpersandSigils; | ||||
9 | |||||
10 | 2 | 40µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::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::Subroutines::ProhibitAmpersandSigils::BEGIN@10 |
11 | 2 | 21µs | 2 | 30µs | # spent 19µs (7+12) within Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::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::Subroutines::ProhibitAmpersandSigils::BEGIN@11
# spent 12µs making 1 call to strict::import |
12 | 2 | 24µs | 2 | 15µs | # spent 12µs (8+4) within Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::BEGIN@12 which was called:
# once (8µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 12µs making 1 call to Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 24µs | 2 | 50µs | # spent 29µs (8+21) within Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::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::Subroutines::ProhibitAmpersandSigils::BEGIN@14
# spent 21µs making 1 call to Exporter::import |
15 | |||||
16 | 2 | 24µs | 2 | 342µs | # spent 174µs (8+167) within Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::BEGIN@16 which was called:
# once (8µs+167µs) by Module::Pluggable::Object::_require at line 16 # spent 174µs making 1 call to Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::BEGIN@16
# spent 167µs making 1 call to Exporter::import |
17 | 2 | 284µs | 2 | 111µs | # spent 59µs (7+52) within Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::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::Subroutines::ProhibitAmpersandSigils::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 | 30µs | Readonly::Scalar my $DESC => q{Subroutine called with "&" sigil}; # spent 30µs making 1 call to Readonly::Scalar |
24 | 1 | 2µs | 1 | 44µs | Readonly::Scalar my $EXPL => [ 175 ]; # spent 44µs making 1 call to Readonly::Scalar |
25 | |||||
26 | 1 | 3µs | 2 | 31µs | Readonly::Hash my %EXEMPTIONS => # spent 27µs making 1 call to Readonly::Hash
# spent 4µs making 1 call to Perl::Critic::Utils::hashify |
27 | hashify( qw< defined exists goto sort > ); | ||||
28 | |||||
29 | 1 | 2µs | 2 | 23µs | Readonly::Hash my %IS_COMMA => # spent 21µs making 1 call to Readonly::Hash
# spent 2µs making 1 call to Perl::Critic::Utils::hashify |
30 | hashify( q{,}, q{=>} ); | ||||
31 | |||||
32 | #----------------------------------------------------------------------------- | ||||
33 | |||||
34 | 1 | 6µs | # spent 3µs within Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::supported_parameters which was called:
# once (3µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
35 | 1 | 1µs | # spent 7µs (6+1) within Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
36 | sub default_themes { return qw(core pbp maintenance) } | ||||
37 | sub applies_to { return 'PPI::Token::Symbol' } | ||||
38 | |||||
39 | #----------------------------------------------------------------------------- | ||||
40 | |||||
41 | sub violates { | ||||
42 | my ( $self, $elem, undef ) = @_; | ||||
43 | |||||
44 | my $previous = $elem->sprevious_sibling(); | ||||
45 | if ( $previous ) { | ||||
46 | #Sigil is allowed if taking a reference, e.g. "\&my_sub" | ||||
47 | return if $previous->isa('PPI::Token::Cast') && $previous eq q{\\}; | ||||
48 | } | ||||
49 | |||||
50 | return if ( $elem !~ m{\A [&] }xms ); # ok | ||||
51 | |||||
52 | # look up past parens to get say the "defined" in "defined(&foo)" or | ||||
53 | # "defined((&foo))" etc | ||||
54 | if (not $previous or | ||||
55 | $previous->isa( 'PPI::Token::Operator' ) and | ||||
56 | $IS_COMMA{ $previous->content() } ) { | ||||
57 | my $up = $elem; | ||||
58 | |||||
59 | PARENT: | ||||
60 | while ( | ||||
61 | ($up = $up->parent) | ||||
62 | and ( | ||||
63 | $up->isa('PPI::Statement::Expression') | ||||
64 | or $up->isa('PPI::Structure::List') | ||||
65 | or $up->isa('PPI::Statement') | ||||
66 | ) | ||||
67 | ) { | ||||
68 | if (my $word = $up->sprevious_sibling) { | ||||
69 | # Since backslashes distribute over lists (per perlref), if | ||||
70 | # we have a list and the previous is a backslash, we're cool. | ||||
71 | return if | ||||
72 | $up->isa('PPI::Structure::List') | ||||
73 | && $word->isa('PPI::Token::Cast') | ||||
74 | && $word->content() eq q{\\}; | ||||
75 | |||||
76 | # For a word set $previous to have it checked against %EXEMPTIONS | ||||
77 | # below. For a non-word it's a violation, leave $previous false | ||||
78 | # to get there. | ||||
79 | if ($word->isa('PPI::Token::Word')) { | ||||
80 | $previous = $word; | ||||
81 | } | ||||
82 | last PARENT; | ||||
83 | } | ||||
84 | } | ||||
85 | } | ||||
86 | return if $previous and $EXEMPTIONS{$previous}; | ||||
87 | |||||
88 | return $self->violation( $DESC, $EXPL, $elem ); | ||||
89 | } | ||||
90 | |||||
91 | 1 | 5µs | 1; | ||
92 | |||||
93 | __END__ |