| 1 | package App::PerlNitpick::Rule::RemoveUnnecessaryScalarKeyword; | ||||||||||
| 2 | # ABSTRACT: Remove unnecessary scalar keyword | ||||||||||
| 3 | |||||||||||
| 4 | =encoding UTF-8 | ||||||||||
| 5 | |||||||||||
| 6 | This nitpicking rules removes C<scalar> keywords that are use in scalar context, for example, in this statement: | ||||||||||
| 7 | |||||||||||
| 8 | my $n = scalar @items; | ||||||||||
| 9 | |||||||||||
| 10 | 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. | ||||||||||
| 11 | |||||||||||
| 12 | =cut | ||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use PPI::Document; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use Perl::Critic::Document; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | use Perl::Critic::Policy::TooMuchCode::ProhibitUnnecessaryScalarKeyword; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | use App::PerlNitpick::PCPWrap; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | sub rewrite { | ||||||||
|
Subroutine
rewrite: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||
| 24 | 1 | my ($self, $doc) = @_; | |||||||||
| 25 | |||||||||||
| 26 | 1 | my $o = App::PerlNitpick::PCPWrap->new('Perl::Critic::Policy::TooMuchCode::ProhibitUnnecessaryScalarKeyword'); | |||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | my $elems = $doc->find( $o->applies_to ) or return $doc; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 1 | my @vio = map { $o->violates($_, $doc) } @$elems; | |||||||||
| 30 | |||||||||||
| 31 | 1 | for (@vio) { | |||||||||
| 32 | 1 | my ($msg, $explain, $el) = @$_; | |||||||||
| 33 | 1 | ▶ | if ($el->next_sibling eq ' ') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 1 | $el->next_sibling->remove; | |||||||||
| 35 | } | ||||||||||
| 36 | 1 | $el->remove; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 1 | return $doc; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 1 | 1; | |||||||||