Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Variables/ProhibitPackageVars.pm |
Statements | Executed 22 statements in 638µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 16µs | 16µs | BEGIN@10 | Perl::Critic::Policy::Variables::ProhibitPackageVars::
1 | 1 | 1 | 14µs | 16µs | supported_parameters | Perl::Critic::Policy::Variables::ProhibitPackageVars::
1 | 1 | 1 | 8µs | 29µs | BEGIN@15 | Perl::Critic::Policy::Variables::ProhibitPackageVars::
1 | 1 | 1 | 8µs | 433µs | BEGIN@19 | Perl::Critic::Policy::Variables::ProhibitPackageVars::
1 | 1 | 1 | 7µs | 11µs | BEGIN@12 | Perl::Critic::Policy::Variables::ProhibitPackageVars::
1 | 1 | 1 | 7µs | 164µs | BEGIN@17 | Perl::Critic::Policy::Variables::ProhibitPackageVars::
1 | 1 | 1 | 7µs | 28µs | BEGIN@14 | Perl::Critic::Policy::Variables::ProhibitPackageVars::
1 | 1 | 1 | 7µs | 58µs | BEGIN@22 | Perl::Critic::Policy::Variables::ProhibitPackageVars::
1 | 1 | 1 | 7µs | 18µs | BEGIN@11 | Perl::Critic::Policy::Variables::ProhibitPackageVars::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::Variables::ProhibitPackageVars::
0 | 0 | 0 | 0s | 0s | __ANON__[:128] | Perl::Critic::Policy::Variables::ProhibitPackageVars::
0 | 0 | 0 | 0s | 0s | _all_upcase | Perl::Critic::Policy::Variables::ProhibitPackageVars::
0 | 0 | 0 | 0s | 0s | _is_our_var | Perl::Critic::Policy::Variables::ProhibitPackageVars::
0 | 0 | 0 | 0s | 0s | _is_package_var | Perl::Critic::Policy::Variables::ProhibitPackageVars::
0 | 0 | 0 | 0s | 0s | _is_vars_pragma | Perl::Critic::Policy::Variables::ProhibitPackageVars::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::Variables::ProhibitPackageVars::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::Variables::ProhibitPackageVars::
0 | 0 | 0 | 0s | 0s | initialize_if_enabled | Perl::Critic::Policy::Variables::ProhibitPackageVars::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::Variables::ProhibitPackageVars::
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::ProhibitPackageVars; | ||||
9 | |||||
10 | 2 | 40µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::Variables::ProhibitPackageVars::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::ProhibitPackageVars::BEGIN@10 |
11 | 2 | 20µs | 2 | 30µs | # spent 18µs (7+12) within Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@11 which was called:
# once (7µs+12µs) by Module::Pluggable::Object::_require at line 11 # spent 18µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@11
# spent 12µs making 1 call to strict::import |
12 | 2 | 18µs | 2 | 15µs | # spent 11µs (7+4) within Perl::Critic::Policy::Variables::ProhibitPackageVars::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::ProhibitPackageVars::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 25µs | 2 | 49µs | # spent 28µs (7+21) within Perl::Critic::Policy::Variables::ProhibitPackageVars::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::Variables::ProhibitPackageVars::BEGIN@14
# spent 21µs making 1 call to Exporter::import |
15 | 2 | 23µs | 2 | 51µs | # spent 29µs (8+21) within Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@15 which was called:
# once (8µs+21µs) by Module::Pluggable::Object::_require at line 15 # spent 29µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@15
# spent 21µs making 1 call to Exporter::import |
16 | |||||
17 | 2 | 27µs | 2 | 321µs | # spent 164µs (7+157) within Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@17 which was called:
# once (7µs+157µs) by Module::Pluggable::Object::_require at line 17 # spent 164µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@17
# spent 157µs making 1 call to Exporter::Tiny::import |
18 | |||||
19 | 1 | 200ns | # spent 433µs (8+425) within Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@19 which was called:
# once (8µs+425µs) by Module::Pluggable::Object::_require at line 21 | ||
20 | :booleans :characters :severities :data_conversion | ||||
21 | 1 | 24µs | 2 | 858µs | }; # spent 433µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@19
# spent 425µs making 1 call to Exporter::import |
22 | 2 | 440µs | 2 | 110µs | # spent 58µs (7+51) within Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@22 which was called:
# once (7µs+51µs) by Module::Pluggable::Object::_require at line 22 # spent 58µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@22
# spent 51µs making 1 call to base::import |
23 | |||||
24 | 1 | 600ns | our $VERSION = '1.121'; | ||
25 | |||||
26 | #----------------------------------------------------------------------------- | ||||
27 | |||||
28 | 1 | 2µs | 1 | 30µs | Readonly::Scalar my $DESC => q{Package variable declared or used}; # spent 30µs making 1 call to Readonly::Scalar |
29 | 1 | 2µs | 1 | 44µs | Readonly::Scalar my $EXPL => [ 73, 75 ]; # spent 44µs making 1 call to Readonly::Scalar |
30 | |||||
31 | #----------------------------------------------------------------------------- | ||||
32 | |||||
33 | # spent 16µs (14+2) within Perl::Critic::Policy::Variables::ProhibitPackageVars::supported_parameters which was called:
# once (14µs+2µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
34 | return ( | ||||
35 | { | ||||
36 | 1 | 12µs | 2 | 2µs | name => 'packages', # spent 2µs making 2 calls to Readonly::Scalar::FETCH, avg 1µs/call |
37 | description => 'The base set of packages to allow variables for.', | ||||
38 | default_string => 'Data::Dumper File::Find FindBin Log::Log4perl', | ||||
39 | behavior => 'string list', | ||||
40 | }, | ||||
41 | { | ||||
42 | name => 'add_packages', | ||||
43 | description => 'The set of packages to allow variables for, in addition to those given in "packages".', | ||||
44 | default_string => $EMPTY, | ||||
45 | behavior => 'string list', | ||||
46 | }, | ||||
47 | ); | ||||
48 | } | ||||
49 | |||||
50 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::Variables::ProhibitPackageVars::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
51 | sub default_themes { return qw(core pbp maintenance) } | ||||
52 | sub applies_to { return qw(PPI::Token::Symbol | ||||
53 | PPI::Statement::Variable | ||||
54 | PPI::Statement::Include) } | ||||
55 | |||||
56 | #----------------------------------------------------------------------------- | ||||
57 | |||||
58 | sub initialize_if_enabled { | ||||
59 | my ($self, $config) = @_; | ||||
60 | |||||
61 | $self->{_all_packages} = { | ||||
62 | hashify keys %{ $self->{_packages} }, keys %{ $self->{_add_packages} } | ||||
63 | }; | ||||
64 | |||||
65 | return $TRUE; | ||||
66 | } | ||||
67 | |||||
68 | #----------------------------------------------------------------------------- | ||||
69 | |||||
70 | sub violates { | ||||
71 | my ( $self, $elem, undef ) = @_; | ||||
72 | |||||
73 | if ( $self->_is_package_var($elem) || | ||||
74 | _is_our_var($elem) || | ||||
75 | _is_vars_pragma($elem) ) | ||||
76 | { | ||||
77 | |||||
78 | return $self->violation( $DESC, $EXPL, $elem ); | ||||
79 | } | ||||
80 | |||||
81 | return; # ok | ||||
82 | } | ||||
83 | |||||
84 | #----------------------------------------------------------------------------- | ||||
85 | |||||
86 | sub _is_package_var { | ||||
87 | my $self = shift; | ||||
88 | my $elem = shift; | ||||
89 | return if !$elem->isa('PPI::Token::Symbol'); | ||||
90 | my ($package, $name) = $elem =~ m{ \A [@\$%] (.*) :: (\w+) \z }xms; | ||||
91 | return if not defined $package; | ||||
92 | return if _all_upcase( $name ); | ||||
93 | return if $self->{_all_packages}->{$package}; | ||||
94 | return 1; | ||||
95 | } | ||||
96 | |||||
97 | #----------------------------------------------------------------------------- | ||||
98 | |||||
99 | sub _is_our_var { | ||||
100 | my $elem = shift; | ||||
101 | return if not $elem->isa('PPI::Statement::Variable'); | ||||
102 | return if $elem->type() ne 'our'; | ||||
103 | return if _all_upcase( $elem->variables() ); | ||||
104 | return 1; | ||||
105 | } | ||||
106 | |||||
107 | #----------------------------------------------------------------------------- | ||||
108 | |||||
109 | sub _is_vars_pragma { | ||||
110 | my $elem = shift; | ||||
111 | return if !$elem->isa('PPI::Statement::Include'); | ||||
112 | return if $elem->pragma() ne 'vars'; | ||||
113 | |||||
114 | # Older Perls don't support the C<our> keyword, so we try to let | ||||
115 | # people use the C<vars> pragma instead, but only if all the | ||||
116 | # variable names are uppercase. Since there are lots of ways to | ||||
117 | # pass arguments to pragmas (e.g. "$foo" or qw($foo) ) we just use | ||||
118 | # a regex to match things that look like variables names. | ||||
119 | |||||
120 | my @varnames = $elem =~ m{ [@\$%&] (\w+) }gxms; | ||||
121 | |||||
122 | return if !@varnames; # no valid variables specified | ||||
123 | return if _all_upcase( @varnames ); | ||||
124 | return 1; | ||||
125 | } | ||||
126 | |||||
127 | sub _all_upcase { ##no critic(ArgUnpacking) | ||||
128 | return all { $_ eq uc $_ } @_; | ||||
129 | } | ||||
130 | |||||
131 | 1 | 3µs | 1; | ||
132 | |||||
133 | __END__ |