| 1 | package Devel::XSCover::XS; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 33 | ▶ | use 5.020; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 33 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 33 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 33 | ▶ | use File::Find (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 33 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 33 | our $VERSION = '0.09'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 33 | our ($KEYWORDS); | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 33 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 33 | $KEYWORDS = qr/^\s*(?:CODE|PPCODE|PREINIT|INPUT|INIT|ALIAS|OUTPUT|PROTOTYPE|C_ARGS|CLEANUP|POSTCALL|OVERLOAD|FALLBACK|ATTRS|INTERFACE|INTERFACE_MACRO|SCOPE|CASE|NO_INIT|NO_OUTPUT|PROTOTYPES|VERSIONCHECK|EXPORT_XSUB_SYMBOLS|REQUIRE|BOOT|INCLUDE|INCLUDE_COMMAND)\s*:/; | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 36 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 36 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 36 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 21 | dir => '.', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | skip => [qw(blib cover_db .git)], | ||||||||||||||||||||||||||||||||||||||||||
| 23 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 36 | $self->{$_} = $args{$_} for keys %args; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 36 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 23 | ▶ | sub generated_files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generated_files: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 23 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 23 | my %pair; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 23 | my $pl = File::Spec->catfile($self->{dir}, 'Makefile.PL'); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 23 | ▶ | if (open my $fh, '<', $pl) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 13 | my $text = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 13 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 13 | ▶ | while ($text =~ /\bXS\s*=>\s*\{(.*?)\}/sg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | my $body = $1; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | while ($body =~ /(['"])([^'"]+)\1\s*=>\s*(['"])([^'"]+)\3/g) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | $pair{ $self->_canon($2) } = $self->_canon($4); | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 23 | my %skip = map { $_ => 1 } @{ $self->{skip} }; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 23 | my $top = _slashes($self->{dir}); | |||||||||||||||||||||||||||||||||||||||||
| 44 | File::Find::find({ | ||||||||||||||||||||||||||||||||||||||||||
| 45 | no_chdir => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 251 | ▶ | wanted => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 251 | ▶ | if (-d $_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 76 | my $base = (File::Spec->splitdir($_))[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 76 | ▶ | $File::Find::prune = 1 if $skip{$base} && _slashes($_) ne $top; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$skip{$base} and _slashes($_) ne $top
MC/DC100%2/2
$skip{$base} and _slashes($_) ne $top
$skip{$base}
_slashes($_) ne $top
Truth table100%3/3
A and B
A= $skip{$base}B= _slashes($_) ne $top
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 76 | return; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 175 | ▶ | return unless /\.xs\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 37 | my $rel = _slashes(File::Spec->abs2rel($_, $self->{dir})); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 37 | (my $c = $rel) =~ s/\.xs\z/.c/; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 37 | ▶ | $pair{$rel} = $c unless defined $pair{$rel}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 23 | }, $self->{dir}); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 15 | return map { [ $_, $pair{$_} ] } | |||||||||||||||||||||||||||||||||||||||||
| 59 | 23 | grep { -f File::Spec->catfile($self->{dir}, $pair{$_}) } sort keys %pair; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 24 | ▶ | sub line_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line_map: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 24 | my ($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 24 | my @map; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 24 | my $own = $self->_canon($c); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 24 | my ($file, $line, $said, $dropped) = ($own, 1, 1, undef); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 24 | my %inverse; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 24 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 24 | for my $text ($self->_lines($c)) { | |||||||||||||||||||||||||||||||||||||||||
| 70 | 10892 | $n++; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 10892 | ▶ | if ($text =~ /^#line\s+(\d+)\s+"([^"]*)"/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 438 | $map[$n] = [ $own, $n ]; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 438 | ($file, $line, $said) = ($self->resolve($c, $2), $1, $1); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 438 | ▶ | $dropped = $file eq $own ? undef : $self->_dropped($file); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 438 | next; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 10454 | ▶ | $line++ while $dropped && $dropped->{$line}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dropped and $dropped->{$line}
MC/DC100%2/2
$dropped and $dropped->{$line}
$dropped
$dropped->{$line}
Truth table100%3/3
A and B
A= $droppedB= $dropped->{$line}
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 10454 | ▶ | $inverse{$file}{$said} //= $line if $said != $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$inverse{$file}{$said} //= $line
MC/DC0%0/2
$inverse{$file}{$said} //= $line
$inverse{$file}{$said}
$line
Truth table33%1/3
A //= B
A= $inverse{$file}{$said}B= $line
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 10454 | $map[$n] = [ $file, $line++ ]; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 10454 | $said++; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 23 | $self->{inverse}{$own} = \%inverse; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 23 | return \@map; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 209 | ▶ | sub _dropped { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dropped: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 209 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 209 | ▶ | return $self->{dropped}{$file} if exists $self->{dropped}{$file}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 36 | my %dropped; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 36 | ▶ | my $path = File::Spec->file_name_is_absolute($file) ? $file : File::Spec->catfile($self->{dir}, $file); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 36 | ▶ | if (-f $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 35 | require Devel::XSCover::Flow; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 35 | %dropped = %{ Devel::XSCover::Flow->new->dropped([ $self->_lines($file) ]) }; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 36 | return $self->{dropped}{$file} = \%dropped; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 22 | ▶ | sub xsubs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsubs: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 22 | my ($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 22 | my @lines = $self->_lines($c); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 22 | my $canon = $self->_canon($c); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 22 | my @xsubs; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 22 | for my $i (0 .. $#lines) { | |||||||||||||||||||||||||||||||||||||||||
| 104 | 10120 | ▶ | next unless $lines[$i] =~ /^XS(?:_EUPXS|_EXTERNAL|_INTERNAL)?\((\w+)\)\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 204 | my $name = $1; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 204 | ▶ | next if $name =~ /^boot_/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 183 | my %xsub = (c_name => $name, c_line => $i + 1); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 183 | for my $j ($i + 1 .. $#lines) { | |||||||||||||||||||||||||||||||||||||||||
| 109 | 1836 | ▶ | last if $lines[$j] =~ /^XS(?:_EUPXS|_EXTERNAL|_INTERNAL)?\(\w+\)\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 1830 | ▶ | next unless $lines[$j] =~ /^#line\s+(\d+)\s+"([^"]*)"/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 179 | my $file = $self->resolve($c, $2); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 179 | ▶ | next if $file eq $canon; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 177 | @xsub{qw(file body_line)} = ($file, $1); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 177 | last; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 183 | push @xsubs, \%xsub; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 22 | return @xsubs; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 22 | ▶ | sub perl_names { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perl_names: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 22 | my ($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 22 | my %names; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 22 | for my $text ($self->_lines($c)) { | |||||||||||||||||||||||||||||||||||||||||
| 125 | 10433 | ▶ | next unless $text =~ /newXS\w*\s*\(\s*"([^"]+)"\s*,\s*(XS_\w+)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 200 | push @{ $names{$2} }, $1; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 22 | return \%names; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 162 | ▶ | sub declaration_line { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
declaration_line: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 162 | my ($self, $file, $body_line, $sub) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 162 | my @lines = $self->_lines($file); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 162 | ▶ | for (my $i = $body_line - 2; $i >= 0; $i--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 546 | my $text = $lines[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 546 | ▶ | next if $text =~ /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 542 | ▶ | next if $text =~ $KEYWORDS; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 366 | ▶ | next if $text =~ /^\s/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 169 | ▶ | next if $text =~ /^[{}]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 165 | ▶ | return undef if $text =~ /^MODULE\s*=/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 164 | ▶ | if ($text =~ /^(\w+)\s*\(/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 159 | ▶ | return $i + 1 if !defined $sub || $1 eq $sub; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $sub or $1 eq $sub
MC/DC100%2/2
not defined $sub or $1 eq $sub
not defined $sub
$1 eq $sub
Truth table100%3/3
not(A) or B
A= not defined $subB= $1 eq $sub
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 12 | ▶ | sub find_declaration { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_declaration: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 12 | my ($self, $files, $perl_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 12 | my ($package, $sub) = $perl_name =~ /^(?:(.*)::)?(\w+)$/; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 12 | ▶ | return unless defined $sub; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 10 | ▶ | $package //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$package //= ""
MC/DC100%1/1
$package //= ""
$package
Truth table100%2/2
A
A= $package
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 10 | for my $file (@$files) { | |||||||||||||||||||||||||||||||||||||||||
| 155 | 18 | my $current = ''; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 18 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 18 | for my $text ($self->_lines($file)) { | |||||||||||||||||||||||||||||||||||||||||
| 158 | 513 | $n++; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 513 | ▶ | if ($text =~ /^MODULE\s*=\s*\S+(?:\s+PACKAGE\s*=\s*(\S+))?/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 11 | ▶ | $current = $1 // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$1 // ""
MC/DC0%0/1
$1 // ""
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 502 | ▶ | return ($file, $n) if $text =~ /^\Q$sub\E\s*\(/ && ($current eq $package || $current eq ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$text =~ /^\Q$sub\E\s*\(/u and $current eq $package || $current eq ""
$current eq $package or $current eq ""
MC/DC100%3/3
$text =~ /^\Q$sub\E\s*\(/u and $current eq $package || $current eq ""
$text =~ /^\Q$sub\E\s*\(/u
$current eq $package
$current eq ""
Truth table100%4/4
A and B or C
A= $text =~ /^\Q$sub\E\s*\(/uB= $current eq $packageC= $current eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 19 | ▶ | sub map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 19 | my ($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 19 | my $lines = $self->line_map($c); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 19 | my $canon = $self->_canon($c); | |||||||||||||||||||||||||||||||||||||||||
| 173 | 19 | my %files; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 19 | for my $entry (@$lines) { | |||||||||||||||||||||||||||||||||||||||||
| 175 | 8286 | ▶ | next unless $entry; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 8267 | ▶ | $files{ $entry->[0] }++ unless $entry->[0] eq $canon; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 19 | my @files = sort keys %files; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 19 | my $names = $self->perl_names($c); | |||||||||||||||||||||||||||||||||||||||||
| 180 | 19 | my %xsubs; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 19 | for my $xsub ($self->xsubs($c)) { | |||||||||||||||||||||||||||||||||||||||||
| 182 | 159 | ▶ | my @names = @{ $names->{ $xsub->{c_name} } || [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$names{$xsub->{'c_name'}} || []
MC/DC100%1/1
$$names{$xsub->{'c_name'}} || []
$$names{$xsub->{'c_name'}}
Truth table100%2/2
A
A= $$names{$xsub->{'c_name'}}
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 159 | ▶ | my $sub = @names ? ($names[0] =~ /(\w+)$/)[0] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 159 | my $line; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 159 | ▶ | if ($xsub->{file}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 156 | $line = $self->declaration_line($xsub->{file}, $xsub->{body_line}, $sub); | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 159 | ▶ | if (!defined $line && @names) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $line and @names
MC/DC100%2/2
not defined $line and @names
not defined $line
@names
Truth table100%3/3
not(A) and B
A= not defined $lineB= @names
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 4 | my ($file, $found) = $self->find_declaration(\@files, $names[0]); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 4 | ▶ | @{$xsub}{qw(file body_line)} = ($file, undef) if $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 4 | $line = $found; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | $xsubs{ $xsub->{c_name} } = { | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 159 | %$xsub, | |||||||||||||||||||||||||||||||||||||||||
| 195 | names => \@names, | ||||||||||||||||||||||||||||||||||||||||||
| 196 | line => $line, | ||||||||||||||||||||||||||||||||||||||||||
| 197 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 19 | ▶ | return { c => $canon, inverse => $self->{inverse}{$canon} || {}, files => \@files, lines => $lines, xsubs => \%xsubs }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'inverse'}{$canon} || {}
MC/DC0%0/1
$self->{'inverse'}{$canon} || {}
$self->{'inverse'}{$canon}
Truth table50%1/2
A
A= $self->{'inverse'}{$canon}
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | ▶ | sub subroutines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subroutines: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 6 | my ($self, $map) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 6 | my @subs; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 6 | for my $c_name (sort keys %{ $map->{xsubs} }) { | |||||||||||||||||||||||||||||||||||||||||
| 206 | 37 | my $x = $map->{xsubs}{$c_name}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 37 | ▶ | next unless defined $x->{line} && @{ $x->{names} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $x->{"line"} and @{$x->{"names"};}
MC/DC100%2/2
defined $x->{"line"} and @{$x->{"names"};}
defined $x->{"line"}
@{$x->{"names"};}
Truth table100%3/3
A and B
A= defined $x->{"line"}B= @{$x->{"names"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 33 | push @subs, { c_name => $c_name, file => $x->{file}, line => $x->{line}, names => $x->{names} }; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 6 | return @subs; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 19 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 19 | return map { $self->map($_->[1]) } $self->generated_files; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 283 | ▶ | sub _lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lines: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 283 | my ($self, $rel) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 283 | ▶ | my $path = File::Spec->file_name_is_absolute($rel) ? $rel : File::Spec->catfile($self->{dir}, $rel); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 283 | ▶ | open my $fh, '<', $path or die "xs_cover: cannot read $path: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 282 | my @lines = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 282 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 282 | chomp @lines; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 282 | return @lines; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 621 | ▶ | sub resolve { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 621 | my ($self, $c, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 621 | my $canon = $self->_canon($name); | |||||||||||||||||||||||||||||||||||||||||
| 231 | 621 | ▶ | return $canon if File::Spec->file_name_is_absolute($name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 618 | ▶ | return $canon if -f File::Spec->catfile($self->{dir}, $canon); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 14 | my ($vol, $dirs) = File::Spec->splitpath($c); | |||||||||||||||||||||||||||||||||||||||||
| 234 | 14 | my $beside = $self->_canon(File::Spec->catpath($vol, $dirs, $name)); | |||||||||||||||||||||||||||||||||||||||||
| 235 | 14 | ▶ | return -f File::Spec->catfile($self->{dir}, $beside) ? $beside : $canon; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 706 | ▶ | sub _canon { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_canon: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 706 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 706 | $name =~ s{^\./+}{}; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 706 | return _slashes(File::Spec->canonpath($name)); | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 768 | ▶ | sub _slashes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_slashes: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 768 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 768 | ▶ | $path =~ s{\\}{/}g if $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 768 | return $path; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 33 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | __END__ | ||||||||||||||||||||||||||||||||||||||||||