| 1 | package App::perlimports::Annotations; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # Some of this logic was lifted directly from Perl::Critic::Annotation | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 107 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 107 | our $VERSION = '0.000067'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 107 | ▶ | use Types::Standard qw( ArrayRef Object ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 107 | has _annotations => ( | |||||||||||||||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 13 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | builder => '_build_annotations', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 107 | has _ppi_document => ( | |||||||||||||||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | isa => Object, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | init_arg => 'ppi_document', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 160 | ▶ | sub _build_annotations { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_annotations: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 160 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 160 | my @found = (); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 160 | ▶ | my $comments | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_ppi_document->find('PPI::Token::Comment') || (return [])
MC/DC100%1/1
$self->_ppi_document->find('PPI::Token::Comment') || (return [])
$self->_ppi_document->find('PPI::Token::Comment')
Truth table100%2/2
A
A= $self->_ppi_document->find('PPI::Token::Comment')
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | = $self->_ppi_document->find('PPI::Token::Comment') || return []; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 36 | my $disable_rx = qr{[#][#] \s* no \s+ perlimports}xms; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 36 | my $enable_rx = qr{[#][#] \s* use \s+ perlimports}xms; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 36 | my @enabled = ( grep { $_ =~ $enable_rx } @{$comments} ); | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 36 | for my $element ( grep { $_ =~ $disable_rx } @{$comments} ) { | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 11 | ▶ | my %found = ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | column_number => $element->column_number, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | line_number => $element->logical_line_number, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | range => [ | ||||||||||||||||||||||||||||||||||||||||||
| 42 | $element->logical_line_number, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | $element->column_number > 1 | ||||||||||||||||||||||||||||||||||||||||||
| 44 | ? ( $element->logical_line_number ) | ||||||||||||||||||||||||||||||||||||||||||
| 45 | : () | ||||||||||||||||||||||||||||||||||||||||||
| 46 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # Seek ahead to see if/when perlimpts is re-enabled | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 11 | ▶ | if ( $element->column_number == 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | for my $on (@enabled) { | |||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | if ( $on->column_number == 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$on->column_number == 1 and $on->logical_line_number > $element->logical_line_number
MC/DC0%0/2
$on->column_number == 1 and $on->logical_line_number > $element->logical_line_number
$on->column_number == 1
$on->logical_line_number > $element->logical_line_number
Truth table33%1/3
A and B
A= $on->column_number == 1B= $on->logical_line_number > $element->logical_line_number
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | && $on->logical_line_number | ||||||||||||||||||||||||||||||||||||||||||
| 54 | > $element->logical_line_number ) { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | $found{range}->[1] = $on->logical_line_number; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 11 | push @found, \%found; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 36 | return \@found; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 310 | ▶ | sub is_ignored { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ignored: called CC=9 SCAR=22.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 310 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 310 | my $element = shift; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 310 | ▶ | unless ( $element && ref($element) && $element->isa('PPI::Element') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$element and ref $element and $element->isa("PPI::Element")
$element and ref $element
MC/DC0%0/3
$element and ref $element and $element->isa("PPI::Element")
$element
ref $element
$element->isa("PPI::Element")
Truth table25%1/4
A and B and C
A= $elementB= ref $elementC= $element->isa("PPI::Element")
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | die 'PPI::Element required'; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 310 | my $line = $element->logical_line_number; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 310 | for my $a ( @{ $self->_annotations } ) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | 43 | my ( $min, $max ) = @{ $a->{range} }; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 43 | ▶ | if ( $line >= $min && ( !$max || $line <= $max ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$line >= $min and !$max || $line <= $max
not $max or $line <= $max
MC/DC100%3/3
$line >= $min and !$max || $line <= $max
$line >= $min
not $max
$line <= $max
Truth table100%4/4
A and not(B) or C
A= $line >= $minB= not $maxC= $line <= $max
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 19 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # Any further annotations do not apply to this element | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 24 | ▶ | last if $line < $max; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 291 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 107 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # ABSTRACT: Find line ranges where perlimports has been disabled | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||||||||||||||