File Coverage

blib/lib/App/PerlNitpick/Rule/RemoveUnnecessaryScalarKeyword.pm
Criterion Covered Total %
statement 29 29 100.0
branch 2 4 50.0
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 38 41 92.6


line stmt bran cond sub pod time code
1             # ABSTRACT: Remove unnecessary scalar keyword
2              
3             =encoding UTF-8
4              
5             This nitpicking rules removes C<scalar> keywords that are use in scalar context, for example, in this statement:
6              
7             my $n = scalar @items;
8              
9             Since the left hand side is a single scalar variable, the assignment is already in scalar context. It is not necessary to include C<scalar> on the right-hand side.
10              
11             =cut
12              
13             use Moose;
14 1     1   207175 use PPI::Document;
  1         447436  
  1         10  
15 1     1   7762 use Perl::Critic::Document;
  1         93514  
  1         33  
16 1     1   441 use Perl::Critic::Policy::TooMuchCode::ProhibitUnnecessaryScalarKeyword;
  1         732319  
  1         36  
17 1     1   11  
  1         3  
  1         67  
18             use App::PerlNitpick::PCPWrap;
19 1     1   2109  
  1         4  
  1         24  
20             no Moose;
21 1     1   6  
  1         1  
  1         8  
22             my ($self, $doc) = @_;
23              
24 1     1 0 6416 my $o = App::PerlNitpick::PCPWrap->new('Perl::Critic::Policy::TooMuchCode::ProhibitUnnecessaryScalarKeyword');
25              
26 1         9 my $elems = $doc->find( $o->applies_to ) or return $doc;
27             my @vio = map { $o->violates($_, $doc) } @$elems;
28 1 50       6  
29 1         374 for (@vio) {
  2         29  
30             my ($msg, $explain, $el) = @$_;
31 1         3 if ($el->next_sibling eq ' ') {
32 1         2 $el->next_sibling->remove;
33 1 50       6 }
34 1         36 $el->remove;
35             }
36 1         58  
37             return $doc;
38             }
39 1         61  
40             1;