blib/lib/App/perlimports/Annotations.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 83.3% 10 / 12 Conditioncond 64.7% 11 / 17 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 83.3% 70 / 84 CC 16 SCAR 20.9
CC
16
Cov
87%
is_ignored
9.6
_build_annotations
8.1
BEGIN
1.0
CRAP 8.0
« blib/lib/App/perlimports/Document.pm ↑ Summary blib/lib/App/perlimports/Sorter.pm »
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 [])
l!l
36124
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')
Aresult
11
00
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
BranchTrueFalseTotal
$element->column_number > 1 ? : 7 4 11
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
BranchTrueFalseTotal
if ($element->column_number == 1) 4 7 11
51 4 for my $on (@enabled) {
52 3 ▶ if ( $on->column_number == 1
Branch: 1 branch
BranchTrueFalseTotal
if ($on->column_number == 1 and $on->logical_line_number > $element->logical_line_number) 3 0 3
Condition33%1/3
$on->column_number == 1 and $on->logical_line_number > $element->logical_line_number
!ll&&!rl&&r
003
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless ($element and ref $element and $element->isa("PPI::Element")) 0 310 310
Condition33%2/6
$element and ref $element and $element->isa("PPI::Element")
!ll&&!rl&&r
00310
$element and ref $element
!ll&&!rl&&r
00310
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")
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if ($line >= $min and !$max || $line <= $max) 19 24 43
Condition100%6/6
$line >= $min and !$max || $line <= $max
!ll&&!rl&&r
91519
not $max or $line <= $max
l!l&&r!l&&!r
71215
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
ABCresult
0XX0
1000
11X1
1011
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
BranchTrueFalseTotal
if $line < $max 9 15 24
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__
« blib/lib/App/perlimports/Document.pm ↑ Summary blib/lib/App/perlimports/Sorter.pm »