| 1 | package Text::AsciidocDown::Include; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 18 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 18 | our $VERSION = '0.1.3'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 18 | ▶ | use Cwd qw(abs_path getcwd); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 18 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 18 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 18 | ▶ | use Text::AsciidocDown::Subs (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | sub expand_includes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 109 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_includes: called CC=14 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 109 | my ($text, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 109 | ▶ | $text = '' unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 109 | ▶ | $opts ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts ||= {}
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 109 | ▶ | my $include = ref($opts->{include}) eq 'HASH' ? $opts->{include} : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 109 | ▶ | return $text unless $include->{enabled}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 21 | ▶ | my $base_dir = defined($include->{base_dir}) ? $include->{base_dir} : getcwd(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 21 | ▶ | $base_dir = abs_path($base_dir) || $base_dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
abs_path($base_dir) || $base_dir
MC/DC0%0/2
abs_path($base_dir) || $base_dir
abs_path($base_dir)
$base_dir
Truth table33%1/3
A || B
A= abs_path($base_dir)B= $base_dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | my $ctx = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | include => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | max_depth => defined($include->{max_depth}) ? int($include->{max_depth}) : 64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | on_missing => $include->{on_missing} || 'error', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | on_cycle => $include->{on_cycle} || 'error', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | on_missing_tag => $include->{on_missing_tag} || 'error', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | on_bad_selector => $include->{on_bad_selector} || 'error', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | restrict_to_base_dir => $include->{restrict_to_base_dir} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | base_dir => $base_dir, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | attributes => ref($opts->{attributes}) eq 'HASH' ? $opts->{attributes} : {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 21 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%8/8
$include->{'on_missing'} || 'error'
$include->{'on_cycle'} || 'error'
$include->{'on_missing_tag'} || 'error'
$include->{'on_bad_selector'} || 'error'
MC/DC100%1/1
$include->{'on_missing'} || 'error'
$include->{'on_missing'}
MC/DC100%1/1
$include->{'on_cycle'} || 'error'
$include->{'on_cycle'}
MC/DC100%1/1
$include->{'on_missing_tag'} || 'error'
$include->{'on_missing_tag'}
MC/DC100%1/1
$include->{'on_bad_selector'} || 'error'
$include->{'on_bad_selector'}
Truth table100%2/2
A
A= $include->{'on_missing'}
Truth table100%2/2
A
A= $include->{'on_cycle'}
Truth table100%2/2
A
A= $include->{'on_missing_tag'}
Truth table100%2/2
A
A= $include->{'on_bad_selector'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | _expand_text( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | $text, $ctx, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | source_path => $opts->{source_path}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 21 | depth => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | stack => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | sub _expand_text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 40 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expand_text: called CC=21 SCAR=31.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 40 | my ($text, $ctx, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 40 | ▶ | if ($state->{depth} > $ctx->{include}{max_depth}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | die "include recursion depth exceeded at " . _where($state->{source_path}, 0) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 39 | my @lines = split /\n/, $text, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 39 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 39 | ▶ | my %attrs = %{$ctx->{attributes} || {}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ctx->{'attributes'} || {}
MC/DC0%0/1
$ctx->{'attributes'} || {}
$ctx->{'attributes'}
Truth table50%1/2
A
A= $ctx->{'attributes'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 39 | for my $idx (0 .. $#lines) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 212 | my $line = $lines[$idx]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 212 | ▶ | if ($line =~ /^:([^:-][^:]*):(?:\s(.*))?$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | my ($name, $value) = ($1, defined($2) ? $2 : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | $attrs{$name} = Text::AsciidocDown::Subs::substitute_attributes($value, \%attrs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | push @out, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 211 | ▶ | if ($line =~ /^\\include::([^[]+)\[(.*)\]$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | push @out, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 210 | ▶ | unless ($line =~ /^include::([^[]+)\[(.*)\]$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 187 | push @out, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 187 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 23 | my ($target_raw, $attrlist) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 23 | my $target = Text::AsciidocDown::Subs::substitute_attributes($target_raw, \%attrs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 23 | my $selectors = _parse_selector_attrlist($attrlist, \%attrs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 23 | ▶ | if ($target =~ m{^[a-z]+://}i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | push @out, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 23 | my $resolved = _resolve_target($target, $state->{source_path}, $ctx->{include}{base_dir}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 23 | ▶ | unless (defined $resolved && -f $resolved) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $resolved and -f $resolved
MC/DC50%1/2
defined $resolved and -f $resolved
defined $resolved
-f $resolved
Truth table66%2/3
A and B
A= defined $resolvedB= -f $resolved
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | my $mode = $ctx->{include}{on_missing}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | ▶ | if ($mode eq 'keep') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | push @out, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | if ($mode eq 'drop') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | die "missing include target '$target' resolved to '$resolved' at " . _where($state->{source_path}, $idx + 1) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 20 | ▶ | if ($ctx->{include}{restrict_to_base_dir} && !_is_under_base($resolved, $ctx->{include}{base_dir})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ctx->{"include"}{"restrict_to_base_dir"} and not _is_under_base($resolved, $ctx->{"include"}{"base_dir"})
MC/DC0%0/2
$ctx->{"include"}{"restrict_to_base_dir"} and not _is_under_base($resolved, $ctx->{"include"}{"base_dir"})
$ctx->{"include"}{"restrict_to_base_dir"}
not _is_under_base($resolved, $ctx->{"include"}{"base_dir"})
Truth table33%1/3
A and not(B)
A= $ctx->{"include"}{"restrict_to_base_dir"}B= not _is_under_base($resolved, $ctx->{"include"}{"base_dir"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | die "include target '$resolved' is outside base dir '$ctx->{include}{base_dir}' at " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | _where($state->{source_path}, $idx + 1) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 20 | ▶ | if (grep { $_ eq $resolved } @{$state->{stack}}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | my $mode = $ctx->{include}{on_cycle}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | if ($mode eq 'keep') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | push @out, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | if ($mode eq 'drop') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | my $chain = join(' -> ', @{$state->{stack}}, $resolved); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | die "include cycle detected: $chain at " . _where($state->{source_path}, $idx + 1) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 19 | my $content = _read_file($resolved); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | my $expanded = _expand_text( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | $content, $ctx, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | source_path => $resolved, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | depth => $state->{depth} + 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 19 | stack => [@{$state->{stack}}, $resolved], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 16 | my ($ok, $selected, $action) = _apply_selectors($expanded, $selectors, $ctx, $line, $state, $idx + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 16 | ▶ | if (!$ok) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 6 | ▶ | if ($action eq 'keep') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 3 | push @out, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | ▶ | if ($action eq 'drop') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | die $selected; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 10 | push @out, split /\n/, $selected, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 32 | return join("\n", @out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | sub _parse_selector_attrlist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 23 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_selector_attrlist: called CC=7 SCAR=20.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 23 | my ($attrlist, $attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 23 | my %s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 23 | ▶ | return \%s unless defined $attrlist && $attrlist ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $attrlist and $attrlist ne ""
MC/DC50%1/2
defined $attrlist and $attrlist ne ""
defined $attrlist
$attrlist ne ""
Truth table66%2/3
A and B
A= defined $attrlistB= $attrlist ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 12 | for my $tok (split /,/, $attrlist) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 13 | $tok =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 13 | ▶ | next if $tok eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 13 | my ($k, $v) = split /=/, $tok, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 13 | ▶ | next unless defined $k && defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $k and defined $v
MC/DC0%0/2
defined $k and defined $v
defined $k
defined $v
Truth table33%1/3
A and B
A= defined $kB= defined $v
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 13 | $v = Text::AsciidocDown::Subs::substitute_attributes($v, $attrs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 13 | $s{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 12 | return \%s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | sub _apply_selectors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 16 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_selectors: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 16 | my ($text, $selectors, $ctx, $line, $state, $line_no) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 16 | ▶ | $selectors ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$selectors ||= {}
MC/DC0%0/1
$selectors ||= {}
$selectors
Truth table50%1/2
A
A= $selectors
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 16 | my $work = $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 16 | ▶ | if (exists $selectors->{tags} || exists $selectors->{tag}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $selectors->{"tags"} or exists $selectors->{"tag"}
MC/DC100%2/2
exists $selectors->{"tags"} or exists $selectors->{"tag"}
exists $selectors->{"tags"}
exists $selectors->{"tag"}
Truth table100%3/3
A or B
A= exists $selectors->{"tags"}B= exists $selectors->{"tag"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 7 | ▶ | my @tags = exists($selectors->{tags}) ? split(/;/, $selectors->{tags}) : ($selectors->{tag}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 7 | ▶ | @tags = map { my $x = $_; $x =~ s/^\s+|\s+$//g; $x } grep { defined && $_ ne '' } @tags; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && $_ ne ''
MC/DC0%0/2
defined $_ && $_ ne ''
defined $_
$_ ne ''
Truth table33%1/3
A && B
A= defined $_B= $_ ne ''
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 7 | my ($ok, $res, $action) = _filter_by_tags($work, \@tags, $ctx, $state, $line_no); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | ▶ | return ($ok, $res, $action) unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 3 | $work = $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 12 | ▶ | if (exists $selectors->{lines}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | my ($ok, $res, $action) = _filter_by_lines($work, $selectors->{lines}, $ctx, $state, $line_no); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 6 | ▶ | return ($ok, $res, $action) unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | $work = $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 10 | return (1, $work, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | sub _filter_by_tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filter_by_tags: called CC=11 SCAR=24.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 7 | my ($text, $tags, $ctx, $state, $line_no) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 7 | my %wanted = map { $_ => 1 } @{$tags}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 7 | my %regions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | my @stack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 7 | my @lines = split /\n/, $text, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 7 | for my $line (@lines) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 70 | ▶ | if ($line =~ /^tag::([A-Za-z0-9_.:-]+)\[\]$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 14 | my $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if (grep { $_ eq $name } @stack) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return _selector_error('nested same-name tag not supported', $ctx->{include}{on_bad_selector}, $state, $line_no); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 14 | push @stack, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 14 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 56 | ▶ | if ($line =~ /^end::([A-Za-z0-9_.:-]+)\[\]$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 14 | my $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 14 | ▶ | if (!@stack || $stack[-1] ne $name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @stack or $stack[-1] ne $name
MC/DC0%0/2
not @stack or $stack[-1] ne $name
not @stack
$stack[-1] ne $name
Truth table33%1/3
not(A) or B
A= not @stackB= $stack[-1] ne $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return _selector_error("mismatched tag terminator '$name'", $ctx->{include}{on_bad_selector}, $state, $line_no); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 14 | pop @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 14 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 42 | for my $name (@stack) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 28 | push @{$regions{$name}}, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 7 | ▶ | if (@stack) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return _selector_error('unclosed tag region', $ctx->{include}{on_bad_selector}, $state, $line_no); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 7 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 7 | for my $name (@{$tags}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 8 | ▶ | if (!exists $regions{$name}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 4 | return _selector_error("missing tag '$name'", $ctx->{include}{on_missing_tag}, $state, $line_no); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | push @out, @{$regions{$name}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | return (1, join("\n", @out), ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | sub _filter_by_lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filter_by_lines: called CC=11 SCAR=24.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 6 | my ($text, $expr, $ctx, $state, $line_no) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 6 | my @lines = split /\n/, $text, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 6 | my @picked; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 6 | for my $range (split /;/, $expr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 6 | $range =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 6 | ▶ | next if $range eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 6 | ▶ | if ($range !~ /^(-?\d*)\.\.(-?\d*)$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | return _selector_error("invalid lines selector '$range'", $ctx->{include}{on_bad_selector}, $state, $line_no); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 4 | my ($s, $e) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | ▶ | my $start = ($s eq '') ? 1 : int($s); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 4 | ▶ | my $end = ($e eq '') ? scalar(@lines) : int($e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 4 | ▶ | $end = scalar(@lines) if $end == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 4 | ▶ | $start = 1 if $start < 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 4 | ▶ | $end = scalar(@lines) if $end > scalar(@lines); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | ▶ | next if $start > $end; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 4 | for my $i ($start .. $end) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 11 | push @picked, $lines[$i - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 4 | return (1, join("\n", @picked), ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | sub _selector_error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_selector_error: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 6 | my ($msg, $policy, $state, $line_no) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 6 | ▶ | if ($policy eq 'keep') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 3 | return (0, $msg, 'keep'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | ▶ | if ($policy eq 'drop') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | return (0, $msg, 'drop'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | return (0, $msg . ' at ' . _where($state->{source_path}, $line_no), 'error'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | sub _resolve_target | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 23 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_target: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 23 | my ($target, $source_path, $base_dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 23 | ▶ | return abs_path($target) if File::Spec->file_name_is_absolute($target); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 23 | ▶ | my $dir = defined($source_path) ? dirname($source_path) : $base_dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 23 | my $path = File::Spec->catfile($dir, $target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 23 | ▶ | return abs_path($path) || $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
abs_path($path) || $path
MC/DC0%0/2
abs_path($path) || $path
abs_path($path)
$path
Truth table33%1/3
A || B
A= abs_path($path)B= $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | sub _read_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 19 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_file: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 19 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 19 | ▶ | open my $fh, '<:encoding(UTF-8)', $path or die "cannot read include file '$path': $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 19 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 19 | my $content = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 19 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 19 | ▶ | return defined($content) ? $content : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | sub _is_under_base | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_under_base: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my ($path, $base) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | my $p = abs_path($path) || $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
abs_path($path) || $path
MC/DC0%0/2
abs_path($path) || $path
abs_path($path)
$path
Truth table0%0/3
A || B
A= abs_path($path)B= $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | my $b = abs_path($base) || $base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
abs_path($base) || $base
MC/DC0%0/2
abs_path($base) || $base
abs_path($base)
$base
Truth table0%0/3
A || B
A= abs_path($base)B= $base
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | return index($p, $b) == 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | sub _where | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_where: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 5 | my ($source_path, $line_no) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 5 | ▶ | $line_no ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$line_no ||= 0
MC/DC100%1/1
$line_no ||= 0
$line_no
Truth table100%2/2
A
A= $line_no
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 5 | ▶ | return (defined($source_path) ? $source_path : '<input>') . ($line_no ? ':' . $line_no : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 18 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||