← 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/TestingAndDebugging/RequireUseWarnings.pm
StatementsExecuted 23 statements in 636µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs16µsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::BEGIN@10Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@10
11113µs15µsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::supported_parametersPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::supported_parameters
11112µs43µsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::BEGIN@15Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@15
1118µs12µsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::BEGIN@12Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@12
1118µs28µsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::BEGIN@13Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@13
1117µs18µsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::BEGIN@11Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@11
1117µs58µsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::BEGIN@19Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@19
1117µs176µsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::BEGIN@18Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@18
1116µs8µsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::default_severityPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::default_severity
1113µs3µsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::BEGIN@16Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@16
0000s0sPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::__ANON__[:107]Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::__ANON__[:107]
0000s0sPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::_find_isnt_include_or_packagePerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::_find_isnt_include_or_package
0000s0sPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::_generate_is_use_warningsPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::_generate_is_use_warnings
0000s0sPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::_statement_isnt_include_or_packagePerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::_statement_isnt_include_or_package
0000s0sPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::applies_toPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::applies_to
0000s0sPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::default_maximum_violations_per_documentPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::default_maximum_violations_per_document
0000s0sPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::default_themesPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::default_themes
0000s0sPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::::violatesPerl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::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::TestingAndDebugging::RequireUseWarnings;
9
10239µs116µs
# spent 16µs within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@10 which was called: # once (16µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11224µs229µs
# spent 18µs (7+11) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::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::TestingAndDebugging::RequireUseWarnings::BEGIN@11 # spent 11µs making 1 call to strict::import
12218µs216µs
# spent 12µs (8+4) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@12 which was called: # once (8µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
# spent 12µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@12 # spent 4µs making 1 call to warnings::import
13222µs248µs
# spent 28µs (8+20) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@13 which was called: # once (8µs+20µs) by Module::Pluggable::Object::_require at line 13
use Readonly;
# spent 28µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@13 # spent 20µs making 1 call to Exporter::import
14
15222µs255µs
# spent 43µs (12+30) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@15 which was called: # once (12µs+30µs) by Module::Pluggable::Object::_require at line 15
use List::Util qw(first);
# spent 43µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@15 # spent 12µs making 1 call to List::Util::import
16219µs13µs
# spent 3µs within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@16 which was called: # once (3µs+0s) by Module::Pluggable::Object::_require at line 16
use version ();
17
18227µs2345µs
# spent 176µs (7+169) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@18 which was called: # once (7µs+169µs) by Module::Pluggable::Object::_require at line 18
use Perl::Critic::Utils qw{ :severities $EMPTY };
# spent 176µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@18 # spent 169µs making 1 call to Exporter::import
192435µs2110µs
# spent 58µs (7+51) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@19 which was called: # once (7µs+51µs) by Module::Pluggable::Object::_require at line 19
use base 'Perl::Critic::Policy';
# spent 58µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::BEGIN@19 # spent 51µs making 1 call to base::import
20
211600nsour $VERSION = '1.121';
22
23#-----------------------------------------------------------------------------
24
2512µs130µsReadonly::Scalar my $DESC => q{Code before warnings are enabled};
# spent 30µs making 1 call to Readonly::Scalar
2612µs144µsReadonly::Scalar my $EXPL => [431];
# spent 44µs making 1 call to Readonly::Scalar
27
28110µs228µsReadonly::Scalar my $MINIMUM_VERSION => version->new(5.006);
# spent 22µs making 1 call to Readonly::Scalar # spent 6µs making 1 call to version::new
29
30#-----------------------------------------------------------------------------
31
32
# spent 15µs (13+2) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::supported_parameters which was called: # once (13µs+2µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
33 return (
34 {
35111µs22µs name => 'equivalent_modules',
# spent 2µs making 2 calls to Readonly::Scalar::FETCH, avg 1µs/call
36 description =>
37 q<The additional modules to treat as equivalent to "warnings".>,
38 default_string => $EMPTY,
39 behavior => 'string list',
40 list_always_present_values =>
41 [ qw< warnings Moose Moose::Role Moose::Util::TypeConstraints > ],
42 },
43 );
44}
45
4612µs
# spent 8µs (6+1) within Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings::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 }
47sub default_themes { return qw( core pbp bugs certrule ) }
48sub applies_to { return 'PPI::Document' }
49
50sub default_maximum_violations_per_document { return 1; }
51
52#-----------------------------------------------------------------------------
53
54sub violates {
55 my ( $self, undef, $document ) = @_;
56
57 my $version = $document->highest_explicit_perl_version();
58 return if $version and $version < $MINIMUM_VERSION;
59
60 # Find the first 'use warnings' statement
61 my $warn_stmnt = $document->find_first( $self->_generate_is_use_warnings() );
62 my $warn_line = $warn_stmnt ? $warn_stmnt->location()->[0] : undef;
63
64 # Find all statements that aren't 'use', 'require', or 'package'
65 my $stmnts_ref = $self->_find_isnt_include_or_package($document);
66 return if !$stmnts_ref;
67
68 # If the 'use warnings' statement is not defined, or the other
69 # statement appears before the 'use warnings', then it violates.
70
71 my @viols = ();
72 for my $stmnt ( @{ $stmnts_ref } ) {
73 last if $stmnt->isa('PPI::Statement::End');
74 last if $stmnt->isa('PPI::Statement::Data');
75
76 my $stmnt_line = $stmnt->location()->[0];
77 if ( (! defined $warn_line) || ($stmnt_line < $warn_line) ) {
78 push @viols, $self->violation( $DESC, $EXPL, $stmnt );
79 }
80 }
81 return @viols;
82}
83
84#-----------------------------------------------------------------------------
85
86sub _generate_is_use_warnings {
87 my ($self) = @_;
88
89 return sub {
90 my (undef, $elem) = @_;
91
92 return 0 if !$elem->isa('PPI::Statement::Include');
93 return 0 if $elem->type() ne 'use';
94
95 # We only want file-scoped pragmas
96 my $parent = $elem->parent();
97 return 0 if !$parent->isa('PPI::Document');
98
99 if ( my $pragma = $elem->pragma() ) {
100 return 1 if $self->{_equivalent_modules}{$pragma};
101 }
102 elsif ( my $module = $elem->module() ) {
103 return 1 if $self->{_equivalent_modules}{$module};
104 }
105
106 return 0;
107 };
108}
109
110#-----------------------------------------------------------------------------
111# Here, we're using the fact that Perl::Critic::Document::find() is optimized
112# to search for elements based on their type. This is faster than using the
113# native PPI::Node::find() method with a custom callback function.
114
115sub _find_isnt_include_or_package {
116 my ($self, $doc) = @_;
117 my $all_statements = $doc->find('PPI::Statement') or return;
118 my @wanted_statements = grep { _statement_isnt_include_or_package($_) } @{$all_statements};
119 return @wanted_statements ? \@wanted_statements : ();
120}
121
122#-----------------------------------------------------------------------------
123
124sub _statement_isnt_include_or_package {
125 my ($elem) = @_;
126 return 0 if $elem->isa('PPI::Statement::Package');
127 return 0 if $elem->isa('PPI::Statement::Include');
128 return 1;
129}
130
13114µs1;
132
133__END__