| 1 | package App::PerlNitpick::Rule::DedupeIncludeStatements; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | sub rewrite { | ||||||||||||||||||||||||||
|
Subroutine
rewrite: called CC=7 SCAR=19.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 5 | 4 | my ($self, $document) = @_; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | my %used; | |||||||||||||||||||||||||||
| 8 | my @to_delete; | ||||||||||||||||||||||||||||
| 9 | 4 | ▶ | for my $el (@{ $document->find('PPI::Statement::Include') ||[]}) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$document->find('PPI::Statement::Include') || []
MC/DC0%0/1
$document->find('PPI::Statement::Include') || []
$document->find('PPI::Statement::Include')
Truth table50%1/2
A
A= $document->find('PPI::Statement::Include')
| |||||||||||||||||||||||||||||
| 10 | 9 | ▶ | next unless $el->type && $el->type eq 'use'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$el->type and $el->type eq "use"
MC/DC0%0/2
$el->type and $el->type eq "use"
$el->type
$el->type eq "use"
Truth table33%1/3
A and B
A= $el->typeB= $el->type eq "use"
| |||||||||||||||||||||||||||||
| 11 | 9 | my $module = $el->module; | |||||||||||||||||||||||||||
| 12 | 9 | my $code = "$el"; | |||||||||||||||||||||||||||
| 13 | 9 | ▶ | if ($used{$code}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 4 | push @to_delete, $el; | |||||||||||||||||||||||||||
| 15 | } else { | ||||||||||||||||||||||||||||
| 16 | 5 | $used{$code} = 1; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 4 | for my $el (@to_delete) { | |||||||||||||||||||||||||||
| 21 | 4 | $self->_remove_with_trailing_characters($el); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 4 | return $document; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 4 | ▶ | sub _remove_with_trailing_characters { | ||||||||||||||||||||||||||
|
Subroutine
_remove_with_trailing_characters: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 28 | 4 | my ($self, $el) = @_; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 4 | ▶ | while ( my $next = $el->next_sibling ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | last if !$next->isa('PPI::Token::Whitespace'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | $next->remove; | |||||||||||||||||||||||||||
| 33 | 1 | ▶ | last if $next eq "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 4 | $el->remove; | |||||||||||||||||||||||||||
| 36 | 4 | return; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 1 | 1; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | __END__ | ||||||||||||||||||||||||||||