← 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:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Modules/RequireExplicitPackage.pm
StatementsExecuted 18 statements in 465µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs16µsPerl::Critic::Policy::Modules::RequireExplicitPackage::::BEGIN@10Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@10
11110µs435µsPerl::Critic::Policy::Modules::RequireExplicitPackage::::BEGIN@15Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@15
1118µs11µsPerl::Critic::Policy::Modules::RequireExplicitPackage::::BEGIN@12Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@12
1117µs57µsPerl::Critic::Policy::Modules::RequireExplicitPackage::::BEGIN@16Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@16
1117µs27µsPerl::Critic::Policy::Modules::RequireExplicitPackage::::BEGIN@13Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@13
1117µs18µsPerl::Critic::Policy::Modules::RequireExplicitPackage::::BEGIN@11Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@11
1117µs7µsPerl::Critic::Policy::Modules::RequireExplicitPackage::::supported_parametersPerl::Critic::Policy::Modules::RequireExplicitPackage::supported_parameters
1116µs8µsPerl::Critic::Policy::Modules::RequireExplicitPackage::::default_severityPerl::Critic::Policy::Modules::RequireExplicitPackage::default_severity
0000s0sPerl::Critic::Policy::Modules::RequireExplicitPackage::::_is_statement_of_interestPerl::Critic::Policy::Modules::RequireExplicitPackage::_is_statement_of_interest
0000s0sPerl::Critic::Policy::Modules::RequireExplicitPackage::::applies_toPerl::Critic::Policy::Modules::RequireExplicitPackage::applies_to
0000s0sPerl::Critic::Policy::Modules::RequireExplicitPackage::::default_maximum_violations_per_documentPerl::Critic::Policy::Modules::RequireExplicitPackage::default_maximum_violations_per_document
0000s0sPerl::Critic::Policy::Modules::RequireExplicitPackage::::default_themesPerl::Critic::Policy::Modules::RequireExplicitPackage::default_themes
0000s0sPerl::Critic::Policy::Modules::RequireExplicitPackage::::prepare_to_scan_documentPerl::Critic::Policy::Modules::RequireExplicitPackage::prepare_to_scan_document
0000s0sPerl::Critic::Policy::Modules::RequireExplicitPackage::::violatesPerl::Critic::Policy::Modules::RequireExplicitPackage::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::Modules::RequireExplicitPackage;
9
10239µs116µs
# spent 16µs within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@10 which was called: # once (16µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11220µs229µs
# spent 18µs (7+11) within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@11 which was called: # once (7µs+11µs) by Module::Pluggable::Object::_require at line 11
use strict;
# spent 18µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@11 # spent 11µs making 1 call to strict::import
12218µs215µs
# spent 11µs (8+4) within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@12 which was called: # once (8µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
# spent 11µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@12 # spent 4µs making 1 call to warnings::import
13225µs247µs
# spent 27µs (7+20) within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@13 which was called: # once (7µs+20µs) by Module::Pluggable::Object::_require at line 13
use Readonly;
# spent 27µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@13 # spent 20µs making 1 call to Exporter::import
14
15224µs2860µs
# spent 435µs (10+425) within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@15 which was called: # once (10µs+425µs) by Module::Pluggable::Object::_require at line 15
use Perl::Critic::Utils qw{ :booleans :severities :classification };
# spent 435µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@15 # spent 425µs making 1 call to Exporter::import
162322µs2106µs
# spent 57µs (7+49) within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@16 which was called: # once (7µs+49µs) by Module::Pluggable::Object::_require at line 16
use base 'Perl::Critic::Policy';
# spent 57µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@16 # spent 49µs making 1 call to base::import
17
181600nsour $VERSION = '1.121';
19
20#-----------------------------------------------------------------------------
21
2212µs128µsReadonly::Scalar my $EXPL => q{Violates encapsulation};
# spent 28µs making 1 call to Readonly::Scalar
231900ns121µsReadonly::Scalar my $DESC => q{Code not contained in explicit package};
# spent 21µs making 1 call to Readonly::Scalar
24
25#-----------------------------------------------------------------------------
26
27
# spent 7µs within Perl::Critic::Policy::Modules::RequireExplicitPackage::supported_parameters which was called: # once (7µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
28 return (
29 {
3019µs name => 'exempt_scripts',
31 description => q{Don't require programs to contain a package statement.},
32 default_string => '1',
33 behavior => 'boolean',
34 },
35 {
36 name => 'allow_import_of',
37 description => q{Allow the specified modules to be imported outside a package},
38 behavior => 'string list',
39 },
40 );
41}
42
4312µs
# spent 8µs (6+1) within Perl::Critic::Policy::Modules::RequireExplicitPackage::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_HIGH }
44sub default_themes { return qw( core bugs ) }
45sub applies_to { return 'PPI::Document' }
46
47sub default_maximum_violations_per_document { return 1; }
48
49#-----------------------------------------------------------------------------
50
51sub prepare_to_scan_document {
52 my ( $self, $document ) = @_;
53
54 return ! $self->{_exempt_scripts} || $document->is_module();
55}
56
57sub violates {
58 my ( $self, $elem, $doc ) = @_;
59
60 # Find the first 'package' statement
61 my $package_stmnt = $doc->find_first( 'PPI::Statement::Package' );
62 my $package_line = $package_stmnt ? $package_stmnt->location()->[0] : undef;
63
64 # Find all statements that aren't 'package' statements
65 my $stmnts_ref = $doc->find( 'PPI::Statement' );
66 return if !$stmnts_ref;
67 my @non_packages = grep {
68 $self->_is_statement_of_interest( $_ )
69 } @{$stmnts_ref};
70 return if !@non_packages;
71
72 # If the 'package' statement is not defined, or the other
73 # statements appear before the 'package', then it violates.
74
75 my @viols = ();
76 for my $stmnt ( @non_packages ) {
77 my $stmnt_line = $stmnt->location()->[0];
78 if ( (! defined $package_line) || ($stmnt_line < $package_line) ) {
79 push @viols, $self->violation( $DESC, $EXPL, $stmnt );
80 }
81 }
82
83 return @viols;
84}
85
86sub _is_statement_of_interest {
87 my ( $self, $elem ) = @_;
88
89 $elem
90 or return $FALSE;
91
92 $elem->isa( 'PPI::Statement::Package' )
93 and return $FALSE;
94
95 if ( $elem->isa( 'PPI::Statement::Include' ) ) {
96 if ( my $module = $elem->module() ) {
97 $self->{_allow_import_of}{$module}
98 and return $FALSE;
99 }
100 }
101
102 return $TRUE;
103}
104
10513µs1;
106
107__END__