← 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/Subroutines/ProtectPrivateSubs.pm
StatementsExecuted 28 statements in 683┬Ás
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11126┬Ás46┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::_parse_private_name_regexPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::_parse_private_name_regex
11122┬Ás25┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::supported_parametersPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::supported_parameters
11117┬Ás17┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::BEGIN@10Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@10
11115┬Ás87┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::BEGIN@15Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@15
11113┬Ás16┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::BEGIN@13Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@13
1118┬Ás29┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::BEGIN@16Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@16
1118┬Ás18┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::BEGIN@12Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@12
1118┬Ás187┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::BEGIN@18Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@18
1118┬Ás60┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::BEGIN@21Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@21
1116┬Ás6┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::CORE:regcompPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::CORE:regcomp (opcode)
1116┬Ás7┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::default_severityPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::default_severity
1111┬Ás1┬ÁsPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::CORE:qrPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::CORE:qr (opcode)
0000s0sPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::_is_other_pkg_private_functionPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::_is_other_pkg_private_function
0000s0sPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::_is_other_pkg_private_methodPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::_is_other_pkg_private_method
0000s0sPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::applies_toPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::applies_to
0000s0sPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::default_themesPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::default_themes
0000s0sPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::::violatesPerl::Critic::Policy::Subroutines::ProtectPrivateSubs::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::Subroutines::ProtectPrivateSubs;
9
10240┬Ás117┬Ás
# spent 17┬Ás within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@10 which was called: # once (17┬Ás+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11
12220┬Ás230┬Ás
# spent 18┬Ás (8+11) within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@12 which was called: # once (8┬Ás+11┬Ás) by Module::Pluggable::Object::_require at line 12
use strict;
# spent 18┬Ás making 1 call to Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@12 # spent 11┬Ás making 1 call to strict::import
13224┬Ás220┬Ás
# spent 16┬Ás (13+4) within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@13 which was called: # once (13┬Ás+4┬Ás) by Module::Pluggable::Object::_require at line 13
use warnings;
# spent 16┬Ás making 1 call to Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@13 # spent 4┬Ás making 1 call to warnings::import
14
15233┬Ás2159┬Ás
# spent 87┬Ás (15+72) within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@15 which was called: # once (15┬Ás+72┬Ás) by Module::Pluggable::Object::_require at line 15
use English qw< $EVAL_ERROR -no_match_vars >;
# spent 87┬Ás making 1 call to Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@15 # spent 72┬Ás making 1 call to English::import
16234┬Ás249┬Ás
# spent 29┬Ás (8+20) within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@16 which was called: # once (8┬Ás+20┬Ás) by Module::Pluggable::Object::_require at line 16
use Readonly;
# spent 29┬Ás making 1 call to Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@16 # spent 20┬Ás making 1 call to Exporter::import
17
181200ns
# spent 187┬Ás (8+180) within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@18 which was called: # once (8┬Ás+180┬Ás) by Module::Pluggable::Object::_require at line 20
use Perl::Critic::Utils qw<
19 :severities $EMPTY is_function_call is_method_call
20123┬Ás2367┬Ás>;
# spent 187┬Ás making 1 call to Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@18 # spent 180┬Ás making 1 call to Exporter::import
212453┬Ás2113┬Ás
# spent 60┬Ás (8+53) within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@21 which was called: # once (8┬Ás+53┬Ás) by Module::Pluggable::Object::_require at line 21
use base 'Perl::Critic::Policy';
# spent 60┬Ás making 1 call to Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::BEGIN@21 # spent 53┬Ás making 1 call to base::import
22
231600nsour $VERSION = '1.121';
24
25#-----------------------------------------------------------------------------
26
2712┬Ás128┬ÁsReadonly::Scalar my $DESC => q<Private subroutine/method used>;
# spent 28┬Ás making 1 call to Readonly::Scalar
2811┬Ás121┬ÁsReadonly::Scalar my $EXPL => q<Use published APIs>;
# spent 21┬Ás making 1 call to Readonly::Scalar
29
30#-----------------------------------------------------------------------------
31
32
# spent 25┬Ás (22+3) within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::supported_parameters which was called: # once (22┬Ás+3┬Ás) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
33 return (
34 {
35120┬Ás23┬Ás name => 'private_name_regex',
# spent 3┬Ás making 2 calls to Readonly::Scalar::FETCH, avg 1┬Ás/call
36 description => 'Pattern that determines what a private subroutine is.',
37 default_string => '\b_\w+\b', ## no critic (RequireInterpolationOfMetachars)
38 behavior => 'string',
39 parser => \& _parse_private_name_regex,
40 },
41 {
42 name => 'allow',
43 description =>
44 q<Subroutines matching the private name regex to allow under this policy.>,
45 default_string => $EMPTY,
46 behavior => 'string list',
47 list_always_present_values => [ qw<
48 POSIX::_PC_CHOWN_RESTRICTED
49 POSIX::_PC_LINK_MAX
50 POSIX::_PC_MAX_CANON
51 POSIX::_PC_MAX_INPUT
52 POSIX::_PC_NAME_MAX
53 POSIX::_PC_NO_TRUNC
54 POSIX::_PC_PATH_MAX
55 POSIX::_PC_PIPE_BUF
56 POSIX::_PC_VDISABLE
57 POSIX::_POSIX_ARG_MAX
58 POSIX::_POSIX_CHILD_MAX
59 POSIX::_POSIX_CHOWN_RESTRICTED
60 POSIX::_POSIX_JOB_CONTROL
61 POSIX::_POSIX_LINK_MAX
62 POSIX::_POSIX_MAX_CANON
63 POSIX::_POSIX_MAX_INPUT
64 POSIX::_POSIX_NAME_MAX
65 POSIX::_POSIX_NGROUPS_MAX
66 POSIX::_POSIX_NO_TRUNC
67 POSIX::_POSIX_OPEN_MAX
68 POSIX::_POSIX_PATH_MAX
69 POSIX::_POSIX_PIPE_BUF
70 POSIX::_POSIX_SAVED_IDS
71 POSIX::_POSIX_SSIZE_MAX
72 POSIX::_POSIX_STREAM_MAX
73 POSIX::_POSIX_TZNAME_MAX
74 POSIX::_POSIX_VDISABLE
75 POSIX::_POSIX_VERSION
76 POSIX::_SC_ARG_MAX
77 POSIX::_SC_CHILD_MAX
78 POSIX::_SC_CLK_TCK
79 POSIX::_SC_JOB_CONTROL
80 POSIX::_SC_NGROUPS_MAX
81 POSIX::_SC_OPEN_MAX
82 POSIX::_SC_PAGESIZE
83 POSIX::_SC_SAVED_IDS
84 POSIX::_SC_STREAM_MAX
85 POSIX::_SC_TZNAME_MAX
86 POSIX::_SC_VERSION
87 POSIX::_exit
88 > ],
89 },
90 );
91}
92
9311┬Ás
# spent 7┬Ás (6+1) within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::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 }
94sub default_themes { return qw( core maintenance certrule ) }
95sub applies_to { return 'PPI::Token::Word' }
96
97#-----------------------------------------------------------------------------
98
99
# spent 46┬Ás (26+20) within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::_parse_private_name_regex which was called: # once (26┬Ás+20┬Ás) by Perl::Critic::PolicyParameter::parse_and_validate_config_value at line 231 of Perl/Critic/PolicyParameter.pm
sub _parse_private_name_regex {
1001700ns my ($self, $parameter, $config_string) = @_;
101
10212┬Ás12┬Ás defined $config_string
# spent 2┬Ás making 1 call to Perl::Critic::PolicyParameter::get_default_string
103 or $config_string = $parameter->get_default_string();
104
1051400ns my $regex;
106318┬Ás27┬Ás eval { $regex = qr/$config_string/; 1 } ## no critic (RegularExpressions)
107 or $self->throw_parameter_value_exception(
108 'private_name_regex',
109 $config_string,
110 undef,
111 "is not a valid regular expression: $EVAL_ERROR",
112 );
113
11414┬Ás111┬Ás $self->__set_parameter_value($parameter, $regex);
# spent 11┬Ás making 1 call to Perl::Critic::Policy::__set_parameter_value
115
11613┬Ás return;
117}
118
119#-----------------------------------------------------------------------------
120
121sub violates {
122 my ( $self, $elem, undef ) = @_;
123
124 if ( my $prior = $elem->sprevious_sibling() ) {
125 my $prior_name = $prior->content();
126 return if $prior_name eq 'package';
127 return if $prior_name eq 'require';
128 return if $prior_name eq 'use';
129 }
130
131 if (
132 $self->_is_other_pkg_private_function($elem)
133 or $self->_is_other_pkg_private_method($elem)
134 ) {
135 return $self->violation( $DESC, $EXPL, $elem );
136 }
137
138 return; # ok!
139}
140
141sub _is_other_pkg_private_function {
142 my ( $self, $elem ) = @_;
143
144 return if ! is_function_call($elem) && ! is_method_call($elem);
145
146 my $private_name_regex = $self->{_private_name_regex};
147 my $content = $elem->content();
148 return
149 $content =~ m< \w+::$private_name_regex \z >xms
150 && $content !~ m< \A SUPER::$private_name_regex \z >xms
151 && ! $self->{_allow}{$content};
152}
153
154sub _is_other_pkg_private_method {
155 my ( $self, $elem ) = @_;
156
157 my $private_name_regex = $self->{_private_name_regex};
158 my $content = $elem->content();
159
160 # look for structures like "Some::Package->_foo()"
161 return if $content !~ m< \A $private_name_regex \z >xms;
162 my $operator = $elem->sprevious_sibling() or return;
163 return if $operator->content() ne q[->];
164
165 my $package = $operator->sprevious_sibling() or return;
166 return if not $package->isa('PPI::Token::Word');
167
168 # sometimes the previous sib is a keyword, as in:
169 # shift->_private_method(); This is typically used as
170 # shorthand for "my $self=shift; $self->_private_method()"
171 return if $package eq 'shift' or $package eq '__PACKAGE__';
172
173 # Maybe the user wanted to exempt this explicitly.
174 return if $self->{_allow}{"${package}::$content"};
175
176 return 1;
177}
178
17913┬Ás1;
180
181__END__
 
# spent 1┬Ás within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::CORE:qr which was called: # once (1┬Ás+0s) by Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::_parse_private_name_regex at line 106
sub Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::CORE:qr; # opcode
# spent 6┬Ás within Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::CORE:regcomp which was called: # once (6┬Ás+0s) by Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::_parse_private_name_regex at line 106
sub Perl::Critic::Policy::Subroutines::ProtectPrivateSubs::CORE:regcomp; # opcode