← 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/ProhibitUnusedVariables.pm
StatementsExecuted 21 statements in 623µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11118µs19µsPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::default_severityPerl::Critic::Policy::Variables::ProhibitUnusedVariables::default_severity
11116µs16µsPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::BEGIN@10Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@10
11111µs15µsPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::BEGIN@12Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@12
1119µs9µsPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::BEGIN@17Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@17
1117µs28µsPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::BEGIN@14Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@14
1117µs54µsPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::BEGIN@20Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@20
1117µs335µsPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::BEGIN@19Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@19
1117µs18µsPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::BEGIN@11Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@11
1117µs139µsPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::BEGIN@15Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@15
1112µs2µsPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::supported_parametersPerl::Critic::Policy::Variables::ProhibitUnusedVariables::supported_parameters
0000s0sPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::__ANON__[:56]Perl::Critic::Policy::Variables::ProhibitUnusedVariables::__ANON__[:56]
0000s0sPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::_get_regexp_symbol_usagePerl::Critic::Policy::Variables::ProhibitUnusedVariables::_get_regexp_symbol_usage
0000s0sPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::_get_symbol_usagePerl::Critic::Policy::Variables::ProhibitUnusedVariables::_get_symbol_usage
0000s0sPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::applies_toPerl::Critic::Policy::Variables::ProhibitUnusedVariables::applies_to
0000s0sPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::default_themesPerl::Critic::Policy::Variables::ProhibitUnusedVariables::default_themes
0000s0sPerl::Critic::Policy::Variables::ProhibitUnusedVariables::::violatesPerl::Critic::Policy::Variables::ProhibitUnusedVariables::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::ProhibitUnusedVariables;
9
10245µs116µs
# spent 16µs within Perl::Critic::Policy::Variables::ProhibitUnusedVariables::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::Variables::ProhibitUnusedVariables::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::Variables::ProhibitUnusedVariables::BEGIN@11 # spent 11µs making 1 call to strict::import
12219µs218µs
# spent 15µs (11+4) within Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@12 which was called: # once (11µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
# spent 15µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@12 # spent 4µs making 1 call to warnings::import
13
14222µs248µs
# spent 28µs (7+20) within Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@14 which was called: # once (7µs+20µs) by Module::Pluggable::Object::_require at line 14
use Readonly;
# spent 28µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@14 # spent 20µs making 1 call to Exporter::import
15223µs2270µs
# spent 139µs (7+132) within Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@15 which was called: # once (7µs+132µs) by Module::Pluggable::Object::_require at line 15
use List::MoreUtils qw< any >;
# spent 139µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@15 # spent 132µs making 1 call to Exporter::Tiny::import
16
17226µs19µs
# spent 9µs within Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@17 which was called: # once (9µs+0s) by Module::Pluggable::Object::_require at line 17
use PPI::Token::Symbol;
18
19224µs2663µs
# spent 335µs (7+328) within Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@19 which was called: # once (7µs+328µs) by Module::Pluggable::Object::_require at line 19
use Perl::Critic::Utils qw< :characters :severities >;
# spent 335µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@19 # spent 328µs making 1 call to Exporter::import
202433µs2100µs
# spent 54µs (7+47) within Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@20 which was called: # once (7µs+47µs) by Module::Pluggable::Object::_require at line 20
use base 'Perl::Critic::Policy';
# spent 54µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@20 # spent 47µs making 1 call to base::import
21
221600nsour $VERSION = '1.121';
23
24#-----------------------------------------------------------------------------
25
2612µs130µsReadonly::Scalar my $EXPL =>
# spent 30µs making 1 call to Readonly::Scalar
27 q<Unused variables clutter code and make it harder to read>;
28
29#-----------------------------------------------------------------------------
30
3115µs
# spent 2µs within Perl::Critic::Policy::Variables::ProhibitUnusedVariables::supported_parameters which was called: # once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters { return () }
3211µs
# spent 19µs (18+1) within Perl::Critic::Policy::Variables::ProhibitUnusedVariables::default_severity which was called: # once (18µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm
sub default_severity { return $SEVERITY_MEDIUM }
33sub default_themes { return qw< core maintenance certrec > }
34sub applies_to { return qw< PPI::Document > }
35
36#-----------------------------------------------------------------------------
37
38sub violates {
39 my ( $self, $elem, $document ) = @_;
40
41 my %symbol_usage;
42 _get_symbol_usage( \%symbol_usage, $document );
43 _get_regexp_symbol_usage( \%symbol_usage, $document );
44 return if not %symbol_usage;
45
46 my $declarations = $document->find('PPI::Statement::Variable');
47 return if not $declarations;
48
49 my @violations;
50
51 DECLARATION:
52 foreach my $declaration ( @{$declarations} ) {
53 next DECLARATION if 'my' ne $declaration->type();
54
55 my @children = $declaration->schildren();
56 next DECLARATION if any { $_ eq q<=> } @children;
57
58 VARIABLE:
59 foreach my $variable ( $declaration->variables() ) {
60 my $count = $symbol_usage{ $variable };
61 next VARIABLE if not $count; # BUG!
62 next VARIABLE if $count > 1;
63
64 push
65 @violations,
66 $self->violation(
67 qq<"$variable" is declared but not used.>,
68 $EXPL,
69 $declaration,
70 );
71 }
72 }
73
74 return @violations;
75}
76
77sub _get_symbol_usage {
78 my ( $symbol_usage, $document ) = @_;
79
80 my $symbols = $document->find('PPI::Token::Symbol');
81 return if not $symbols;
82
83 foreach my $symbol ( @{$symbols} ) {
84 $symbol_usage->{ $symbol->symbol() }++;
85 }
86
87 return;
88}
89
90sub _get_regexp_symbol_usage {
91 my ( $symbol_usage, $document ) = @_;
92
93 foreach my $class ( qw{
94 PPI::Token::Regexp::Match
95 PPI::Token::Regexp::Substitute
96 PPI::Token::QuoteLike::Regexp
97 } ) {
98
99 foreach my $regex ( @{ $document->find( $class ) || [] } ) {
100
101 my $ppix = $document->ppix_regexp_from_element( $regex ) or next;
102 $ppix->failures() and next;
103
104 foreach my $code ( @{
105 $ppix->find( 'PPIx::Regexp::Token::Code' ) || [] } ) {
106 my $subdoc = $code->ppi() or next;
107 _get_symbol_usage( $symbol_usage, $subdoc );
108 }
109
110 }
111
112 }
113
114 return;
115}
116
117#-----------------------------------------------------------------------------
118
11913µs1;
120
121__END__