← 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/Variables/ProhibitPackageVars.pm
StatementsExecuted 22 statements in 638µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs16µsPerl::Critic::Policy::Variables::ProhibitPackageVars::::BEGIN@10Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@10
11114µs16µsPerl::Critic::Policy::Variables::ProhibitPackageVars::::supported_parametersPerl::Critic::Policy::Variables::ProhibitPackageVars::supported_parameters
1118µs29µsPerl::Critic::Policy::Variables::ProhibitPackageVars::::BEGIN@15Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@15
1118µs433µsPerl::Critic::Policy::Variables::ProhibitPackageVars::::BEGIN@19Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@19
1117µs11µsPerl::Critic::Policy::Variables::ProhibitPackageVars::::BEGIN@12Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@12
1117µs164µsPerl::Critic::Policy::Variables::ProhibitPackageVars::::BEGIN@17Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@17
1117µs28µsPerl::Critic::Policy::Variables::ProhibitPackageVars::::BEGIN@14Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@14
1117µs58µsPerl::Critic::Policy::Variables::ProhibitPackageVars::::BEGIN@22Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@22
1117µs18µsPerl::Critic::Policy::Variables::ProhibitPackageVars::::BEGIN@11Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@11
1116µs7µsPerl::Critic::Policy::Variables::ProhibitPackageVars::::default_severityPerl::Critic::Policy::Variables::ProhibitPackageVars::default_severity
0000s0sPerl::Critic::Policy::Variables::ProhibitPackageVars::::__ANON__[:128]Perl::Critic::Policy::Variables::ProhibitPackageVars::__ANON__[:128]
0000s0sPerl::Critic::Policy::Variables::ProhibitPackageVars::::_all_upcasePerl::Critic::Policy::Variables::ProhibitPackageVars::_all_upcase
0000s0sPerl::Critic::Policy::Variables::ProhibitPackageVars::::_is_our_varPerl::Critic::Policy::Variables::ProhibitPackageVars::_is_our_var
0000s0sPerl::Critic::Policy::Variables::ProhibitPackageVars::::_is_package_varPerl::Critic::Policy::Variables::ProhibitPackageVars::_is_package_var
0000s0sPerl::Critic::Policy::Variables::ProhibitPackageVars::::_is_vars_pragmaPerl::Critic::Policy::Variables::ProhibitPackageVars::_is_vars_pragma
0000s0sPerl::Critic::Policy::Variables::ProhibitPackageVars::::applies_toPerl::Critic::Policy::Variables::ProhibitPackageVars::applies_to
0000s0sPerl::Critic::Policy::Variables::ProhibitPackageVars::::default_themesPerl::Critic::Policy::Variables::ProhibitPackageVars::default_themes
0000s0sPerl::Critic::Policy::Variables::ProhibitPackageVars::::initialize_if_enabledPerl::Critic::Policy::Variables::ProhibitPackageVars::initialize_if_enabled
0000s0sPerl::Critic::Policy::Variables::ProhibitPackageVars::::violatesPerl::Critic::Policy::Variables::ProhibitPackageVars::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::Variables::ProhibitPackageVars;
9
10240µs116µ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
use 5.006001;
11220µs230µ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
use strict;
# spent 18µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@11 # spent 12µs making 1 call to strict::import
12218µs215µ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
use warnings;
# spent 11µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@12 # spent 4µs making 1 call to warnings::import
13
14225µs249µ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
use Readonly;
# spent 28µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@14 # spent 21µs making 1 call to Exporter::import
15223µs251µ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
use Carp qw( carp );
# spent 29µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@15 # spent 21µs making 1 call to Exporter::import
16
17227µs2321µ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
use List::MoreUtils qw(all);
# 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
191200ns
# 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
use Perl::Critic::Utils qw{
20 :booleans :characters :severities :data_conversion
21124µs2858µs};
# spent 433µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@19 # spent 425µs making 1 call to Exporter::import
222440µs2110µ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
use base 'Perl::Critic::Policy';
# spent 58µs making 1 call to Perl::Critic::Policy::Variables::ProhibitPackageVars::BEGIN@22 # spent 51µs making 1 call to base::import
23
241600nsour $VERSION = '1.121';
25
26#-----------------------------------------------------------------------------
27
2812µs130µsReadonly::Scalar my $DESC => q{Package variable declared or used};
# spent 30µs making 1 call to Readonly::Scalar
2912µs144µsReadonly::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
sub supported_parameters {
34 return (
35 {
36112µs22µ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
5012µ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
sub default_severity { return $SEVERITY_MEDIUM }
51sub default_themes { return qw(core pbp maintenance) }
52sub applies_to { return qw(PPI::Token::Symbol
53 PPI::Statement::Variable
54 PPI::Statement::Include) }
55
56#-----------------------------------------------------------------------------
57
58sub 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
70sub 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
86sub _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
99sub _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
109sub _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
127sub _all_upcase { ##no critic(ArgUnpacking)
128 return all { $_ eq uc $_ } @_;
129}
130
13113µs1;
132
133__END__