Pod/Coverage/TrustMe/Parser.pm

filter: Statementstmt 96.5% 85 / 88 Branchbran 93.3% 28 / 30 Conditioncond 83.3% 25 / 30 MC/DCmcdc 80.0% 12 / 15 Subroutinesub 100% 12 / 12 Podpod 100% 5 / 5 totaltotal 92.7% 167 / 180 CC 30 SCAR 20.6
CC
30
Cov
93%
_handle_text
13.7
_handle_element_start
10.0
_handle_element_end
6.0
CRAP 7.8
« Test/Pod/Coverage/TrustMe.pm ↑ Summary Pod/Coverage/TrustMe.pm »
1 package Pod::Coverage::TrustMe::Parser;
2 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 24 our $VERSION = '0.002002';
6 24 $VERSION =~ tr/_//d;
7  
8 24 ▶use Pod::Simple ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 our @ISA = qw(Pod::Simple);
10 24 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 84 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
13 84 my $class = shift;
14 84 my $self = $class->SUPER::new(@_);
15 84 $self->accept_targets_as_text('Pod::Coverage');
16 84 $self->{+__PACKAGE__} = {};
17 84 return $self;
18 }
19  
20 414 ▶sub ignore_empty {
Subroutine ignore_empty: called CC=2 SCAR=6.9
Pod documented
21 414 my $self = shift;
22 414 my $me = $self->{+__PACKAGE__};
23 414 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 413 414
24 1 $me->{ignore_empty} = shift;
25 }
26 414 return $me->{ignore_empty};
27 }
28  
29 2476 ▶sub _handle_element_start {
Subroutine _handle_element_start: called CC=10 SCAR=23.0
30 2476 my $self = shift;
31 2476 my $me = $self->{+__PACKAGE__};
32 2476 my ($name, $attr) = @_;
33 2476 ▶ if ($name eq 'for') {
Branch: 4 branches
BranchTrueFalseTotal
if ($name eq 'for') { } 9 2467 2476
elsif ($name eq 'L' and $attr->{'type'} eq 'pod' and defined $attr->{'to'}) { } 139 2328 2467
elsif ($name eq 'item-text' or $name eq 'item-bullet' or $name =~ /\Ahead[2-9]\z/) { } 413 1915 2328
elsif ($name =~ /\Ahead1\z/) { } 157 1758 1915
34 9 push @{ $me->{in} }, $attr;
35 }
36 ▶ elsif ($name eq 'L' && $attr->{type} eq 'pod' && defined $attr->{to}) {
Condition100%6/6
$name eq "L" and $attr->{"type"} eq "pod" and defined $attr->{"to"}
!ll&&!rl&&r
228939139
$name eq "L" and $attr->{"type"} eq "pod"
!ll&&!rl&&r
227415178
MC/DC100%3/3
$name eq "L" and $attr->{"type"} eq "pod" and defined $attr->{"to"}
$name eq "L" $attr->{"type"} eq "pod" defined $attr->{"to"}
Truth table100%4/4
A and B and C
A= $name eq "L"B= $attr->{"type"} eq "pod"C= defined $attr->{"to"}
ABCresult
0XX0
10X0
1100
1111
37 139 my $to = "$attr->{to}";
38 77 push @{ $me->{links} }, $to
39 139 ▶ unless $me->{links_hash}{$to}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $me->{"links_hash"}{$to}++ 77 62 139
40 }
41 ▶ elsif ($name eq 'item-text' || $name eq 'item-bullet' || $name =~ /\Ahead[2-9]\z/) {
Condition100%6/6
$name eq "item-text" or $name eq "item-bullet" or $name =~ /\Ahead[2-9]\z/
l!l&&r!l&&!r
2751381915
$name eq "item-text" or $name eq "item-bullet"
l!l&&r!l&&!r
250252053
MC/DC100%3/3
$name eq "item-text" or $name eq "item-bullet" or $name =~ /\Ahead[2-9]\z/
$name eq "item-text" $name eq "item-bullet" $name =~ /\Ahead[2-9]\z/
Truth table100%4/4
A or B or C
A= $name eq "item-text"B= $name eq "item-bullet"C= $name =~ /\Ahead[2-9]\z/
ABCresult
1XX1
01X1
0011
0000
42 413 delete $me->{maybe_covered};
43 413 $me->{consider} = $name;
44 413 $me->{consider_text} = '';
45 }
46 elsif ($name =~ /\Ahead1\z/) {
47 157 delete $me->{maybe_covered};
48 }
49 2476 $self->SUPER::_handle_element_start(@_);
50 }
51 2476 ▶sub _handle_element_end {
Subroutine _handle_element_end: called CC=6 SCAR=17.9
52 2476 my $self = shift;
53 2476 my $me = $self->{+__PACKAGE__};
54 2476 my ($name) = @_;
55 2476 ▶ if ($name eq 'for') {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'for') { } 9 2467 2476
elsif ($name eq ($me->{'consider'} || '')) { } 413 2054 2467
56 9 pop @{ $self->{+__PACKAGE__}{in} };
57 }
58 ▶ elsif ($name eq ($me->{consider}||'')) {
Condition100%2/2
$me->{'consider'} || ''
l!l
6201847
MC/DC100%1/1
$me->{'consider'} || ''
$me->{'consider'}
Truth table100%2/2
A
A= $me->{'consider'}
Aresult
11
00
59 413 delete $me->{consider};
60 413 my $text = delete $me->{consider_text};
61 413 my @covered = $text =~ /([^\s\|,\/]+)/g;
62 413 for my $covered ( @covered ) {
63 # looks like a method
64 897 $covered =~ s/.*->//;
65 # looks fully qualified
66 897 $covered =~ s/\A\w+(?:::\w+)*::(\w+)/$1/;
67 # looks like it includes parameters
68 897 $covered =~ s/(\w+)[;\(].*/$1/;
69 }
70 413 @covered = grep /\A\w+\z/, @covered;
71 413 ▶ if ($self->ignore_empty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ignore_empty) { } 2 411 413
72 2 push @{ $me->{maybe_covered} }, @covered;
73 }
74 else {
75 411 push @{ $me->{covered} },
76 411 grep !$me->{covered_hash}{$_}++,
77 @covered;
78 }
79 }
80 2476 $self->SUPER::_handle_element_end(@_);
81 }
82  
83 2831 ▶sub _handle_text {
Subroutine _handle_text: called CC=12 SCAR=26.2
84 2831 my $self = shift;
85 2831 my $me = $self->{+__PACKAGE__};
86 2831 my ($text) = @_;
87 2831 my $in = $me->{in};
88 2831 ▶ if ($in && @$in && $in->[-1]{target} =~ /\APod::Coverage(?:::Trust(?:Me|Pod))?\z/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($in and @$in and $in->[-1]{'target'} =~ /\APod::Coverage(?:::Trust(?:Me|Pod))?\z/) { } 10 2821 2831
elsif ($me->{'consider'}) { } 545 2276 2821
elsif ($me->{'maybe_covered'}) { } 1 2275 2276
Condition83%5/6
$in and @$in and $in->[-1]{"target"} =~ /\APod::Coverage(?:::Trust(?:Me|Pod))?\z/
!ll&&!rl&&r
2821010
$in and @$in
!ll&&!rl&&r
239542610
MC/DC66%2/3
$in and @$in and $in->[-1]{"target"} =~ /\APod::Coverage(?:::Trust(?:Me|Pod))?\z/
$in @$in $in->[-1]{"target"} =~ /\APod::Coverage(?:::Trust(?:Me|Pod))?\z/
Truth table75%3/4
A and B and C
A= $inB= @$inC= $in->[-1]{"target"} =~ /\APod::Coverage(?:::Trust(?:Me|Pod))?\z/
ABCresult
0XX0
10X0
1100
1111
89 10 for my $token ($text =~ /(\S+)/g) {
90 11 my $re;
91 11 ▶ if ($token eq '*EVERYTHING*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq '*EVERYTHING*') { } 1 10 11
92 1 $re = qr{.?};
93 }
94 else {
95 10 $re = eval { qr{\A(?:$token)\z} };
96 10 ▶ if (!$re) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($re) 0 10 10
97 0 ▶ my $file = $self->{source_filename} || '<input>';
Condition0%0/2
$self->{'source_filename'} || '<input>'
l!l
00
MC/DC0%0/1
$self->{'source_filename'} || '<input>'
$self->{'source_filename'}
Truth table0%0/2
A
A= $self->{'source_filename'}
Aresult
11
00
98 0 ▶ my $line = $in->[-1]{start_line} || '<unknown>';
Condition0%0/2
$in->[-1]{'start_line'} || '<unknown>'
l!l
00
MC/DC0%0/1
$in->[-1]{'start_line'} || '<unknown>'
$in->[-1]{'start_line'}
Truth table0%0/2
A
A= $in->[-1]{'start_line'}
Aresult
11
00
99 0 croak "Error compiling Pod::Coverage regex /$token/ at $file line $line: $@";
100 }
101 }
102 11 push @{ $me->{trusted} }, $re
103 11 ▶ unless $me->{trusted_hash}{$re}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $me->{"trusted_hash"}{$re}++ 11 0 11
104 }
105 }
106 elsif ($me->{consider}) {
107 545 $me->{consider_text} .= $text;
108 }
109 elsif ($me->{maybe_covered}) {
110 1 push @{ $me->{covered} },
111 grep !$me->{covered_hash}{$_}++,
112 1 @{ delete $me->{maybe_covered} };
113 }
114 2831 $self->SUPER::_handle_text(@_);
115 }
116  
117 11 ▶sub links {
Subroutine links: called CC=2 SCAR=6.9
Pod documented
118 11 my $self = shift;
119 11 ▶ return $self->{+__PACKAGE__}{links} ||= [];
Condition100%2/2
$self->{"Pod::Coverage::TrustMe::Parser"}{"links"} ||= []
l!l
38
MC/DC100%1/1
$self->{"Pod::Coverage::TrustMe::Parser"}{"links"} ||= []
$self->{"Pod::Coverage::TrustMe::Parser"}{"links"}
Truth table100%2/2
A
A= $self->{"Pod::Coverage::TrustMe::Parser"}{"links"}
Aresult
11
00
120 }
121  
122 28 ▶sub trusted {
Subroutine trusted: called CC=2 SCAR=6.9
Pod documented
123 28 my $self = shift;
124 28 ▶ return $self->{+__PACKAGE__}{trusted} ||= [];
Condition100%2/2
$self->{"Pod::Coverage::TrustMe::Parser"}{"trusted"} ||= []
l!l
820
MC/DC100%1/1
$self->{"Pod::Coverage::TrustMe::Parser"}{"trusted"} ||= []
$self->{"Pod::Coverage::TrustMe::Parser"}{"trusted"}
Truth table100%2/2
A
A= $self->{"Pod::Coverage::TrustMe::Parser"}{"trusted"}
Aresult
11
00
125 }
126  
127 82 ▶sub covered {
Subroutine covered: called CC=2 SCAR=6.9
Pod documented
128 82 my $self = shift;
129 82 ▶ return $self->{+__PACKAGE__}{covered} ||= [];
Condition100%2/2
$self->{"Pod::Coverage::TrustMe::Parser"}{"covered"} ||= []
l!l
6418
MC/DC100%1/1
$self->{"Pod::Coverage::TrustMe::Parser"}{"covered"} ||= []
$self->{"Pod::Coverage::TrustMe::Parser"}{"covered"}
Truth table100%2/2
A
A= $self->{"Pod::Coverage::TrustMe::Parser"}{"covered"}
Aresult
11
00
130 }
131  
132 24 1;
133 __END__
« Test/Pod/Coverage/TrustMe.pm ↑ Summary Pod/Coverage/TrustMe.pm »