| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Variables/ProhibitUnusedVariables.pm |
| Statements | Executed 21 statements in 623µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 18µs | 19µs | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::default_severity |
| 1 | 1 | 1 | 16µs | 16µs | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@10 |
| 1 | 1 | 1 | 11µs | 15µs | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@12 |
| 1 | 1 | 1 | 9µs | 9µs | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@17 |
| 1 | 1 | 1 | 7µs | 28µs | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@14 |
| 1 | 1 | 1 | 7µs | 54µs | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@20 |
| 1 | 1 | 1 | 7µs | 335µs | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@19 |
| 1 | 1 | 1 | 7µs | 18µs | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@11 |
| 1 | 1 | 1 | 7µs | 139µs | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@15 |
| 1 | 1 | 1 | 2µs | 2µs | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::supported_parameters |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::__ANON__[:56] |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::_get_regexp_symbol_usage |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::_get_symbol_usage |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::applies_to |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::default_themes |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Variables::ProhibitUnusedVariables::violates |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | ############################################################################## | ||||
| 2 | # $URL$ | ||||
| 3 | # $Date$ | ||||
| 4 | # $Author$ | ||||
| 5 | # $Revision$ | ||||
| 6 | ############################################################################## | ||||
| 7 | |||||
| 8 | package Perl::Critic::Policy::Variables::ProhibitUnusedVariables; | ||||
| 9 | |||||
| 10 | 2 | 45µs | 1 | 16µ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 # spent 16µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@10 |
| 11 | 2 | 20µs | 2 | 29µ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 # spent 18µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@11
# spent 11µs making 1 call to strict::import |
| 12 | 2 | 19µs | 2 | 18µ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 # spent 15µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@12
# spent 4µs making 1 call to warnings::import |
| 13 | |||||
| 14 | 2 | 22µs | 2 | 48µ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 # spent 28µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@14
# spent 20µs making 1 call to Exporter::import |
| 15 | 2 | 23µs | 2 | 270µ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 # 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 | |||||
| 17 | 2 | 26µs | 1 | 9µ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 # spent 9µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@17 |
| 18 | |||||
| 19 | 2 | 24µs | 2 | 663µ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 # spent 335µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@19
# spent 328µs making 1 call to Exporter::import |
| 20 | 2 | 433µs | 2 | 100µ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 # spent 54µs making 1 call to Perl::Critic::Policy::Variables::ProhibitUnusedVariables::BEGIN@20
# spent 47µs making 1 call to base::import |
| 21 | |||||
| 22 | 1 | 600ns | our $VERSION = '1.121'; | ||
| 23 | |||||
| 24 | #----------------------------------------------------------------------------- | ||||
| 25 | |||||
| 26 | 1 | 2µs | 1 | 30µs | Readonly::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 | |||||
| 31 | 1 | 5µ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 | ||
| 32 | 1 | 1µ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 | ||
| 33 | sub default_themes { return qw< core maintenance certrec > } | ||||
| 34 | sub applies_to { return qw< PPI::Document > } | ||||
| 35 | |||||
| 36 | #----------------------------------------------------------------------------- | ||||
| 37 | |||||
| 38 | sub 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 | |||||
| 77 | sub _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 | |||||
| 90 | sub _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 | |||||
| 119 | 1 | 3µs | 1; | ||
| 120 | |||||
| 121 | __END__ |