blib/lib/LaTeX/Replicase.pm

filter: Statementstmt 96.8% 1132 / 1169 Branchbran 92.2% 781 / 848 (5 uncoverable) Conditioncond 87.4% 500 / 572 MC/DCmcdc 76.0% 235 / 309 Subroutinesub 100% 31 / 31 Podpod 100% 7 / 7 totaltotal 91.5% 2686 / 2936 (5 uncoverable) CC 659 SCAR 43.7
CC
659
Cov
93%
onecell
146.0
_replisome
111.6
replication
98.7
CRAP 79.3
↑ Summary
1 package LaTeX::Replicase;
2  
3 7 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # no warnings 'numeric';
7 7 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 ▶use File::ShareDir qw(module_file); # dist_file
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use File::Basename qw(fileparse);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use File::Compare;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use Storable qw(retrieve);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 # use Data::Dumper;
16  
17 7 require Exporter;
18  
19 7 our @ISA = qw(Exporter);
20  
21 7 our %EXPORT_TAGS = ('all' => [ qw(
22 replication
23 tex_escape
24 REase
25 AGLkit
26 font_metrics
27 onecell
28 multicell
29 ) ],
30 );
31  
32 7 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
33 7 our @EXPORT = qw( );
34  
35 7 our $VERSION = '0.815';
36 7 our $DEBUG = 0;
37  
38 7 our $qs = qr/^|_|\b/o;
39 7 our $qe = qr/_|\b|$/o;
40  
41 7 our $q = qr!\\hskip0pt +plus *0?.02em\\/!o;
42 7 our $glue = '\\hskip0pt plus.02em\\/';
43  
44 # '!'=>\x21 '"'=>\x22 '#'=>\x23 '$'=>\x24 '%'=>\x25 '&'=>\x26 "'"=>\x27
45 # '('=>\x28 ')'=>\x29 '*'=>\x2A '+'=>\x2B ','=>\x2C '-'=>\x2D '.'=>\x2E '/'=>\x2F
46 # ---
47 # ':'=>\x3A ';'=>\x3B '<'=>\x3C '='=>\x3D '>'=>\x3E '?'=>\x3F '@'=>\x40
48 # ---
49 # '['=>\x5B '\'=>\x5C ']'=>\x5D '^'=>\x5E '_'=>\x5F '`'=>\x60
50 # ---
51 # '{'=>\x7B '|'=>\x7C '}'=>\x7D '~'=>\x7E
52 7 our $sI = qr/[\s\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]/o;
53 7 our $sII = qr/[a-zA-Z0-9,=:;!\>\<\)\(\/.\s\+\-*?]+/o;
54 7 our $sVII = qr/[%&}{_#\$]/o;
55 7 our $sCLS = qr/[\$\t%&}{\-*\/=._\^~#'`"]/o;
56 7 our $sACT = qr/[\$\t%&}{\-*\/=._\^~#'`",;!\>]/o;
57  
58 # font sizes, depending on the document's base font size (pt), see \documentclass[...pt]
59 7 our $fontSizeTeX = {
60 names => {tiny=>0, scriptsize=>1, footnotesize=>2, small=>3, normalsize=>4, large=>5, Large=>6, LARGE=>7, huge=>8, Huge=>9},
61 classic => {
62 # 0 1 2 3 [4] 5 6 7 8 9
63 10 => [5, 7, 8, 9, 10, 12, 14.4, 17.28, 20.74, 24.88],
64 11 => [6, 8, 9, 10, 10.95, 12, 14.4, 17.28, 20.74, 24.88],
65 12 => [6, 8, 10, 10.95, 12, 14.4, 17.28, 20.74, 24.88, 24.88],
66 },
67 extsizes => {
68 # 0 1 2 3 [4] 5 6 7 8 9
69 8 => [5, 6, 7, 7.6, 8, 9, 10, 10.95, 12, 14.4 ],
70 9 => [5, 6, 7, 8, 9, 10, 10.95, 12, 14.4, 17.28],
71 14 => [8, 10, 10.95, 12, 14.4, 17.28, 20.74, 24.88, 24.88, 29.86],
72 17 => [10, 12, 14.4, 14.4, 17.28, 20.74, 24.88, 29.86, 29.86, 35.83],
73 20 => [12, 14.4, 17.28, 17.28, 20.74, 24.88, 29.86, 35.83, 35.83, 43 ],
74 },
75  
76 };
77  
78 7 ▶while( my( $k, $v ) = each %{ $fontSizeTeX->{classic} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$LaTeX::Replicase::fontSizeTeX{"classic"};}) 21 7 28
79 21 $fontSizeTeX->{extsizes}{$k} = $v;
80 }
81  
82 7 our $refHypMsk = {
83 en => qr/[a-zA-Z\-]+/o,
84 ru => qr/[а-яёА-ЯЁ\-]+/o,
85 };
86  
87 #-------------------
88 # External functions
89 #-------------------
90  
91 # Masks (or replaces with equivalents) the active 9 TeX characters: &, %, $, #, _, {, }, ^, \
92 # with additionally replace character '~'
93 # INPUT:
94 # $_[0] string
95 # $_[1] HASH of options (only need 'esc' key) / SCALAR string with additional substitutions: '~_%_s_REase_'
96 # OUTPUT (and $_[1]->{mflag} if $_[1] is 'HASH'):
97 # 0 -- value NOT changed
98 # 1 -- value changed
99  
100 107 ▶sub tex_escape {
Subroutine tex_escape: called CC=49 SCAR=38.9
Pod documented
101 107 ▶ $_[0] or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] or return 0 105 2 107
102  
103 105 our( $qs, $qe, $sI, $sII, $sVII, $sCLS, $sACT );
104  
105 105 my $opH = ref $_[1] eq 'HASH';
106 105 my $mflag = 0;
107 105 my $prm = '';
108  
109 105 ▶ if( $opH ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opH) { } 44 61 105
elsif (ref \$_[1] eq 'SCALAR') { } 60 1 61
110  
111 44 ▶ if( $_[1]->{_MFLAGS_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1]{"_MFLAGS_"}) 5 39 44
112 5 ▶ return 0 if $_[1]->{_MFLAGS_} & 0b0100; # SUPPER critical changes in TeX-commands before
Branch: 1 branch
BranchTrueFalseTotal
if $_[1]{"_MFLAGS_"} & 4 1 4 5
113 4 ▶ goto _tex_escape_to_REase if $_[1]->{_MFLAGS_} & 0b0010; # critical changes in TeX-commands before
Branch: 1 branch
BranchTrueFalseTotal
if $_[1]{"_MFLAGS_"} & 2 3 1 4
114 }
115  
116 40 ▶ $prm = $_[1]->{esc} // '';
Condition100%2/2
$_[1]{"esc"} // ""
l!l
346
MC/DC100%1/1
$_[1]{"esc"} // ""
$_[1]{"esc"}
Truth table100%2/2
A
A= $_[1]{"esc"}
Aresult
11
00
117 }
118 elsif( ref \$_[1] eq 'SCALAR') {
119 60 ▶ $prm = $_[1] // '';
Condition100%2/2
$_[1] // ""
l!l
3822
MC/DC100%1/1
$_[1] // ""
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
120 }
121  
122 101 ▶ goto _tex_escape_to_REase if $_[0] =~/\A${sII}\Z/m;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /\A$LaTeX::Replicase::sII\Z/m 19 82 101
123  
124 82 my $stag = ''; # start tag
125  
126 82 ▶ if( $_[0] =~/\A%%%:/ and $prm !~/!stag(?:$qe)/) { # SKIP start tag
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /\A%%%:/ and not $prm =~ /!stag(?:$LaTeX::Replicase::qe)/) 12 70 82
Condition100%3/3
$_[0] =~ /\A%%%:/ and not $prm =~ /!stag(?:$LaTeX::Replicase::qe)/
!ll&&!rl&&r
63712
MC/DC100%2/2
$_[0] =~ /\A%%%:/ and not $prm =~ /!stag(?:$LaTeX::Replicase::qe)/
$_[0] =~ /\A%%%:/ not $prm =~ /!stag(?:$LaTeX::Replicase::qe)/
Truth table100%3/3
A and not(B)
A= $_[0] =~ /\A%%%:/B= not $prm =~ /!stag(?:$LaTeX::Replicase::qe)/
ABresult
0X0
100
111
127  
128 12 ▶ if( $prm =~/\-stag(?:$qe)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($prm =~ /\-stag(?:$LaTeX::Replicase::qe)/) { } 2 10 12
elsif ($prm =~ /\+stag(?:$LaTeX::Replicase::qe)/) { } 8 2 10
129 2 $_[0] =~s/\A(%%%:)+//m; # remove ALL start tag(s)
130 2 my $s = $1;
131 2 ▶ $stag = $s if $prm =~/\+stag(?:$qe)/;
Branch: 1 branch
BranchTrueFalseTotal
if $prm =~ /\+stag(?:$LaTeX::Replicase::qe)/ 1 1 2
132 2 $mflag |= 0b0001; # simple text changes
133 }
134 elsif( $prm =~/\+stag(?:$qe)/) { # save start tag '%%%:'
135 8 ▶ return $mflag if $prm !~/(?:$qs)REase(?:$qe)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $prm =~ /(?:$LaTeX::Replicase::qs)REase(?:$LaTeX::Replicase::qe)/ 7 1 8
136  
137 1 goto _tex_escape_to_REase;
138 }
139 else {
140 2 $_[0] =~s/\A%%%://m; # remove 1 start tag
141 2 $mflag |= 0b0001; # simple text changes
142 2 goto _tex_escape_to_REase;
143 }
144  
145 }
146  
147 72 ▶ if( $_[0] =~/\\/ ) { # check '\' symbol
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /\\/) { } 22 50 72
148  
149 22 my @arr = split /\\/, $_[0], -1;
150  
151 22 my $yes = 0;
152 22 my $z;
153 my $i;
154 22 foreach( @arr ) {
155 230 $z = length;
156 230 my $offset = 0;
157  
158 230 ▶ if( ++$i > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (++$i > 1) { } 208 22 230
elsif (not $z) { } 17 5 22
159  
160 208 ▶ if( ! $z ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($z) 17 191 208
161 17 $_ = 'char92\\/';
162 17 next;
163 }
164  
165 191 ▶ next if /^char92(?:\D|$)/ or /^textbackslash(?:[^a-zA-Z]|$)/
Branch: 1 branch
BranchTrueFalseTotal
if /^char92(?:\D|$)/ or /^textbackslash(?:[^a-zA-Z]|$)/ or /^relax(?:[^a-zA-Z]|$)/ or /^hskip\s*\d/ 25 166 191
Condition100%9/9
/^char92(?:\D|$)/ or /^textbackslash(?:[^a-zA-Z]|$)/ or /^relax(?:[^a-zA-Z]|$)/ or /^hskip\s*\d/
l!l&&r!l&&!r
205166
/^char92(?:\D|$)/ or /^textbackslash(?:[^a-zA-Z]|$)/ or /^relax(?:[^a-zA-Z]|$)/
l!l&&r!l&&!r
137171
/^char92(?:\D|$)/ or /^textbackslash(?:[^a-zA-Z]|$)/
l!l&&r!l&&!r
85178
MC/DC100%4/4
/^char92(?:\D|$)/ or /^textbackslash(?:[^a-zA-Z]|$)/ or /^relax(?:[^a-zA-Z]|$)/ or /^hskip\s*\d/
/^char92(?:\D|$)/ /^textbackslash(?:[^a-zA-Z]|$)/ /^relax(?:[^a-zA-Z]|$)/ /^hskip\s*\d/
Truth table100%5/5
A or B or C or D
A= /^char92(?:\D|$)/B= /^textbackslash(?:[^a-zA-Z]|$)/C= /^relax(?:[^a-zA-Z]|$)/D= /^hskip\s*\d/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
166 or /^relax(?:[^a-zA-Z]|$)/
167 or /^hskip\s*\d/;
168  
169 166 ▶ if( $prm !~/(?:$qs)strong(?:$qe)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prm =~ /(?:$LaTeX::Replicase::qs)strong(?:$LaTeX::Replicase::qe)/) 142 24 166
170 142 ▶ if( $prm =~/(?:$qs)mutual(?:$qe)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($prm =~ /(?:$LaTeX::Replicase::qs)mutual(?:$LaTeX::Replicase::qe)/) { } 24 118 142
elsif (/^$LaTeX::Replicase::sACT/) { } 105 13 118
171 24 ▶ if( /^$sCLS/ ) { # classic active TeX & LaTeX symbols, but without '\<space>' command
Branch: 1 branch
BranchTrueFalseTotal
if (/^$LaTeX::Replicase::sCLS/) 18 6 24
172 18 ▶ next if $z < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $z < 2 1 17 18
173 17 $offset = 1;
174 }
175 }
176 elsif( /^$sACT/ ) { # active symbols allowed in LaTeX
177 105 ▶ next if $z < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $z < 2 32 73 105
178 73 $offset = 1;
179 }
180 }
181  
182 133 ▶ if( ! $offset ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($offset) 43 90 133
183 43 ▶ my $bs = 'char92'.(/^$sI/ ? '':'\\/');
Branch: 1 branch
BranchTrueFalseTotal
/^$LaTeX::Replicase::sI/ ? : 31 12 43
184 43 $_ = $bs . $_;
185 43 $offset = length $bs;
186 }
187  
188 }
189 elsif( ! $z ) {
190 17 next;
191 }
192  
193 # masking active symbols
194 138 ▶ if( ! $offset ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $offset) { } 5 133 138
195 5 s/$sVII/\\$&/g;
196 5 s|\^|\\^\\/|g; # ^ --> \^\/
197 5 ▶ s|~|\\~\\/|g if $prm =~/~/; # tilde (~) --> \~\/
Branch: 1 branch
BranchTrueFalseTotal
if $prm =~ /~/ 3 2 5
198  
199 5 ▶ if( $prm =~/(?:$qs)hyphen(?:$qe)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prm =~ /(?:$LaTeX::Replicase::qs)hyphen(?:$LaTeX::Replicase::qe)/) 3 2 5
200 3 s/(?<=[[:alpha:]])\-(?=[[:alpha:]])/"=/gi; #"# make compound words with 'active' hyphens
201 }
202 }
203 # elsif( $offset < length )
204 else {
205 133 substr( $_, $offset ) =~s/$sVII/\\$&/g;
206 133 substr( $_, $offset ) =~s|\^|\\^\\/|g; # ^ --> \^\/
207 133 ▶ substr( $_, $offset ) =~s|~|\\~\\/|g if $prm =~/~/; # tilde (~) --> \~\/
Branch: 1 branch
BranchTrueFalseTotal
if $prm =~ /~/ 127 6 133
208  
209 133 ▶ if( $prm =~/(?:$qs)hyphen(?:$qe)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prm =~ /(?:$LaTeX::Replicase::qs)hyphen(?:$LaTeX::Replicase::qe)/) 9 124 133
210 9 substr( $_, $offset ) =~s/(?<=[[:alpha:]])\-(?=[[:alpha:]])/"=/gi; #"# make compound words with 'active' hyphens
211 }
212 }
213  
214 }
215 continue {
216 230 ▶ if( $z != length ) { # critical changes for TeX-commands
Branch: 1 branch
BranchTrueFalseTotal
if ($z != length $_) 71 159 230
217 71 ▶ $yes ||= 1;
Condition100%2/2
$yes ||= 1
l!l
6011
MC/DC100%1/1
$yes ||= 1
$yes
Truth table100%2/2
A
A= $yes
Aresult
11
00
218 71 $mflag |= 0b0010;
219 }
220 }
221  
222 22 ▶ if( $yes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yes) 11 11 22
223 11 $_[0] = join '\\', @arr;
224 11 $_[0] =~s|(?<![~\^])\\/(?=\\)||g; # '\/\' --> '\'
225 }
226  
227 }
228 else {
229  
230 50 for( $_[0] ) {
231 50 my $z = length;
232  
233 50 s/[%}{_&#\$]/\\$&/g; # masking active symbols
234 50 s|\^|\\^\\/|g; # ^ --> \^\/
235  
236 50 ▶ if( $prm =~/~/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prm =~ /~/) 20 30 50
237 20 s|~|\\~\\/|g; # tilde (~) --> \~\/
238 }
239  
240 50 ▶ if( $prm =~/(?:$qs)hyphen(?:$qe)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prm =~ /(?:$LaTeX::Replicase::qs)hyphen(?:$LaTeX::Replicase::qe)/) 7 43 50
241 7 s/(?<=[[:alpha:]])\-(?=[[:alpha:]])/"=/gi; #"# make compound words with 'active' hyphens
242 }
243  
244 50 s|(?<![~\^])\\/(?=\\)||g; # '\/\' --> '\'
245  
246 50 ▶ $mflag |= 0b0010 if $z != length; # critical changes for TeX-commands
Branch: 1 branch
BranchTrueFalseTotal
if $z != length $_ 39 11 50
247 }
248  
249 }
250  
251 72 ▶ $_[0] = $stag . $_[0] if $stag; # add start tag
Branch: 1 branch
BranchTrueFalseTotal
if $stag 1 71 72
252  
253 _tex_escape_to_REase:
254  
255 97 ▶ if( $prm =~/(?:$qs)REase(?:$qe)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prm =~ /(?:$LaTeX::Replicase::qs)REase(?:$LaTeX::Replicase::qe)/) 12 85 97
256 12 ▶ if( $opH ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opH) { } 4 8 12
257 4 $_[1]->{_MFLAGS_} += 0;
258 4 $_[1]->{_MFLAGS_} |= $mflag;
259  
260 4 $mflag |= &REase;
261 }
262 else {
263 8 $mflag |= &REase( $_[0], { _MFLAGS_ => $mflag, esc => $prm } );
264 }
265  
266 }
267  
268  
269 97 ▶ return $mflag if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 93 4 97
270 }
271  
272 # REstrictase
273 # INPUT:
274 # $_[0] string
275 # $_[1] HASH of options
276 # OUTPUT:
277 # 0 -- value NOT changed
278 # 1 -- value changed
279 70 ▶sub REase {
Subroutine REase: called CC=26 SCAR=32.6
Pod documented
280 70 ▶ $_[0] or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] or return 0 67 3 70
281  
282 67 our( $qs, $qe, $q, $glue, $sI );
283  
284 67 my $opH = ref $_[1] eq 'HASH';
285  
286 67 my $prm = '';
287 67 my $n = 3; # size of tile, by default
288  
289 67 ▶ if( $opH ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opH) { } 48 19 67
elsif (ref \$_[1] eq 'SCALAR') { } 17 2 19
290 48 ▶ return 0 if $_[1]->{_MFLAGS_} and $_[1]->{_MFLAGS_} & 0b0100; # there were super critical changes in TeX-commands before
Branch: 1 branch
BranchTrueFalseTotal
if $_[1]{"_MFLAGS_"} and $_[1]{"_MFLAGS_"} & 4 1 47 48
Condition100%3/3
$_[1]{"_MFLAGS_"} and $_[1]{"_MFLAGS_"} & 4
!ll&&!rl&&r
27201
MC/DC100%2/2
$_[1]{"_MFLAGS_"} and $_[1]{"_MFLAGS_"} & 4
$_[1]{"_MFLAGS_"} $_[1]{"_MFLAGS_"} & 4
Truth table100%3/3
A and B
A= $_[1]{"_MFLAGS_"}B= $_[1]{"_MFLAGS_"} & 4
ABresult
0X0
100
111
291  
292 47 ▶ $prm = $_[1]->{esc} // '';
Condition100%2/2
$_[1]{"esc"} // ""
l!l
3215
MC/DC100%1/1
$_[1]{"esc"} // ""
$_[1]{"esc"}
Truth table100%2/2
A
A= $_[1]{"esc"}
Aresult
11
00
293 47 ▶ $n = $& if $_[1]->{tile} and $_[1]->{tile} =~/[2-9]/; # 2..9
Branch: 1 branch
BranchTrueFalseTotal
if $_[1]{"tile"} and $_[1]{"tile"} =~ /[2-9]/ 9 38 47
Condition100%3/3
$_[1]{"tile"} and $_[1]{"tile"} =~ /[2-9]/
!ll&&!rl&&r
3719
MC/DC100%2/2
$_[1]{"tile"} and $_[1]{"tile"} =~ /[2-9]/
$_[1]{"tile"} $_[1]{"tile"} =~ /[2-9]/
Truth table100%3/3
A and B
A= $_[1]{"tile"}B= $_[1]{"tile"} =~ /[2-9]/
ABresult
0X0
100
111
294 }
295 elsif( ref \$_[1] eq 'SCALAR') {
296 17 ▶ $prm = $_[1] // '';
Condition100%2/2
$_[1] // ""
l!l
215
MC/DC100%1/1
$_[1] // ""
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
297 }
298  
299 66 my $mflag = 0;
300  
301 66 ▶ if( $_[0] =~/^%%%:/ and $prm !~/!stag(?:$qe)/) { # SKIP start tag
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^%%%:/ and not $prm =~ /!stag(?:$LaTeX::Replicase::qe)/) 3 63 66
Condition100%3/3
$_[0] =~ /^%%%:/ and not $prm =~ /!stag(?:$LaTeX::Replicase::qe)/
!ll&&!rl&&r
6123
MC/DC100%2/2
$_[0] =~ /^%%%:/ and not $prm =~ /!stag(?:$LaTeX::Replicase::qe)/
$_[0] =~ /^%%%:/ not $prm =~ /!stag(?:$LaTeX::Replicase::qe)/
Truth table100%3/3
A and not(B)
A= $_[0] =~ /^%%%:/B= not $prm =~ /!stag(?:$LaTeX::Replicase::qe)/
ABresult
0X0
100
111
302  
303 3 ▶ if( $prm =~/\-stag(?:$qe)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prm =~ /\-stag(?:$LaTeX::Replicase::qe)/) { } 1 2 3
304 1 $_[0] =~s/^(%%%:)+//; # remove ALL start tags
305 1 $mflag |= 0b0001; # simple text changes (without TeX-commands)
306 }
307 else {
308 2 $_[0] =~s/^%%%://; # remove 1 start tag only
309 2 return 0b0001;
310 }
311 }
312  
313 64 ▶ return 0 if $_[0] =~/\\relax\\\/$/ # exists etag
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ m[\\relax\\/$] or $_[0] =~ /^(?:%%%:)?$LaTeX::Replicase::q/ or length $_[0] < $n + 2 32 32 64
Condition100%6/6
$_[0] =~ m[\\relax\\/$] or $_[0] =~ /^(?:%%%:)?$LaTeX::Replicase::q/ or length $_[0] < $n + 2
l!l&&r!l&&!r
32932
$_[0] =~ m[\\relax\\/$] or $_[0] =~ /^(?:%%%:)?$LaTeX::Replicase::q/
l!l&&r!l&&!r
2161
MC/DC100%3/3
$_[0] =~ m[\\relax\\/$] or $_[0] =~ /^(?:%%%:)?$LaTeX::Replicase::q/ or length $_[0] < $n + 2
$_[0] =~ m[\\relax\\/$] $_[0] =~ /^(?:%%%:)?$LaTeX::Replicase::q/ length $_[0] < $n + 2
Truth table100%4/4
A or B or C
A= $_[0] =~ m[\\relax\\/$]B= $_[0] =~ /^(?:%%%:)?$LaTeX::Replicase::q/C= length $_[0] < $n + 2
ABCresult
1XX1
01X1
0011
0000
314 or $_[0] =~/^(?:%%%:)?$q/ # protection against reuse
315 or length( $_[0] ) < $n + 2;
316  
317 32 my @arr = split /\s+/, $_[0], -1;
318  
319 32 ▶ my $stag = ($arr[0] =~s/^%%%://) ? $& : ''; # start tag
Branch: 1 branch
BranchTrueFalseTotal
$arr[0] =~ s/^%%%:// ? : 2 30 32
320 32 ▶ my $etag = ($_[0] =~/\s+$/) ? $& : ''; # end tag
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /\s+$/ ? : 2 30 32
321  
322 32 for( @arr ) {
323 51 ▶ next if $n + 2 > length
Branch: 1 branch
BranchTrueFalseTotal
if $n + 2 > length $_ or /^\p{Alpha}+$/ 15 36 51
Condition100%3/3
$n + 2 > length $_ or /^\p{Alpha}+$/
l!l&&r!l&&!r
12336
MC/DC100%2/2
$n + 2 > length $_ or /^\p{Alpha}+$/
$n + 2 > length $_ /^\p{Alpha}+$/
Truth table100%3/3
A or B
A= $n + 2 > length $_B= /^\p{Alpha}+$/
ABresult
1X1
011
000
324 or /^\p{Alpha}+$/;
325  
326 36 my $z = $_;
327  
328 36 s/(?:(?<b>.{2,$n}[^\x5C])|(?<b>[^\x5C]|\b))(?<s>[^\x5C\p{Alpha}\.><\}\{'`=_\"-])(?(1)|(?=\p{Alpha}))/$+{b}$glue$+{s}$glue/g; #'
329  
330 36 s/-{1,3}/$glue$&$glue/g; # don't touch the em dash
331 36 s/\<{1,2}/$glue$&/g;
332 36 s/\>{1,2}/$&$glue/g;
333  
334 # removal of excess glue:
335 36 s/(?<=[\(\[\{«])(?:$q)+(?=[[:alnum:]])//g; # after the opening parenthesis
336 36 s/(?<=[[:alnum:]])(?:$q)+(?=[\)\]\}»])//g; # before the closing parenthesis
337  
338 36 s/(?<=\p{Alpha})(?:$q)+([,\.:!;])/$1$glue/g; # permutation for these symbols
339  
340 # final removal of excess glue:
341 36 s/^(?:\s*$q\s*)+|(?:$q\s*)+$//g; # start & end glue
342 36 s/\x5C(?:$q)+/\\/g; # JIC: glue after '\'
343  
344 36 ▶ s|(?<=\\char)(?:$q)?9(?:$q)?2(${sI}?)|'92'.$1//'\\/'|eg; # restore '/'
Condition50%1/2
'92' . $1 // "\\/"
l!l
130
MC/DC0%0/1
'92' . $1 // "\\/"
'92' . $1
Truth table50%1/2
A
A= '92' . $1
Aresult
11
00
345  
346 # delete an extra:
347 36 s|(?<=\\char92)($q)\\/|$1|g; # remove '\/'
348 36 s|(?<=\\char92)\\(?!$q)/|$glue|g; # '\/' --> glue
349 36 s|(?<=\x5C\^)($q)\\/|$1|g; # '\^\/'
350 36 s|(?<=\\~)($q)\\/|$1|g; # '\~\/'
351 36 s/(?:$q){2,}/$glue/g;
352  
353 36 ▶ $mflag |= 0b0111 if $z ne $_;
Branch: 1 branch
BranchTrueFalseTotal
if $z ne $_ 34 2 36
354 }
355  
356 32 ▶ if( $mflag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mflag) 31 1 32
357 31 $arr[0] = $stag . $glue . $arr[0];
358 31 $_[0] = join ' ', @arr;
359 31 ▶ $_[0] =~s/ +$/$etag/ if $etag;
Branch: 1 branch
BranchTrueFalseTotal
if $etag 1 30 31
360 }
361  
362 32 ▶ return $mflag if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 31 1 32
363 }
364  
365  
366 40 ▶sub replication {
Subroutine replication: called CC=85 SCAR=45.9
Pod documented
367 40 my( $source, $info, %op ) = @_;
368  
369 40 our $DEBUG;
370 40 ▶ $op{debug} //= $DEBUG;
Condition66%2/3
$op{"debug"} //= $LaTeX::Replicase::DEBUG
l!l&&r!l&&!r
3280
MC/DC0%0/2
$op{"debug"} //= $LaTeX::Replicase::DEBUG
$op{"debug"} $LaTeX::Replicase::DEBUG
Truth table66%2/3
A //= B
A= $op{"debug"}B= $LaTeX::Replicase::DEBUG
ABresult
1X1
011
000
371  
372 40 our( $qs, $qe, $sI, $sII );
373  
374 40 my $rstype = ref \$source;
375 40 my $stype = ref $source;
376  
377 40 my @logs;
378  
379 40 ▶ if( defined( $source ) && length( $source ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source and length $source) { } 38 2 40
Condition100%3/3
defined $source and length $source
!ll&&!rl&&r
1138
MC/DC100%2/2
defined $source and length $source
defined $source length $source
Truth table100%3/3
A and B
A= defined $sourceB= length $source
ABresult
0X0
100
111
380  
381 38 ▶ if( $rstype eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if ($rstype eq 'SCALAR') { } 33 5 38
elsif ($stype ne 'ARRAY') { } 1 4 5
382 33 for( $source ) {
383 33 s/^\s+//;
384 33 s/\s+.*//s;
385  
386 7 ▶ $_ = (glob)[0] if $^O =~/(?:linux|bsd|darwin|solaris|sunos)/;
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /(?:linux|bsd|darwin|solaris|sunos)/ 32 1 33
387 }
388 }
389 elsif( $stype ne 'ARRAY') {
390 1 $_ = "!!! ERROR#6: invalid FILE or ARRAY input!";
391 1 ▶ $op{silent} or carp $_;
Branch: 1 branch
BranchTrueFalseTotal
$op{"silent"} or carp($_) 1 0 1
392  
393 1 push @logs, $_;
394 1 return \@logs;
395 }
396  
397 }
398 else {
399 2 $_ = "!!! ERROR#0: undefined input FILE or ARRAY!";
400 # uncoverable branch true
401 2 ▶ $op{silent} or carp $_;
Branch: 1 branch
BranchTrueFalseTotal
$op{"silent"} or carp($_) 2 0 2
402  
403 2 push @logs, $_;
404 2 return \@logs;
405 }
406  
407 37 ▶push @logs, "--> Checking source data: '$source'" if $op{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op{"debug"} 4 33 37
408  
409 37 ▶ if(( $rstype eq 'SCALAR' and ! -s $source) or ( $stype eq 'ARRAY' and ! @$source)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rstype eq "SCALAR" and not -s $source or $stype eq "ARRAY" and not @$source) 1 36 37
Condition77%7/9
$rstype eq "SCALAR" and not -s $source or $stype eq "ARRAY" and not @$source
l!l&&r!l&&!r
1036
$rstype eq "SCALAR" and not -s $source
!ll&&!rl&&r
4321
$stype eq "ARRAY" and not @$source
!ll&&!rl&&r
3240
MC/DC50%2/4
$rstype eq "SCALAR" and not -s $source or $stype eq "ARRAY" and not @$source
$rstype eq "SCALAR" not -s $source $stype eq "ARRAY" not @$source
Truth table42%3/7
A and not(B) or C and not(D)
A= $rstype eq "SCALAR"B= not -s $sourceC= $stype eq "ARRAY"D= not @$source
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
410 1 $_ = "!!! ERROR#1: source ('$source') does NOT exist or is EMPTY!";
411 # uncoverable branch true
412 1 ▶ $op{silent} or carp $_;
Branch: 1 branch
BranchTrueFalseTotal
$op{"silent"} or carp($_) 1 0 1
413  
414 1 push @logs, $_;
415 1 return \@logs;
416 }
417  
418 # global data of TeX file
419 36 my $dtype = ref $info;
420 36 ▶ unless( ( $dtype eq 'HASH' and %$info ) or ($dtype eq 'ARRAY' and @$info ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dtype eq "HASH" and %$info or $dtype eq "ARRAY" and @$info) 4 32 36
Condition100%9/9
$dtype eq "HASH" and %$info or $dtype eq "ARRAY" and @$info
l!l&&r!l&&!r
2574
$dtype eq "HASH" and %$info
!ll&&!rl&&r
10125
$dtype eq "ARRAY" and @$info
!ll&&!rl&&r
317
MC/DC100%4/4
$dtype eq "HASH" and %$info or $dtype eq "ARRAY" and @$info
$dtype eq "HASH" %$info $dtype eq "ARRAY" @$info
Truth table71%5/7
A and B or C and D
A= $dtype eq "HASH"B= %$infoC= $dtype eq "ARRAY"D= @$info
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
421 4 $_= "!!! ERROR#2: EMPTY or WRONG data!";
422 4 ▶ $op{silent} or carp $_;
Branch: 1 branch
BranchTrueFalseTotal
$op{"silent"} or carp($_) 4 0 4
423  
424 4 push @logs, $_;
425 4 return \@logs;
426 }
427  
428 # environments: global for %%%V:, %%%VAR: ; and local for %%%VAR:
429 32 my $data = my $vardata = $info;
430  
431 32 my( $filename, $dir );
432 32 ▶ if( $rstype eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rstype eq 'SCALAR') { } 28 4 32
433 28 ( $filename, $dir, my($ext)) = fileparse( $source );
434 }
435 else { # for ARRAY input
436 4 $filename = 'ready.tex';
437 4 $dir = '.';
438 }
439  
440 32 my( $fh, $ofile );
441 32 ▶ if( defined( $_ = $op{ofile} ) && length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $op{'ofile'}) and length $_) { } 29 3 32
Condition66%2/3
defined($_ = $op{"ofile"}) and length $_
!ll&&!rl&&r
3029
MC/DC50%1/2
defined($_ = $op{"ofile"}) and length $_
defined($_ = $op{"ofile"}) length $_
Truth table66%2/3
A and B
A= defined($_ = $op{"ofile"})B= length $_
ABresult
0X0
100
111
442 29 ▶ if(/::STDOUT$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/::STDOUT$/) { } 1 28 29
443 1 $fh = $ofile = $_;
444 }
445 else {
446 28 s/^\s+//;
447 28 s/\s+.*//s;
448 28 ▶ $ofile = ( $^O =~/(?:linux|bsd|darwin|solaris|sunos)/ ) ? (glob)[0] : $_;
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /(?:linux|bsd|darwin|solaris|sunos)/ ? : 27 1 28
449 }
450 }
451 else {
452 3 ▶ my $outdir = $op{outdir} // "$dir/$$"; # Target dir for ready TeX file
Condition50%1/2
$op{"outdir"} // "$dir/${$}"
l!l
30
MC/DC0%0/1
$op{"outdir"} // "$dir/${$}"
$op{"outdir"}
Truth table50%1/2
A
A= $op{"outdir"}
Aresult
11
00
453 3 ▶ if( length $outdir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $outdir) { } 2 1 3
454 2 for( $outdir ) {
455 2 s/^\s+//;
456 2 s/\s+.*//s;
457  
458 2 ▶ $_ = (glob)[0] if $^O =~/(?:linux|bsd|darwin|solaris|sunos)/;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /(?:linux|bsd|darwin|solaris|sunos)/ 2 0 2
459 }
460 }
461 else { # for $outdir = ''
462 1 $outdir = "./$$";
463 }
464  
465 3 ▶ unless( -d $outdir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $outdir) 2 1 3
466 2 make_path( $outdir, {error => \my $err} );
467  
468 # uncoverable branch true
469 2 ▶ if ($err && @$err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err and @$err) 0 2 2
Condition33%1/3
$err and @$err
!ll&&!rl&&r
020
MC/DC0%0/2
$err and @$err
$err @$err
Truth table33%1/3
A and B
A= $errB= @$err
ABresult
0X0
100
111
470  
471 0 for my $diag (@$err) {
472 0 my( $path, $message ) = %$diag;
473 0 ▶ $_ = ( $path && length( $path ) ) ?
Branch: 1 branch
BranchTrueFalseTotal
$path && length $path ? : 0 0 0
Condition0%0/3
$path and length $path
!ll&&!rl&&r
000
MC/DC0%0/2
$path and length $path
$path length $path
Truth table0%0/3
A and B
A= $pathB= length $path
ABresult
0X0
100
111
474 "!!! ERROR#7: ('$path' creation problem) $message" :
475 "!!! ERROR#8: (general error) $message";
476  
477 # uncoverable branch true
478 # uncoverable branch false
479 0 ▶ $op{silent} or carp $_;
Branch: 1 branch
BranchTrueFalseTotal
$op{"silent"} or carp($_) 0 0 0
480 0 push @logs, $_;
481 }
482  
483 0 return \@logs;
484 }
485  
486 }
487  
488 3 $ofile = "$outdir/$filename";
489 }
490  
491 32 ▶push @logs, "--> Using '$ofile' file as output" if $op{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op{"debug"} 4 28 32
492  
493 # new file must be different
494 32 ▶ if( -s $ofile and $rstype eq 'SCALAR'
Branch: 1 branch
BranchTrueFalseTotal
if (-s $ofile and $rstype eq "SCALAR" and $source eq $ofile && compare($source, $ofile) == 0 || join(",", stat $source) eq join(",", stat $ofile)) 1 31 32
Condition75%9/12
-s $ofile and $rstype eq "SCALAR" and $source eq $ofile && compare($source, $ofile) == 0 || join(",", stat $source) eq join(",", stat $ofile)
!ll&&!rl&&r
2831
-s $ofile and $rstype eq "SCALAR"
!ll&&!rl&&r
2804
$source eq $ofile and compare($source, $ofile) == 0 or join(",", stat $source) eq join(",", stat $ofile)
l!l&&r!l&&!r
103
$source eq $ofile and compare($source, $ofile) == 0
!ll&&!rl&&r
301
MC/DC40%2/5
-s $ofile and $rstype eq "SCALAR" and $source eq $ofile && compare($source, $ofile) == 0 || join(",", stat $source) eq join(",", stat $ofile)
-s $ofile $rstype eq "SCALAR" $source eq $ofile compare($source, $ofile) == 0 join(",", stat $source) eq join(",", stat $ofile)
Truth table42%3/7
A and B and C and D or E
A= -s $ofileB= $rstype eq "SCALAR"C= $source eq $ofileD= compare($source, $ofile) == 0E= join(",", stat $source) eq join(",", stat $ofile)
ABCDEresult
0XXXX0
10XXX0
110X00
111000
1111X1
110X11
111011
495 and (
496 ( $source eq $ofile and compare( $source, $ofile ) == 0 )
497 or
498 ( join(',', stat $source) eq join(',', stat $ofile) )
499 )
500 ) {
501 1 $_= "!!! ERROR#3: Input (template) & output files match. Can't overwrite template file!";
502 1 ▶ $op{silent} or carp $_;
Branch: 1 branch
BranchTrueFalseTotal
$op{"silent"} or carp($_) 1 0 1
503  
504 1 push @logs, $_;
505 1 return \@logs;
506 }
507  
508 31 my $TEMPLATE;
509 31 ▶ if( $rstype eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rstype eq "SCALAR") 27 4 31
510 27 ▶ my $mode = $op{utf8} ? ':utf8' : '';
Branch: 1 branch
BranchTrueFalseTotal
$op{'utf8'} ? : 3 24 27
511  
512 27 ▶push @logs, "--> Open '$source'" if $op{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op{"debug"} 4 23 27
513  
514 27 ▶ open $TEMPLATE, "<:raw$mode", $source or do{
Branch: 1 branch
BranchTrueFalseTotal
open $TEMPLATE, "<:raw$mode", $source or do { $_ = "!!! ERROR#4: $!"; $op{"silent"} or carp($_); push @logs, $_; return \@logs } 27 0 27
515 0 $_= "!!! ERROR#4: $!";
516 0 ▶ $op{silent} or carp $_;
Branch: 1 branch
BranchTrueFalseTotal
$op{"silent"} or carp($_) 0 0 0
517  
518 0 push @logs, $_;
519 0 return \@logs;
520 };
521 }
522  
523 31 ▶ unless( $fh ) { # it's not "::STDOUT"
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh) 30 1 31
524 30 ▶ my $mode = $op{utf8} ? ':encoding(utf8)' : '';
Branch: 1 branch
BranchTrueFalseTotal
$op{'utf8'} ? : 3 27 30
525  
526 30 ▶push @logs, "--> Open '$ofile'" if $op{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op{"debug"} 4 26 30
527  
528 30 ▶ open $fh, ">$mode", $ofile or do{
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">$mode", $ofile or do { $_ = "!!! ERROR#5: $!"; $op{"silent"} or carp($_); push @logs, $_; return \@logs } 30 0 30
529 0 $_= "!!! ERROR#5: $!";
530 0 ▶ $op{silent} or carp $_;
Branch: 1 branch
BranchTrueFalseTotal
$op{"silent"} or carp($_) 0 0 0
531  
532 0 push @logs, $_;
533 0 return \@logs;
534 };
535 }
536  
537 31 my %actions = (
538 tex_escape => \&tex_escape,
539 REase => \&REase,
540 );
541  
542 31 ▶ if( ref $op{_ACTIONS_} eq 'ARRAY' and @{ $op{_ACTIONS_} } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $op{'_ACTIONS_'} eq 'ARRAY' and @{$op{'_ACTIONS_'};}) { } 5 26 31
elsif ($op{'esc'}) { } 4 22 26
Condition100%3/3
ref $op{"_ACTIONS_"} eq "ARRAY" and @{$op{"_ACTIONS_"};}
!ll&&!rl&&r
2515
MC/DC100%2/2
ref $op{"_ACTIONS_"} eq "ARRAY" and @{$op{"_ACTIONS_"};}
ref $op{"_ACTIONS_"} eq "ARRAY" @{$op{"_ACTIONS_"};}
Truth table100%3/3
A and B
A= ref $op{"_ACTIONS_"} eq "ARRAY"B= @{$op{"_ACTIONS_"};}
ABresult
0X0
100
111
543  
544 5 my %done;
545  
546 5 for my $f ( @{ $op{_ACTIONS_} } ) { # Check subs and setup
547 27 ▶ $f or next;
Branch: 1 branch
BranchTrueFalseTotal
$f or next 22 5 27
548  
549 22 my $rftype = ref \$f;
550 22 my $ftype = ref $f;
551  
552 22 ▶ if( $rftype eq 'SCALAR') {
Branch: 3 branches
BranchTrueFalseTotal
if ($rftype eq 'SCALAR') { } 9 13 22
elsif ($ftype eq 'CODE') { } 2 11 13
elsif ($ftype eq 'HASH' and ref $f->{'_code_'} eq 'CODE') { } 9 2 11
553 9 ▶ if( exists $actions{$f} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $actions{$f}) { } 7 2 9
554  
555 7 ▶ if( exists( $done{$f} ) or exists( $done{ $actions{$f} } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $done{$f} or exists $done{$actions{$f}}) { } 4 3 7
Condition100%3/3
exists $done{$f} or exists $done{$actions{$f}}
l!l&&r!l&&!r
133
MC/DC100%2/2
exists $done{$f} or exists $done{$actions{$f}}
exists $done{$f} exists $done{$actions{$f}}
Truth table100%3/3
A or B
A= exists $done{$f}B= exists $done{$actions{$f}}
ABresult
1X1
011
000
556 4 $done{$f} = $done{ $actions{$f} } = undef;
557 4 undef $f;
558 }
559 else {
560 3 $done{$f} = $done{ $actions{$f} } = undef;
561 $f = {
562 _name_ => $f,
563 3 _code_ => $actions{$f},
564 };
565 }
566 }
567 else {
568 2 undef $f;
569 }
570 9 next;
571 }
572 elsif( $ftype eq 'CODE') {
573  
574 2 ▶ if( exists $done{$f} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $done{$f}) { } 1 1 2
575 1 undef $f;
576 }
577 else {
578 1 $done{$f} = undef;
579 1 $f = {
580 _code_ => $f,
581 };
582 }
583 2 next;
584 }
585 ▶ elsif( $ftype eq 'HASH' and ref $f->{_code_} eq 'CODE') {
Condition100%3/3
$ftype eq "HASH" and ref $f->{"_code_"} eq "CODE"
!ll&&!rl&&r
119
MC/DC100%2/2
$ftype eq "HASH" and ref $f->{"_code_"} eq "CODE"
$ftype eq "HASH" ref $f->{"_code_"} eq "CODE"
Truth table100%3/3
A and B
A= $ftype eq "HASH"B= ref $f->{"_code_"} eq "CODE"
ABresult
0X0
100
111
586  
587 9 ▶ if( exists $done{ $f->{_code_} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $done{$f->{'_code_'}}) { } 1 8 9
588 1 undef $f;
589 }
590 else {
591 8 $done{ $f->{_code_} } = undef;
592 }
593 }
594 else {
595 2 undef $f;
596 }
597  
598 }
599  
600 5 ▶ if( $op{esc} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op{"esc"}) 3 2 5
601 3 my $f = 'tex_escape';
602 3 ▶ if( ! exists $done{$f} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $done{$f}) 2 1 3
603 2 unshift @{ $op{_ACTIONS_} }, { # must be 1st if not specified
604 _name_ => $f,
605 2 _code_ => $actions{$f},
606 };
607  
608 2 $done{$f} = undef;
609 }
610  
611 3 $f = 'REase';
612 3 ▶ if( $op{esc} =~/(?:$qs)$f(?:$qe)/ and ! exists $done{$f} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op{"esc"} =~ /(?:$LaTeX::Replicase::qs)$f(?:$LaTeX::Replicase::qe)/ and not exists $done{$f}) 1 2 3
Condition100%3/3
$op{"esc"} =~ /(?:$LaTeX::Replicase::qs)$f(?:$LaTeX::Replicase::qe)/ and not exists $done{$f}
!ll&&!rl&&r
111
MC/DC100%2/2
$op{"esc"} =~ /(?:$LaTeX::Replicase::qs)$f(?:$LaTeX::Replicase::qe)/ and not exists $done{$f}
$op{"esc"} =~ /(?:$LaTeX::Replicase::qs)$f(?:$LaTeX::Replicase::qe)/ not exists $done{$f}
Truth table100%3/3
A and not(B)
A= $op{"esc"} =~ /(?:$LaTeX::Replicase::qs)$f(?:$LaTeX::Replicase::qe)/B= not exists $done{$f}
ABresult
0X0
100
111
613 1 push @{ $op{_ACTIONS_} }, { # must be last if not specified
614 _name_ => $f,
615 1 _code_ => $actions{$f},
616 };
617  
618 1 $done{$f} = undef;
619 1 $op{esc} =~s/$f//g;
620 }
621 }
622  
623 5 @{ $op{_ACTIONS_} } = grep{ defined } @{ $op{_ACTIONS_} }; # getting rid of uncertainties
624  
625 }
626 elsif( $op{esc} ) {
627 4 my $f = 'tex_escape';
628 $op{_ACTIONS_} = [
629 { # must be 1st
630 _name_ => $f,
631 4 _code_ => $actions{$f},
632 }
633 ];
634  
635 4 $f = 'REase';
636 4 ▶ if( $op{esc} =~/(?:$qs)$f(?:$qe)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op{"esc"} =~ /(?:$LaTeX::Replicase::qs)$f(?:$LaTeX::Replicase::qe)/) 1 3 4
637 1 push @{ $op{_ACTIONS_} }, { # must be last
638 _name_ => $f,
639 1 _code_ => $actions{$f},
640 };
641  
642 1 $op{esc} =~s/$f//g;
643 }
644  
645 }
646 else {
647 22 $op{_ACTIONS_} = [];
648 }
649  
650 31 $op{fh} = $fh;
651 31 $op{logs} = \@logs;
652 31 $op{nlo} = 1; # Number Line Output, start of 1
653  
654 31 my $chkVAR = 0; # check %%%VAR for ARRAY|HASH|SCALAR|REF->SCALAR type
655 31 my $key;
656 my $tdz; # flag of The Dead Zone
657 31 my @columns;
658 31 my $end = 0;
659  
660 =for comment
661 =begin comment
662 @columns:
663 [...]: -- table columns
664 [...]{...} -- descriptions (properties) of table columns:
665 {ki} -- name (key || index ) of a variable from $data->{ $key }
666 {%} -- NO \par
667 {x} -- check the eXistence of Value (or eXpanded)
668 {v} -- to paste by default text (located in template) if variable =~/^\x{001}$/
669 {p} -- to paste text on right
670 {head}[...] -- TeX strings before %%%V:
671 {tail}[...] -- TeX strings after %%%V:
672 {eX}[...] -- indices of {head} that eXcept for the first and last elements and rows of %%%VAR:
673 =end comment
674 =cut
675  
676 31 ▶ if( $TEMPLATE ) { # source is file
Branch: 1 branch
BranchTrueFalseTotal
if ($TEMPLATE) { } 27 4 31
677 27 ▶ while( my $z = <$TEMPLATE> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $z = readline $TEMPLATE)) 1373 3 1376
678  
679 1373 $end = &_replisome( $info, \$z, \$data, \$vardata, \$chkVAR, \$key, \$tdz, \@columns, \%op );
680  
681 1373 ▶ if( $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end) 24 1349 1373
682 24 ▶ print { $fh } <$TEMPLATE> if $end != 3; # %%%ENDT:
Branch: 1 branch
BranchTrueFalseTotal
if $end != 3 18 6 24
683  
684 24 last; #--> Exit template: \endinput AND \end{document}
685 }
686 1349 undef $z;
687  
688 }
689 27 close $TEMPLATE;
690 }
691 else { # source is ARRAY
692 4 for my $z ( @$source ) {
693  
694 308 ▶ if( $end ) { # %%%ENDT:
Branch: 1 branch
BranchTrueFalseTotal
if ($end) { } 4 304 308
695 4 print { $fh } $z;
696 }
697 else {
698 304 $end = &_replisome( $info, \$z, \$data, \$vardata, \$chkVAR, \$key, \$tdz, \@columns, \%op );
699  
700 304 ▶ last if $end == 3; # \endinput OR \end{document}
Branch: 1 branch
BranchTrueFalseTotal
if $end == 3 3 301 304
701 }
702 }
703 }
704  
705 31 ▶ if( ! $end and defined( $key ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $end and defined $key) 2 29 31
Condition100%3/3
not $end and defined $key
!ll&&!rl&&r
2812
MC/DC100%2/2
not $end and defined $key
not $end defined $key
Truth table100%3/3
not(A) and B
A= not $endB= defined $key
ABresult
0X0
100
111
706 2 &_var_output( $key, $vardata, \@columns, \%op );
707  
708 2 $_ = "~~> l.EOF. WARNING#1: Missing '%%%ENDx' tag for '$key'";
709 2 ▶ $op{silent} or carp $_;
Branch: 1 branch
BranchTrueFalseTotal
$op{"silent"} or carp($_) 1 1 2
710 2 push @logs, $_;
711 }
712  
713 31 ▶ $ofile =~/::STDOUT$/ or close $fh;
Branch: 1 branch
BranchTrueFalseTotal
$ofile =~ /::STDOUT$/ or close $fh 1 30 31
714  
715 31 ▶ return @logs ? \@logs : undef;
Branch: 1 branch
BranchTrueFalseTotal
@logs ? : 19 12 31
716 }
717  
718 #---------------------
719 # Internal functions
720  
721 1677 ▶sub _replisome {
Subroutine _replisome: called CC=110 SCAR=47.1
722 1677 my( $info, $z, $data, $vardata, $chkVAR, $key, $tdz, $columns, $op ) = @_;
723  
724 1677 ▶ if( defined $$key ) { # We are in VAR-structure
Branch: 2 branches
BranchTrueFalseTotal
if (defined $$key) { } 763 914 1677
elsif ($$z =~ /%%%+END(?<t>[TZ]?):/) { } 55 859 914
725  
726 763 ▶ return 0 unless $$z =~/%%%[AETV]\S*:/; # Nope control tags --> drop TeX line
Branch: 1 branch
BranchTrueFalseTotal
unless $$z =~ /%%%[AETV]\S*:/ 159 604 763
727  
728 604 my $vtype = ref $$vardata;
729  
730 604 ▶ if( $$z =~/%%%(?:END(?<t>[TZ]?)|TDZ|VAR):/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$z =~ /%%%(?:END(?<t>[TZ]?)|TDZ|VAR):/) { } 122 482 604
731 122 my $t = $+{t};
732  
733 122 my $end = &_var_output( $$key, $$vardata, $columns, $op );
734  
735 # Clear the VAR-structure for the next external VARiable
736 122 $$chkVAR = 0;
737 122 undef $$key;
738 122 @$columns = ();
739  
740 122 ▶ return $end if $end;
Branch: 1 branch
BranchTrueFalseTotal
if $end 6 116 122
741  
742 116 ▶ if( $t ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t) 13 103 116
743 13 ▶ return 1 if $t eq 'T'; # END of Template area --> output everything to the end of template without substitution
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "T" 10 3 13
744 3 undef $$tdz; # if $t eq 'Z';
745 }
746  
747 106 ▶ return 0 if $$z =~/%%%ENDZ?:/; # end of %%%VAR: tag
Branch: 1 branch
BranchTrueFalseTotal
if $$z =~ /%%%ENDZ?:/ 85 21 106
748  
749 21 ▶ if( $$z =~/%%%+TDZ:/) { # The Dead Zone
Branch: 1 branch
BranchTrueFalseTotal
if ($$z =~ /%%%+TDZ:/) 10 11 21
750 10 $$tdz = 1;
751 10 return 0;
752 }
753 }
754 else {
755 482 ▶ my $vk = $vtype eq 'HASH' ? $$vardata->{ $$key } : $$vardata->[ $$key ];
Branch: 1 branch
BranchTrueFalseTotal
$vtype eq 'HASH' ? : 467 15 482
756 482 ▶ my $sclr = (ref(\$vk) eq 'SCALAR' or ref($vk) eq 'SCALAR');
Condition100%3/3
ref \$vk eq 'SCALAR' || ref $vk eq 'SCALAR'
l!l&&r!l&&!r
336443
MC/DC100%2/2
ref \$vk eq 'SCALAR' || ref $vk eq 'SCALAR'
ref \$vk eq 'SCALAR' ref $vk eq 'SCALAR'
Truth table100%3/3
A || B
A= ref \$vk eq 'SCALAR'B= ref $vk eq 'SCALAR'
ABresult
1X1
011
000
757  
758 # Index of column in target table
759 482 ▶ my $j = ( @$columns && exists( $columns->[-1]{ki} ) ) ?
Branch: 1 branch
BranchTrueFalseTotal
@$columns && exists $columns->[-1]{'ki'} ? : 200 282 482
Condition100%3/3
@$columns and exists $columns->[-1]{"ki"}
!ll&&!rl&&r
81201200
MC/DC100%2/2
@$columns and exists $columns->[-1]{"ki"}
@$columns exists $columns->[-1]{"ki"}
Truth table100%3/3
A and B
A= @$columnsB= exists $columns->[-1]{"ki"}
ABresult
0X0
100
111
760 @$columns :
761 $#$columns; # ($#$columns // 0);
762 482 ▶ $j = 0 if $j < 0 or $sclr;
Branch: 1 branch
BranchTrueFalseTotal
if $j < 0 or $sclr 120 362 482
Condition100%3/3
$j < 0 or $sclr
l!l&&r!l&&!r
8139362
MC/DC100%2/2
$j < 0 or $sclr
$j < 0 $sclr
Truth table100%3/3
A or B
A= $j < 0B= $sclr
ABresult
1X1
011
000
763  
764 482 ▶ if( ! $sclr and $$z =~/^(.*?)\s?%%%+V:\s*(\*?)([^\s:%#\*]+)(%?)\s?(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $sclr and $$z =~ /^(.*?)\s?%%%+V:\s*(\*?)([^\s:%#\*]+)(%?)\s?(.*)/) { } 199 283 482
elsif ($$z =~ /(?<s>.+?)\s?%%%+ADD(?<t>[AEX]?):(?<p>%?)/ or $$z =~ /^\s*%%%+ADD(?<t>[AEX]?):(?<p>%?)\s?(?<s>.*?)[\r\n]*$/) { } 270 13 283
Condition100%3/3
not $sclr and $$z =~ /^(.*?)\s?%%%+V:\s*(\*?)([^\s:%#\*]+)(%?)\s?(.*)/
!ll&&!rl&&r
39244199
MC/DC100%2/2
not $sclr and $$z =~ /^(.*?)\s?%%%+V:\s*(\*?)([^\s:%#\*]+)(%?)\s?(.*)/
not $sclr $$z =~ /^(.*?)\s?%%%+V:\s*(\*?)([^\s:%#\*]+)(%?)\s?(.*)/
Truth table100%3/3
not(A) and B
A= not $sclrB= $$z =~ /^(.*?)\s?%%%+V:\s*(\*?)([^\s:%#\*]+)(%?)\s?(.*)/
ABresult
0X0
100
111
765 # the non-SCALAR V-variable is nested in a VAR-structure
766 199 my $dV = $1; # Value, by default
767 199 my $eXi = $2; # check the eXistence of Value (or eXpanded)
768 199 my $ki = $3; # name (key or index) of V-variable
769 199 my $Np = $4; # NO \par
770 199 my $paste = $5; # on right
771  
772 199 ▶ if( $$chkVAR == 0b0001
Branch: 3 branches
BranchTrueFalseTotal
if ($$chkVAR == 1 or $$chkVAR == 4 or $$chkVAR == 8) { } 84 115 199
elsif ($$chkVAR == 2) { } 62 53 115
elsif (ref $vk eq 'HASH' and exists $vk->{$ki} and ref \$vk->{$ki} eq 'SCALAR' || ref $vk->{$ki} eq 'SCALAR' || $ki eq '@' && ref $vk->{'@'} eq 'ARRAY') { } 47 12 59
Condition100%6/6
$$chkVAR == 1 or $$chkVAR == 4 or $$chkVAR == 8
l!l&&r!l&&!r
822115
$$chkVAR == 1 or $$chkVAR == 4
l!l&&r!l&&!r
5329117
MC/DC100%3/3
$$chkVAR == 1 or $$chkVAR == 4 or $$chkVAR == 8
$$chkVAR == 1 $$chkVAR == 4 $$chkVAR == 8
Truth table100%4/4
A or B or C
A= $$chkVAR == 1B= $$chkVAR == 4C= $$chkVAR == 8
ABCresult
1XX1
01X1
0011
0000
773 or $$chkVAR == 0b0100
774 or $$chkVAR == 0b01000
775 ) { # V-variable is in {HASH|ARRAY}.ARRAY or SCALAR or REF->SCALAR in regular ARRAY of VAR-structure
776  
777 84 ▶ if( $ki eq '@') {
Branch: 3 branches
BranchTrueFalseTotal
if ($ki eq '@') { } 7 77 84
elsif ($ki =~ /^\-*(\d+)$/ and $1 < @$vk || $ki < 0 && $1 == @$vk) { } 39 38 77
elsif ($ki =~ /^[\d,\-]+$/) { } 36 2 38
778 7 $ki = '0-'; # ALL elements
779 7 $columns->[$j]{ki} = $ki; # starting index (unnamed meaning)
780 }
781 ▶ elsif( $ki =~/^\-*(\d+)$/ && ($1 < @$vk or ($ki < 0 && $1 == @$vk)) ) {
Condition100%9/9
$ki =~ /^\-*(\d+)$/ and $1 < @$vk || $ki < 0 && $1 == @$vk
!ll&&!rl&&r
201839
$1 < @$vk or $ki < 0 and $1 == @$vk
l!l&&r!l&&!r
34518
$ki < 0 and $1 == @$vk
!ll&&!rl&&r
1445
MC/DC100%4/4
$ki =~ /^\-*(\d+)$/ and $1 < @$vk || $ki < 0 && $1 == @$vk
$ki =~ /^\-*(\d+)$/ $1 < @$vk $ki < 0 $1 == @$vk
Truth table100%5/5
A and B or C and D
A= $ki =~ /^\-*(\d+)$/B= $1 < @$vkC= $ki < 0D= $1 == @$vk
ABCDresult
0XXX0
100X0
10100
11XX1
10111
782 # specific indices, e.g.: 0 or 3 or -1
783 39 $columns->[$j]{ki} = $ki;
784 }
785 elsif( $ki =~/^[\d,\-]+$/) {
786 # mixed indexes, e.g.: 1-3,6-7-9,-,4,-5,0,7- or 3- (i.e. 3..arr_end) or 0-5 (0..5) or -1- (-1,-2,..arr_start)
787 36 for( $ki ) {
788 36 s/\-+/-/g;
789 36 s/,+/,/g;
790 }
791 36 $columns->[$j]{ki} = $ki;
792 }
793 else {
794 2 ▶push @{$op->{logs}}, "~~> l.$. WARNING#8: ARRAY index is not numeric in %%%V:". $ki if $op->{debug} or ! $op->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} or not $op->{"ignore"} 2 0 2
Condition66%2/3
$op->{"debug"} or not $op->{"ignore"}
l!l&&r!l&&!r
110
MC/DC0%0/2
$op->{"debug"} or not $op->{"ignore"}
$op->{"debug"} not $op->{"ignore"}
Truth table66%2/3
A or not(B)
A= $op->{"debug"}B= not $op->{"ignore"}
ABresult
1X1
011
000
795 }
796  
797 }
798 elsif( $$chkVAR == 0b0010) { # V-variable is in {HASH|ARRAY}.HASH of VAR-structure
799  
800 62 for my $d ( @$vk ) {
801 65 ▶ if( exists $d->{$ki} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $d->{$ki}) 62 3 65
802 62 $columns->[$j]{ki} = $ki; # save variable name in j-th column
803 62 last;
804 }
805 }
806 }
807 ▶ elsif( ref $vk eq 'HASH'
Condition86%13/15
ref $vk eq "HASH" and exists $vk->{$ki} and ref \$vk->{$ki} eq "SCALAR" || ref $vk->{$ki} eq "SCALAR" || $ki eq "\@" && ref $vk->{"\@"} eq "ARRAY"
!ll&&!rl&&r
4247
ref $vk eq "HASH" and exists $vk->{$ki}
!ll&&!rl&&r
0449
ref \$vk->{$ki} eq "SCALAR" or ref $vk->{$ki} eq "SCALAR" or $ki eq "\@" and ref $vk->{"\@"} eq "ARRAY"
l!l&&r!l&&!r
4432
ref \$vk->{$ki} eq "SCALAR" or ref $vk->{$ki} eq "SCALAR"
l!l&&r!l&&!r
4315
$ki eq "\@" and ref $vk->{"\@"} eq "ARRAY"
!ll&&!rl&&r
203
MC/DC66%4/6
ref $vk eq "HASH" and exists $vk->{$ki} and ref \$vk->{$ki} eq "SCALAR" || ref $vk->{$ki} eq "SCALAR" || $ki eq "\@" && ref $vk->{"\@"} eq "ARRAY"
ref $vk eq "HASH" exists $vk->{$ki} ref \$vk->{$ki} eq "SCALAR" ref $vk->{$ki} eq "SCALAR" $ki eq "\@" ref $vk->{"\@"} eq "ARRAY"
Truth table71%5/7
A and B and C or D or E and F
A= ref $vk eq "HASH"B= exists $vk->{$ki}C= ref \$vk->{$ki} eq "SCALAR"D= ref $vk->{$ki} eq "SCALAR"E= $ki eq "\@"F= ref $vk->{"\@"} eq "ARRAY"
ABCDEFresult
0XXXXX0
10XXXX0
11000X0
1100100
111XXX1
1101XX1
1100111
808 and exists( $vk->{$ki} )
809 and ( ref \$vk->{$ki} eq 'SCALAR'
810 or ref $vk->{$ki} eq 'SCALAR'
811 or ( $ki eq '@' and ref $vk->{'@'} eq 'ARRAY')
812 )
813 ) {
814 47 $columns->[$j]{ki} = $ki; # save variable key in j-th element
815 }
816  
817 199 ▶ &_set_column( $dV, $eXi, $Np, $paste, $columns->[$j] ) if exists $columns->[$j]{ki};
Branch: 1 branch
BranchTrueFalseTotal
if exists $columns->[$j]{"ki"} 191 8 199
818 }
819 ▶ elsif( $$z =~/(?<s>.+?)\s?%%%+ADD(?<t>[AEX]?):(?<p>%?)/
Condition100%3/3
$$z =~ /(?<s>.+?)\s?%%%+ADD(?<t>[AEX]?):(?<p>%?)/ or $$z =~ /^\s*%%%+ADD(?<t>[AEX]?):(?<p>%?)\s?(?<s>.*?)[\r\n]*$/
l!l&&r!l&&!r
2264413
MC/DC100%2/2
$$z =~ /(?<s>.+?)\s?%%%+ADD(?<t>[AEX]?):(?<p>%?)/ or $$z =~ /^\s*%%%+ADD(?<t>[AEX]?):(?<p>%?)\s?(?<s>.*?)[\r\n]*$/
$$z =~ /(?<s>.+?)\s?%%%+ADD(?<t>[AEX]?):(?<p>%?)/ $$z =~ /^\s*%%%+ADD(?<t>[AEX]?):(?<p>%?)\s?(?<s>.*?)[\r\n]*$/
Truth table100%3/3
A or B
A= $$z =~ /(?<s>.+?)\s?%%%+ADD(?<t>[AEX]?):(?<p>%?)/B= $$z =~ /^\s*%%%+ADD(?<t>[AEX]?):(?<p>%?)\s?(?<s>.*?)[\r\n]*$/
ABresult
1X1
011
000
820 or $$z =~/^\s*%%%+ADD(?<t>[AEX]?):(?<p>%?)\s?(?<s>.*?)[\r\n]*$/
821 ) {
822 270 my $s = $+{s};
823  
824 270 ▶ if( $+{p} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($+{'p'}) { } 59 211 270
825 59 ▶ length($s) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
length $s or return 0 58 1 59
826 }
827 else {
828 211 $s .= "\n";
829 }
830  
831 269 ▶ if( $+{t} eq 'A') { # %%%ADDA:
Branch: 2 branches
BranchTrueFalseTotal
if ($+{'t'} eq 'A') { } 5 264 269
elsif ($+{'t'} eq 'E') { } 37 227 264
832 5 push @{ $columns->[$j]{head} }, $s;
833 5 $columns->[$j]{ki} = '%%%ADDA'; # phantom
834 5 $columns->[$j]{'%'} = 1;
835 }
836 elsif( $+{t} eq 'E') { # %%%ADDE:
837 37 ▶ if( @$columns && ( $sclr or (exists( $columns->[-1]{ki} ) && ! $columns->[$j]) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$columns and $sclr || exists $columns->[-1]{'ki'} && !$columns->[$j]) { } 33 4 37
Condition88%8/9
@$columns and $sclr || exists $columns->[-1]{"ki"} && !$columns->[$j]
!ll&&!rl&&r
3133
$sclr or exists $columns->[-1]{"ki"} and not $columns->[$j]
l!l&&r!l&&!r
15181
exists $columns->[-1]{"ki"} and not $columns->[$j]
!ll&&!rl&&r
1018
MC/DC75%3/4
@$columns and $sclr || exists $columns->[-1]{"ki"} && !$columns->[$j]
@$columns $sclr exists $columns->[-1]{"ki"} not $columns->[$j]
Truth table80%4/5
A and B or C and not(D)
A= @$columnsB= $sclrC= exists $columns->[-1]{"ki"}D= not $columns->[$j]
ABCDresult
0XXX0
100X0
10100
11XX1
10111
838 33 push @{ $columns->[-1]{tail} }, $s;
839 }
840 else {
841 4 push @{ $columns->[$j]{head} }, $s;
842 }
843 }
844 else { # %%%ADD[X]:
845 227 push @{ $columns->[$j]{head} }, $s;
846 227 ▶ $columns->[$j]{eX}{ $#{ $columns->[$j]{head} } } = undef if ! $sclr and $+{t} eq 'X'; # $$chkVAR && ... %%%ADDX:
Branch: 1 branch
BranchTrueFalseTotal
if not $sclr and $+{"t"} eq "X" 46 181 227
Condition100%3/3
not $sclr and $+{"t"} eq "X"
!ll&&!rl&&r
1816346
MC/DC100%2/2
not $sclr and $+{"t"} eq "X"
not $sclr $+{"t"} eq "X"
Truth table100%3/3
not(A) and B
A= not $sclrB= $+{"t"} eq "X"
ABresult
0X0
100
111
847 }
848 }
849  
850 481 return 0;
851 }
852  
853 }
854 elsif( $$z =~/%%%+END(?<t>[TZ]?):/) { # end of template area
855  
856 # Clear the VAR-structure for the next external variable
857 55 $$chkVAR = 0;
858 55 undef $$key;
859 55 @$columns = ();
860  
861 55 ▶ return 1 if $+{t} eq 'T'; # END of Template area --> output everything to the end of template without substitution
Branch: 1 branch
BranchTrueFalseTotal
if $+{"t"} eq "T" 9 46 55
862  
863 46 ▶ undef $$tdz if $+{t} eq 'Z'; # End of TDZ
Branch: 1 branch
BranchTrueFalseTotal
if $+{"t"} eq "Z" 28 18 46
864 46 return 0;
865 }
866  
867 870 ▶ $$tdz = 1 if $$z =~s/^\s*%%%+TDZ:\s?[\r\n]*//; # The Dead Zone
Branch: 1 branch
BranchTrueFalseTotal
if $$z =~ s/^\s*%%%+TDZ:\s?[\r\n]*// 13 857 870
868  
869 870 ▶ if( $$tdz ) { # The Dead Zone is ON
Branch: 1 branch
BranchTrueFalseTotal
if ($$tdz) 172 698 870
870 172 ▶ if( length $$z ) {# Output TeX
Branch: 1 branch
BranchTrueFalseTotal
if (length $$z) 161 11 172
871 161 print { $op->{fh} } $$z;
872 161 ++$op->{nlo};
873 }
874 172 return 0;
875 }
876  
877 698 ▶ if( $$z =~/(.*?)\s?%%%+VAR:\s*(\*?)([^\s:%#\*]+)(%?)\s?(.*)/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($$z =~ /(.*?)\s?%%%+VAR:\s*(\*?)([^\s:%#\*]+)(%?)\s?(.*)/) { } 152 546 698
elsif ($$z =~ /%%%V:\s*=(def|esc|ignore|silent|debug)=\s*([\d~%]*)/) { } 9 537 546
elsif ($$z =~ /^(?<v>.*?)\s?%%%+V:\s*(?<x>\*?)(?<k>[^\s:%#\*]+)(?<p>%?)\s?(?<s>.*)/) { } 78 459 537
878 152 my $before = $1; # Value, by default
879 152 my $eXi = $2; # eXistence of Value
880 152 my $k = my $k0 = $3; # name (key)
881 152 my $Np = $4; # NO \par
882 152 my $paste = $5; # on right text for SCALAR only
883  
884 # root or global structure (environment)
885 152 ▶ my $vd = ( $k =~s/^\/+//) ? $info : $$data;
Branch: 1 branch
BranchTrueFalseTotal
$k =~ s[^/+][] ? : 14 138 152
886  
887 152 my $xk; # for unknown/undefined sub-key
888 152 my @kk = grep length, split '/', $k;
889  
890 # Search nested sub-keys
891 152 foreach my $sk ( @kk ) {
892 164 $$vardata = $vd;
893  
894 164 my $vtype = ref $vd;
895  
896 164 ▶ if( $sk =~/^\-*(\d+)$/
Branch: 2 branches
BranchTrueFalseTotal
if ($sk =~ /^\-*(\d+)$/ and $vtype eq 'ARRAY' and $1 < @{$vd;} || $sk + 0 < 0 && $1 == @{$vd;}) { } 23 141 164
elsif ($vtype eq 'HASH' and exists $vd->{$sk}) { } 115 26 141
Condition100%9/9
$sk =~ /^\-*(\d+)$/ and $vtype eq "ARRAY" and $1 < @{$vd;} || $sk + 0 < 0 && $1 == @{$vd;}
!ll&&!rl&&r
140123
$sk =~ /^\-*(\d+)$/ and $vtype eq "ARRAY"
!ll&&!rl&&r
139124
$1 < @{$vd;} or $sk + 0 < 0 and $1 == @{$vd;}
l!l&&r!l&&!r
2121
MC/DC100%4/4
$sk =~ /^\-*(\d+)$/ and $vtype eq "ARRAY" and $1 < @{$vd;} || $sk + 0 < 0 && $1 == @{$vd;}
$sk =~ /^\-*(\d+)$/ $vtype eq "ARRAY" $1 < @{$vd;} $sk + 0 < 0 and $1 == @{$vd;}
Truth table100%5/5
A and B and C or D
A= $sk =~ /^\-*(\d+)$/B= $vtype eq "ARRAY"C= $1 < @{$vd;}D= $sk + 0 < 0 and $1 == @{$vd;}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
897 and $vtype eq 'ARRAY'
898 24 ▶ and ( $1 < @{$vd} or ( $sk+0 < 0 and $1 == @{$vd} ))
Condition66%2/3
$sk + 0 < 0 and $1 == @{$vd;}
!ll&&!rl&&r
102
MC/DC50%1/2
$sk + 0 < 0 and $1 == @{$vd;}
$sk + 0 < 0 $1 == @{$vd;}
Truth table66%2/3
A and B
A= $sk + 0 < 0B= $1 == @{$vd;}
ABresult
0X0
100
111
899 ) {
900 23 ▶ last if &_data_redef( $sk, $vd->[$sk+0], \$k, \$vd, \$xk );
Branch: 1 branch
BranchTrueFalseTotal
if &_data_redef($sk, $$vd[$sk + 0], \$k, \$vd, \$xk) 7 16 23
901 }
902 ▶ elsif( $vtype eq 'HASH' and exists( $vd->{$sk} )) {
Condition100%3/3
$vtype eq "HASH" and exists $vd->{$sk}
!ll&&!rl&&r
818115
MC/DC100%2/2
$vtype eq "HASH" and exists $vd->{$sk}
$vtype eq "HASH" exists $vd->{$sk}
Truth table100%3/3
A and B
A= $vtype eq "HASH"B= exists $vd->{$sk}
ABresult
0X0
100
111
903 115 ▶ last if &_data_redef( $sk, $vd->{$sk}, \$k, \$vd, \$xk );
Branch: 1 branch
BranchTrueFalseTotal
if &_data_redef($sk, $vd->{$sk}, \$k, \$vd, \$xk) 44 71 115
904 }
905 else {
906 26 $xk = $sk;
907 26 last;
908 }
909 }
910  
911 # Clear the VAR-structure for a new variable
912 152 $$chkVAR = 0;
913 152 undef $$key;
914 152 @$columns = ();
915  
916 152 ▶ if( $xk ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xk) 26 126 152
917 26 ▶push @{$op->{logs}}, "~~> l.$. WARNING#2: unknown or undef ARRAY|HASH|SCALAR|REF.SCALAR of sub-key '$xk' in %%%VAR:". $k0 if $op->{debug} or ! $op->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} or not $op->{"ignore"} 21 5 26
Condition100%3/3
$op->{"debug"} or not $op->{"ignore"}
l!l&&r!l&&!r
8135
MC/DC100%2/2
$op->{"debug"} or not $op->{"ignore"}
$op->{"debug"} not $op->{"ignore"}
Truth table100%3/3
A or not(B)
A= $op->{"debug"}B= not $op->{"ignore"}
ABresult
1X1
011
000
918  
919 26 $$vardata = $$data;
920 26 print { $op->{fh} } $$z;
921 26 ++$op->{nlo};
922 26 return 0;
923 }
924  
925 # key or sub-...sub-key is found
926 126 ▶push @{$op->{logs}}, "--> l.$. Found %%%VAR:". $k0 if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 20 106 126
927  
928 126 ▶ my $vk = ref $$vardata eq 'HASH' ? $$vardata->{$k} : $$vardata->[$k];
Branch: 1 branch
BranchTrueFalseTotal
ref $$vardata eq 'HASH' ? : 111 15 126
929  
930 126 ▶push @{$op->{logs}}, "~~> l.$. NOT defined key in %%%VAR:". $k0 if ! defined($vk) && $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $vk and $op->{"debug"} 2 124 126
Condition100%3/3
not defined $vk and $op->{"debug"}
!ll&&!rl&&r
11862
MC/DC100%2/2
not defined $vk and $op->{"debug"}
not defined $vk $op->{"debug"}
Truth table100%3/3
not(A) and B
A= not defined $vkB= $op->{"debug"}
ABresult
0X0
100
111
931  
932 126 ▶ return 0 if &_chk_var( $k, $vk, $eXi, $Np, \$paste, \$before, $chkVAR, $columns, $z, $op );
Branch: 1 branch
BranchTrueFalseTotal
if &_chk_var($k, $vk, $eXi, $Np, \$paste, \$before, $chkVAR, $columns, $z, $op) 2 124 126
933  
934 # push @{$op->{logs}}, "--> l.$. Remember key = '$k' (chkVAR=$$chkVAR), type: ".ref($vk) if $op->{debug}; ###AG
935  
936 124 $$key = $k; # save key name
937 124 return 0;
938  
939 }
940 elsif( $$z =~/%%%V:\s*=(def|esc|ignore|silent|debug)=\s*([\d~%]*)/) { # setting up facultative options
941 9 my $k = $1;
942 9 ▶ my $x = $2 || 0;
Condition100%2/2
$2 || 0
l!l
54
MC/DC100%1/1
$2 || 0
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
943 9 ▶ my $i = ( $op->{$k} && $op->{$k} =~/\d\d?/ ) ? $& : 0;
Branch: 1 branch
BranchTrueFalseTotal
$op->{$k} && $op->{$k} =~ /\d\d?/ ? : 3 6 9
Condition100%3/3
$op->{$k} and $op->{$k} =~ /\d\d?/
!ll&&!rl&&r
513
MC/DC100%2/2
$op->{$k} and $op->{$k} =~ /\d\d?/
$op->{$k} $op->{$k} =~ /\d\d?/
Truth table100%3/3
A and B
A= $op->{$k}B= $op->{$k} =~ /\d\d?/
ABresult
0X0
100
111
944  
945 9 ▶ if( $i < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 2) 8 1 9
946 8 $op->{$k} = $x ;
947  
948 8 ▶push @{$op->{logs}}, "~~> l.$. Option =$k= set to $x" if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 5 3 8
949  
950 }
951  
952 9 return 0;
953 }
954 elsif( $$z =~/^(?<v>.*?)\s?%%%+V:\s*(?<x>\*?)(?<k>[^\s:%#\*]+)(?<p>%?)\s?(?<s>.*)/) {
955 78 my $k = $+{k};
956  
957 78 my %el;
958 78 &_set_column( $+{v}, $+{x}, $+{p}, $+{s}, \%el );
959  
960 78 my $inidata = $$data; # save initial environment
961  
962 78 my $slash;
963 78 ▶ if( $k =~s/^\/+//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($k =~ s[^/+][]) { } 14 64 78
elsif ($k =~ m[/]) { } 3 61 64
964 14 $slash = 1;
965 14 $$data = $info; # reset to root environment
966  
967 14 ▶ length($k) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
length $k or return 0 10 4 14
968 }
969 elsif( $k =~/\//) {
970 3 $slash = 1;
971 }
972  
973 # Search nested sub-keys
974 74 my $x = 0; # 1 is SCALAR value found or unknown sub-key
975 74 my @kk = grep length, split '/', $k;
976  
977 74 my $i = 0;
978 74 foreach my $sk ( @kk ) {
979  
980 87 my $dtype = ref $$data;
981  
982 87 my $d;
983 87 ▶ if( $sk =~/^\-*(\d+)$/
Branch: 2 branches
BranchTrueFalseTotal
if ($sk =~ /^\-*(\d+)$/ and $dtype eq 'ARRAY' and $1 < @{$$data;} || $sk + 0 < 0 && $1 == @{$$data;}) { } 12 75 87
elsif ($dtype eq 'HASH' and exists $$data->{$sk}) { } 35 40 75
Condition66%6/9
$sk =~ /^\-*(\d+)$/ and $dtype eq "ARRAY" and $1 < @{$$data;} || $sk + 0 < 0 && $1 == @{$$data;}
!ll&&!rl&&r
75012
$sk =~ /^\-*(\d+)$/ and $dtype eq "ARRAY"
!ll&&!rl&&r
641112
$1 < @{$$data;} or $sk + 0 < 0 and $1 == @{$$data;}
l!l&&r!l&&!r
1200
MC/DC50%2/4
$sk =~ /^\-*(\d+)$/ and $dtype eq "ARRAY" and $1 < @{$$data;} || $sk + 0 < 0 && $1 == @{$$data;}
$sk =~ /^\-*(\d+)$/ $dtype eq "ARRAY" $1 < @{$$data;} $sk + 0 < 0 and $1 == @{$$data;}
Truth table60%3/5
A and B and C or D
A= $sk =~ /^\-*(\d+)$/B= $dtype eq "ARRAY"C= $1 < @{$$data;}D= $sk + 0 < 0 and $1 == @{$$data;}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
984 and $dtype eq 'ARRAY'
985 0 ▶ and ( $1 < @{$$data} or ( $sk+0 < 0 and $1 == @{$$data} ))
Condition0%0/3
$sk + 0 < 0 and $1 == @{$$data;}
!ll&&!rl&&r
000
MC/DC0%0/2
$sk + 0 < 0 and $1 == @{$$data;}
$sk + 0 < 0 $1 == @{$$data;}
Truth table0%0/3
A and B
A= $sk + 0 < 0B= $1 == @{$$data;}
ABresult
0X0
100
111
986 ) {
987 12 $d = $$data->[$sk+0];
988 }
989 ▶ elsif( $dtype eq 'HASH' && exists( $$data->{$sk} )) {
Condition100%3/3
$dtype eq "HASH" and exists $$data->{$sk}
!ll&&!rl&&r
73335
MC/DC100%2/2
$dtype eq "HASH" and exists $$data->{$sk}
$dtype eq "HASH" exists $$data->{$sk}
Truth table100%3/3
A and B
A= $dtype eq "HASH"B= exists $$data->{$sk}
ABresult
0X0
100
111
990 35 $d = $$data->{$sk};
991 }
992 else {
993 40 ▶push @{$op->{logs}}, "~~> l.$. WARNING#3: unknown sub-key '$sk' in %%%V:". $k if $op->{debug} or ! $op->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} or not $op->{"ignore"} 35 5 40
Condition100%3/3
$op->{"debug"} or not $op->{"ignore"}
l!l&&r!l&&!r
14215
MC/DC100%2/2
$op->{"debug"} or not $op->{"ignore"}
$op->{"debug"} not $op->{"ignore"}
Truth table100%3/3
A or not(B)
A= $op->{"debug"}B= not $op->{"ignore"}
ABresult
1X1
011
000
994  
995 40 print { $op->{fh} } $$z;
996 40 ++$op->{nlo};
997  
998 40 $x = 1;
999 40 last;
1000 }
1001  
1002 47 my $dtp = ref $d;
1003  
1004 # Check type
1005 47 ▶ if( $dtp =~/^(?:ARRAY|HASH)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dtp =~ /^(?:ARRAY|HASH)$/) 16 31 47
1006  
1007 16 ▶ if( $slash ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slash) 15 1 16
1008 15 $$data = $d; # sub-key (path) found: redefined
1009 15 next;
1010 }
1011  
1012 1 ▶push @{$op->{logs}}, "~~> l.$. WARNING#5: (ARRAY|HASH) w/o '/' is wrong type of '$sk' in %%%V:". $k if $op->{debug} or ! $op->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} or not $op->{"ignore"} 1 0 1
Condition33%1/3
$op->{"debug"} or not $op->{"ignore"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$op->{"debug"} or not $op->{"ignore"}
$op->{"debug"} not $op->{"ignore"}
Truth table33%1/3
A or not(B)
A= $op->{"debug"}B= not $op->{"ignore"}
ABresult
1X1
011
000
1013  
1014 1 print { $op->{fh} } $$z;
1015 1 ++$op->{nlo};
1016  
1017 1 $x = 1;
1018 1 last;
1019 }
1020  
1021 31 my $v;
1022 31 ▶ if( ref \$d eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref \$d eq 'SCALAR') { } 29 2 31
elsif ($dtp eq 'SCALAR') { } 1 1 2
1023 29 $v = $d;
1024 }
1025 elsif( $dtp eq 'SCALAR') { # REF->SCALAR
1026 1 $v = $$d;
1027 }
1028 else {
1029 1 ▶push @{$op->{logs}}, "~~> l.$. WARNING#4: wrong type (not SCALAR|ARRAY|HASH) of '$sk' in %%%V:". $k if $op->{debug} or ! $op->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} or not $op->{"ignore"} 1 0 1
Condition33%1/3
$op->{"debug"} or not $op->{"ignore"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$op->{"debug"} or not $op->{"ignore"}
$op->{"debug"} not $op->{"ignore"}
Truth table33%1/3
A or not(B)
A= $op->{"debug"}B= not $op->{"ignore"}
ABresult
1X1
011
000
1030  
1031 1 print { $op->{fh} } $$z;
1032 1 ++$op->{nlo};
1033  
1034 1 $x = 1;
1035 1 last;
1036 }
1037  
1038 30 ▶ $_ = &_v_print( $k, $v, \%el, $op ) and return $_;
Branch: 1 branch
BranchTrueFalseTotal
$_ = &_v_print($k, $v, \%el, $op) and return $_ 3 27 30
1039  
1040 27 ▶push @{$op->{logs}}, "~~> l.$. WARNING#9: '$sk' is not at the end of %%%V:". $k if $i < $#kk and ( $op->{debug} or ! $op->{ignore} );
Branch: 1 branch
BranchTrueFalseTotal
if $i < $#kk and $op->{"debug"} || !$op->{"ignore"} 1 26 27
Condition50%3/6
$i < $#kk and $op->{"debug"} || !$op->{"ignore"}
!ll&&!rl&&r
2601
$op->{"debug"} or not $op->{"ignore"}
l!l&&r!l&&!r
100
MC/DC33%1/3
$i < $#kk and $op->{"debug"} || !$op->{"ignore"}
$i < $#kk $op->{"debug"} not $op->{"ignore"}
Truth table50%2/4
A and B or not(C)
A= $i < $#kkB= $op->{"debug"}C= not $op->{"ignore"}
ABCresult
0XX0
1000
11X1
1011
1041  
1042 27 $x = 1;
1043 27 last;
1044 }
1045 continue {
1046 15 ++$i;
1047 }
1048  
1049 71 ▶ $$data = $inidata if $x; # SCALAR value found or unknown sub-key: reset to initial environment
Branch: 1 branch
BranchTrueFalseTotal
if $x 69 2 71
1050  
1051 71 return 0;
1052 }
1053  
1054 459 print { $op->{fh} } $$z;
1055 459 ++$op->{nlo};
1056  
1057 459 return 0;
1058 }
1059  
1060  
1061 320 ▶sub _set_column {
Subroutine _set_column: called CC=5 SCAR=16.1
1062 320 my( $dV, $eXi, $Np, $paste, $column ) = @_;
1063  
1064 320 ▶ $column->{v} = $dV if length $dV; # Value, by default
Branch: 1 branch
BranchTrueFalseTotal
if length $dV 231 89 320
1065 320 ▶ $column->{x} = 1 if $eXi; # check the eXistence of Value
Branch: 1 branch
BranchTrueFalseTotal
if $eXi 3 317 320
1066 320 ▶ $column->{'%'} = 1 if $Np; # NO \par
Branch: 1 branch
BranchTrueFalseTotal
if $Np 50 270 320
1067 320 ▶ $column->{p} = $paste if length $paste; # on right text for SCALAR only
Branch: 1 branch
BranchTrueFalseTotal
if length $paste 29 291 320
1068 }
1069  
1070  
1071 138 ▶sub _data_redef {
Subroutine _data_redef: called CC=5 SCAR=16.1
1072 138 my( $sk, $d, $k, $data, $xk ) = @_;
1073  
1074 138 ▶ if( ref $d eq 'ARRAY' or ref $d eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $d eq "ARRAY" or ref $d eq "HASH") 87 51 138
Condition100%3/3
ref $d eq "ARRAY" or ref $d eq "HASH"
l!l&&r!l&&!r
642351
MC/DC100%2/2
ref $d eq "ARRAY" or ref $d eq "HASH"
ref $d eq "ARRAY" ref $d eq "HASH"
Truth table100%3/3
A or B
A= ref $d eq "ARRAY"B= ref $d eq "HASH"
ABresult
1X1
011
000
1075 87 $$data = $d; # redefined for %%%VAR:
1076 87 $$k = $sk;
1077 87 return 0;
1078 }
1079  
1080 51 ▶ if( ref \$d eq 'SCALAR' or ref $d eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref \$d eq 'SCALAR' or ref $d eq 'SCALAR') { } 50 1 51
Condition100%3/3
ref \$d eq "SCALAR" or ref $d eq "SCALAR"
l!l&&r!l&&!r
4731
MC/DC100%2/2
ref \$d eq "SCALAR" or ref $d eq "SCALAR"
ref \$d eq "SCALAR" ref $d eq "SCALAR"
Truth table100%3/3
A or B
A= ref \$d eq "SCALAR"B= ref $d eq "SCALAR"
ABresult
1X1
011
000
1081 50 $$k = $sk;
1082 }
1083 else {
1084 1 $$xk = $sk;
1085 }
1086 51 return 1;
1087 }
1088  
1089 126 ▶sub _chk_var {
Subroutine _chk_var: called CC=15 SCAR=27.1
1090 126 my( $k, $vk, $eXi, $Np, $paste, $before, $chkVAR, $columns, $z, $op ) = @_;
1091  
1092 126 ▶ if( ref $vk eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $vk eq 'ARRAY') { } 54 72 126
elsif (ref \$vk eq 'SCALAR' or ref $vk eq 'SCALAR') { } 51 21 72
1093  
1094 54 ▶ if( @{ $vk } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$vk;}) { } 53 1 54
1095 # Check ARRAY.{ARRAY|HASH|SCALAR[.REF]}
1096  
1097 53 for my $d ( @{ $vk } ) {
1098 182 my $dtype = ref $d;
1099  
1100 182 ▶ if($dtype eq 'ARRAY'){
Branch: 4 branches
BranchTrueFalseTotal
if ($dtype eq 'ARRAY') { } 52 130 182
elsif ($dtype eq 'HASH') { } 41 89 130
elsif (ref \$d eq 'SCALAR') { } 84 5 89
elsif ($dtype eq 'SCALAR') { } 4 1 5
1101 52 $$chkVAR |= 0b00001;
1102 }
1103 elsif($dtype eq 'HASH') {
1104 41 $$chkVAR |= 0b00010;
1105 }
1106 elsif(ref \$d eq 'SCALAR') {
1107 84 $$chkVAR |= 0b00100;
1108 }
1109 elsif($dtype eq 'SCALAR') { # REF->SCALAR
1110 4 $$chkVAR |= 0b01000;
1111 }
1112 else {
1113 1 $$chkVAR |= 0b10000; # other
1114 }
1115 }
1116 }
1117 else {
1118 1 $$chkVAR |= 0b00100; # by default, SCALAR
1119 }
1120  
1121 54 ▶ if( $$chkVAR > 0b01000 or ($$chkVAR & ($$chkVAR - 1)) ) { # not 1 bit only, i.e. bolee odnoj edinicu
Branch: 1 branch
BranchTrueFalseTotal
if ($$chkVAR > 8 or $$chkVAR & $$chkVAR - 1) 2 52 54
Condition66%2/3
$$chkVAR > 8 or $$chkVAR & $$chkVAR - 1
l!l&&r!l&&!r
2052
MC/DC50%1/2
$$chkVAR > 8 or $$chkVAR & $$chkVAR - 1
$$chkVAR > 8 $$chkVAR & $$chkVAR - 1
Truth table66%2/3
A or B
A= $$chkVAR > 8B= $$chkVAR & $$chkVAR - 1
ABresult
1X1
011
000
1122 2 ▶push @{$op->{logs}}, "~~> l.$. WARNING#6: mixed types (ARRAY with HASH with SCALAR or other) of %%%VAR:". $k if $op->{debug} or ! $op->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} or not $op->{"ignore"} 2 0 2
Condition33%1/3
$op->{"debug"} or not $op->{"ignore"}
l!l&&r!l&&!r
020
MC/DC0%0/2
$op->{"debug"} or not $op->{"ignore"}
$op->{"debug"} not $op->{"ignore"}
Truth table33%1/3
A or not(B)
A= $op->{"debug"}B= not $op->{"ignore"}
ABresult
1X1
011
000
1123  
1124 2 print { $op->{fh} } $$z;
1125 2 ++$op->{nlo};
1126 2 return 1;
1127 }
1128 }
1129 ▶ elsif( ref \$vk eq 'SCALAR' or ref $vk eq 'SCALAR') {
Condition100%3/3
ref \$vk eq "SCALAR" or ref $vk eq "SCALAR"
l!l&&r!l&&!r
48321
MC/DC100%2/2
ref \$vk eq "SCALAR" or ref $vk eq "SCALAR"
ref \$vk eq "SCALAR" ref $vk eq "SCALAR"
Truth table100%3/3
A or B
A= ref \$vk eq "SCALAR"B= ref $vk eq "SCALAR"
ABresult
1X1
011
000
1130 51 $columns->[0]{ki} = $k;
1131 51 &_set_column('', $eXi, $Np, $$paste, $columns->[0] );
1132 }
1133  
1134 124 ▶ if( $$before ) {# Output prefix TeX
Branch: 1 branch
BranchTrueFalseTotal
if ($$before) 19 105 124
1135 19 print { $op->{fh} } $$before;
1136 # ++$op->{nlo};
1137 }
1138  
1139 124 return 0;
1140 }
1141  
1142 # VALUE output
1143 658 ▶sub _v_print {
Subroutine _v_print: called CC=25 SCAR=32.2
1144 658 my( $k, $v, $el, $op ) = @_;
1145 658 ▶ $v = $$v if ref $v eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "SCALAR" 3 655 658
1146  
1147 658 ▶ unless( defined $v ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 56 602 658
1148 56 ▶ if( $op->{def} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->{"def"}) 52 4 56
1149 52 ▶push @{$op->{logs}}, "~~> l.$.".' NOT defined %%%V[AR]:'. $k if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 5 47 52
1150  
1151 52 return 0;
1152 }
1153 4 $v = '';
1154 }
1155  
1156 606 ▶ if( $el->{x} && length($v) ) { # for '*param'
Branch: 1 branch
BranchTrueFalseTotal
if ($el->{'x'} and length $v) { } 5 601 606
Condition100%3/3
$el->{"x"} and length $v
!ll&&!rl&&r
60015
MC/DC100%2/2
$el->{"x"} and length $v
$el->{"x"} length $v
Truth table100%3/3
A and B
A= $el->{"x"}B= length $v
ABresult
0X0
100
111
1157  
1158 5 my $f;
1159 5 for('v','p') {
1160 10 ▶ exists( $el->{$_} ) or next;
Branch: 1 branch
BranchTrueFalseTotal
exists $el->{$_} or next 9 1 10
1161  
1162 9 print { $op->{fh} } $el->{$_};
1163 9 $f = 1;
1164 }
1165  
1166 5 ▶push @{$op->{logs}}, "--> l.$.>". $op->{nlo} .' Insert by eXistence condition (*) of %%%V[AR]:'. $k .'= '. $el->{v} if $f && $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $f and $op->{"debug"} 1 4 5
Condition66%2/3
$f and $op->{"debug"}
!ll&&!rl&&r
041
MC/DC50%1/2
$f and $op->{"debug"}
$f $op->{"debug"}
Truth table66%2/3
A and B
A= $fB= $op->{"debug"}
ABresult
0X0
100
111
1167  
1168 }
1169 else {
1170 601 ▶ if( $v =~s/^\x{01}//) { # by default text from template
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/^\x{01}//) 5 596 601
1171 5 ▶ if( exists $el->{v} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"v"}) 3 2 5
1172 3 print { $op->{fh} } $el->{v};
1173  
1174 0 ▶push @{$op->{logs}}, "--> l.$.>". $op->{nlo} .' Insert text by default %%%V[AR]:'. $k .'= '. $el->{v} if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 0 3 3
1175 }
1176 }
1177  
1178 601 ▶ if( $v =~/^\x{03}(\x{03}?)/) { # END of INPUT template
Branch: 3 branches
BranchTrueFalseTotal
if ($v =~ /^\x{03}(\x{03}?)/) { } 4 597 601
elsif ($v =~ /^\x{04}/) { } 5 592 597
elsif (length $v) { } 568 24 592
1179 4 ▶ say { $op->{fh} } $1 ? '\bye' : '\endinput';
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 1 3 4
1180 4 ++$op->{nlo};
1181  
1182 4 return 3;
1183 }
1184 elsif( $v =~/^\x{04}/) { # END of INPUT template, similar to \bye
1185 5 say { $op->{fh} } '\end{document}';
1186 5 ++$op->{nlo};
1187  
1188 5 return 3;
1189 }
1190 elsif( length $v ) {
1191 568 $op->{_MFLAGS_} = 0; # value modification (change) flag: 0 is 'NO', 1 -- 'YES' for ordinary text, 2 -- 'YES' for TeX-commands
1192 568 for my $f ( @{ $op->{_ACTIONS_} } ) {
1193 83 ▶ $f or next;
Branch: 1 branch
BranchTrueFalseTotal
$f or next 74 9 83
1194  
1195 74 ▶ $_ = int( $f->{_code_}->( $v, $op ) // 0 );
Condition100%2/2
$f->{"_code_"}->($v, $op) // 0
l!l
713
MC/DC100%1/1
$f->{"_code_"}->($v, $op) // 0
$f->{"_code_"}->($v, $op)
Truth table100%2/2
A
A= $f->{"_code_"}->($v, $op)
Aresult
11
00
1196 74 $op->{_MFLAGS_} += 0;
1197 74 $op->{_MFLAGS_} |= $_;
1198 }
1199  
1200 568 ▶push @{$op->{logs}}, "--> l.$.>". $op->{nlo} .' Insert %%%V[AR]:'. $k .'= '. $v if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 75 493 568
1201  
1202 568 print { $op->{fh} } $v;
1203 568 ▶ ++$op->{nlo} while $v =~/\n/g;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /\n/g and do { ++$op->{"nlo"} } 18 568 586
1204  
1205 568 ▶ print { $op->{fh} } $el->{p} if exists $el->{p};
Branch: 1 branch
BranchTrueFalseTotal
if exists $el->{"p"} 16 552 568
1206 }
1207 }
1208  
1209 597 ▶ unless( $el->{'%'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($el->{"%"}) 439 158 597
1210 439 print { $op->{fh} } "\n"; # NO:YES \par
1211 439 ++$op->{nlo};
1212 }
1213  
1214 597 return 0;
1215 }
1216  
1217 # HEAD-TAIL output
1218 1250 ▶sub _ht_print {
Subroutine _ht_print: called CC=9 SCAR=22.0
1219 1250 my( $el, $ht, $op, $border ) = @_;
1220  
1221 1250 ▶ $el->{$ht} or return;
Branch: 1 branch
BranchTrueFalseTotal
$el->{$ht} or return 579 671 1250
1222  
1223 579 my $i = 0;
1224 579 foreach( @{ $el->{$ht} } ) {
1225 696 ▶ next if $ht eq 'head' and $border && exists( $el->{eX} ) && exists( $el->{eX}{$i} );
Branch: 1 branch
BranchTrueFalseTotal
if $ht eq "head" and ($border and exists $el->{"eX"} and exists $el->{"eX"}{$i}) 46 650 696
Condition100%9/9
$ht eq "head" and ($border and exists $el->{"eX"} and exists $el->{"eX"}{$i})
!ll&&!rl&&r
6458646
$border and exists $el->{"eX"} and exists $el->{"eX"}{$i}
!ll&&!rl&&r
5662046
$border and exists $el->{"eX"}
!ll&&!rl&&r
5462066
MC/DC100%4/4
$ht eq "head" and ($border and exists $el->{"eX"} and exists $el->{"eX"}{$i})
$ht eq "head" $border exists $el->{"eX"} exists $el->{"eX"}{$i}
Truth table100%5/5
A and B and C and D
A= $ht eq "head"B= $borderC= exists $el->{"eX"}D= exists $el->{"eX"}{$i}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1226  
1227 650 ▶push @{$op->{logs}}, "-->\tl.$.>". $op->{nlo} ." Insert $ht: ". $_ if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 68 582 650
1228  
1229 650 print { $op->{fh} } $_;
1230 650 ▶ ++$op->{nlo} while /\n/g;
Branch: 1 branch
BranchTrueFalseTotal
/\n/g and do { ++$op->{"nlo"} } 483 650 1133
1231 }
1232 continue {
1233 696 ++$i;
1234 }
1235  
1236 }
1237  
1238 # HEAD-VALUE-TAIL output
1239 657 ▶sub _hvt_print {
Subroutine _hvt_print: called CC=6 SCAR=17.9
1240 657 my( $ki, $val, $el, $op, $border ) = @_;
1241  
1242 657 ▶ if( length($ki) and ! defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ki and not defined $val) 32 625 657
Condition100%3/3
length $ki and not defined $val
!ll&&!rl&&r
5357232
MC/DC100%2/2
length $ki and not defined $val
length $ki not defined $val
Truth table100%3/3
A and not(B)
A= length $kiB= not defined $val
ABresult
0X0
100
111
1243 32 ▶ if( $op->{def} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->{"def"}) 29 3 32
1244 29 ▶ push @{$op->{logs}}, "~~> l.$.".' NOT defined %%%V:'. $ki if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 11 18 29
1245 29 return 0;
1246 }
1247  
1248 3 $val = '';
1249 }
1250  
1251 # output head of variable
1252 628 &_ht_print( $el, 'head', $op, $border );
1253  
1254 # output value of variable ( $ki, $val, $el, $op )
1255 628 ▶ $_ = &_v_print and return $_;
Branch: 1 branch
BranchTrueFalseTotal
$_ = &_v_print and return $_ 6 622 628
1256  
1257 # output tail of variable
1258 622 &_ht_print( $el, 'tail', $op, 0);
1259  
1260 622 return 0;
1261 }
1262  
1263  
1264 279 ▶sub _s_a_prn {
Subroutine _s_a_prn: called CC=9 SCAR=22.1
1265 279 my( $i, $values, $el, $op, $border, $col ) = @_;
1266  
1267 279 my $val = $values->[$i];
1268 279 ▶ $val = $$val if ref $val eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $val eq "SCALAR" 4 275 279
1269  
1270 279 my $end = 0;
1271  
1272 279 ▶ if( ref \$val eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref \$val eq 'SCALAR') { } 273 6 279
elsif (ref $val eq 'ARRAY') { } 5 1 6
1273 273 $end = &_hvt_print( $i, $val, $el, $op, $$border );
1274  
1275 273 ++$$col;
1276 273 $$border = 0;
1277 }
1278 elsif( ref $val eq 'ARRAY') { # [...].ARRAY.ARRAY
1279  
1280 5 for( @$val ) {
1281 27 ▶ next if ref \$_ ne 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref \$_ ne "SCALAR" 1 26 27
1282  
1283 # [...].ARRAY.ARRAY.SCALAR
1284 26 $end = &_hvt_print( $i, $_, $el, $op, $$border );
1285  
1286 26 ++$$col;
1287 26 $$border = 0;
1288  
1289 26 ▶ last if $end;
Branch: 1 branch
BranchTrueFalseTotal
if $end 0 26 26
1290 }
1291 }
1292 else {
1293 1 ▶push @{$op->{logs}}, "~~> l.$. WARNING#10: ...ARRAY.ARRAY[$i] is NOT a SCALAR in %%%V:$i ...skipped" if $op->{debug} or ! $op->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} or not $op->{"ignore"} 1 0 1
Condition33%1/3
$op->{"debug"} or not $op->{"ignore"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$op->{"debug"} or not $op->{"ignore"}
$op->{"debug"} not $op->{"ignore"}
Truth table33%1/3
A or not(B)
A= $op->{"debug"}B= not $op->{"ignore"}
ABresult
1X1
011
000
1294 }
1295  
1296 279 return $end;
1297 }
1298  
1299  
1300 198 ▶sub _mixed_indices {
Subroutine _mixed_indices: called CC=23 SCAR=31.4
1301 198 my( $ki, $values, $el, $op, $border ) = @_;
1302  
1303 198 my $nd = @$values;
1304 198 my $col = my $end = 0;
1305  
1306 198 for my $ii ( split ',', $ki ) { # e.g. -1-,1-3,6-7-9,-,4,-5,0,7-
1307 216 ▶ next if $ii eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $ii eq "-" 1 215 216
1308  
1309 215 ▶ if( $ii =~/^(\-[1-9]\d*)\-(\d*)$/) { # -1- i.e. reverse: -1,-2,..-@arr (i.e. arr_start)
Branch: 1 branch
BranchTrueFalseTotal
if ($ii =~ /^(\-[1-9]\d*)\-(\d*)$/) 12 203 215
1310 12 my $s = $1;
1311 12 ▶ my $e = -1*($2 || $nd);
Condition66%2/3
$2 || $nd
l!l&&r!l&&!r
2100
MC/DC0%0/2
$2 || $nd
$2 $nd
Truth table66%2/3
A || B
A= $2B= $nd
ABresult
1X1
011
000
1312 12 ▶ $s = -1*$nd if abs($s) > $nd;
Branch: 1 branch
BranchTrueFalseTotal
if abs $s > $nd 1 11 12
1313 12 ▶ $e = -1*$nd if abs($e) > $nd;
Branch: 1 branch
BranchTrueFalseTotal
if abs $e > $nd 1 11 12
1314 12 ▶ ($s, $e) = ($e, $s) if $e > $s;
Branch: 1 branch
BranchTrueFalseTotal
if $e > $s 1 11 12
1315  
1316 12 ▶ for( my $i = $s; $i >= $e; --$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $e) 38 12 50
1317 38 ▶ $end = &_s_a_prn( $i, $values, $el, $op, \$border, \$col ) and last;
Branch: 1 branch
BranchTrueFalseTotal
$end = &_s_a_prn($i, $values, $el, $op, \$border, \$col) and last 0 38 38
1318 }
1319  
1320 12 ▶ $end ? last : next;
Branch: 1 branch
BranchTrueFalseTotal
$end ? : 0 12 12
1321 }
1322  
1323 203 ▶ if( $ii =~/^\-[0-9]+$/ ) { # -5
Branch: 1 branch
BranchTrueFalseTotal
if ($ii =~ /^\-[0-9]+$/) 6 197 203
1324 6 my $i = $ii+0;
1325  
1326 6 ▶ if( abs($i) <= $nd ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $i <= $nd) 4 2 6
1327 4 ▶ $end = &_s_a_prn( $i, $values, $el, $op, \$border, \$col ) and last;
Branch: 1 branch
BranchTrueFalseTotal
$end = &_s_a_prn($i, $values, $el, $op, \$border, \$col) and last 1 3 4
1328 }
1329  
1330 5 next;
1331 }
1332  
1333 197 my @n = grep{length} sort{$a <=> $b} split '-', $ii;
1334  
1335 197 ▶ if( @n < 2 and $n[0] < $nd ) { # e.g. 4 || 0 || 7(-)
Branch: 1 branch
BranchTrueFalseTotal
if (@n < 2 and $n[0] < $nd) { } 189 8 197
Condition100%3/3
@n < 2 and $n[0] < $nd
!ll&&!rl&&r
53189
MC/DC100%2/2
@n < 2 and $n[0] < $nd
@n < 2 $n[0] < $nd
Truth table100%3/3
A and B
A= @n < 2B= $n[0] < $nd
ABresult
0X0
100
111
1336 189 ▶ if( $ii =~/\-$/) { # 7(-)
Branch: 1 branch
BranchTrueFalseTotal
if ($ii =~ /\-$/) { } 18 171 189
1337  
1338 18 ▶ for( my $i = $n[0]; $i < $nd; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $nd) 51 18 69
1339 51 ▶ $end = &_s_a_prn( $i, $values, $el, $op, \$border, \$col ) and last;
Branch: 1 branch
BranchTrueFalseTotal
$end = &_s_a_prn($i, $values, $el, $op, \$border, \$col) and last 0 51 51
1340 }
1341  
1342 }
1343 else { # 4 || 0
1344 171 ▶ $end = &_s_a_prn( $n[0], $values, $el, $op, \$border, \$col ) and last;
Branch: 1 branch
BranchTrueFalseTotal
$end = &_s_a_prn($n[0], $values, $el, $op, \$border, \$col) and last 0 171 171
1345 }
1346  
1347 }
1348 else { # 1-3 ->(1..3) || 6-7-9 ->(6..9)
1349 8 ▶ for( my $i = $n[0]; $i <= $n[-1]; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $n[-1]) 15 6 21
1350 15 ▶ $end = &_s_a_prn( $i, $values, $el, $op, \$border, \$col ) and last;
Branch: 1 branch
BranchTrueFalseTotal
$end = &_s_a_prn($i, $values, $el, $op, \$border, \$col) and last 2 13 15
1351 }
1352 }
1353  
1354 197 ▶ last if $end;
Branch: 1 branch
BranchTrueFalseTotal
if $end 2 195 197
1355 }
1356  
1357 198 return( $col, $end );
1358 }
1359  
1360  
1361 124 ▶sub _var_output {
Subroutine _var_output: called CC=70 SCAR=44.4
1362 124 my( $key, $vardata, $columns, $op ) = @_;
1363 124 ▶ my $values = (ref $vardata eq 'HASH') ? $vardata->{ $key } : $vardata->[ $key ];
Branch: 1 branch
BranchTrueFalseTotal
ref $vardata eq 'HASH' ? : 109 15 124
1364  
1365 124 ▶ @$columns or return;
Branch: 1 branch
BranchTrueFalseTotal
@$columns or return 124 0 124
1366  
1367 124 my $end = 0;
1368  
1369 124 ▶ if( ref \$values eq 'SCALAR' or ref $values eq 'SCALAR') { # key => SCALAR
Branch: 1 branch
BranchTrueFalseTotal
if (ref \$values eq "SCALAR" or ref $values eq "SCALAR") 51 73 124
Condition100%3/3
ref \$values eq "SCALAR" or ref $values eq "SCALAR"
l!l&&r!l&&!r
48373
MC/DC100%2/2
ref \$values eq "SCALAR" or ref $values eq "SCALAR"
ref \$values eq "SCALAR" ref $values eq "SCALAR"
Truth table100%3/3
A or B
A= ref \$values eq "SCALAR"B= ref $values eq "SCALAR"
ABresult
1X1
011
000
1370 51 return &_hvt_print( $key, $values, $columns->[0], $op );
1371 }
1372  
1373 73 ▶ if( ref $values eq 'ARRAY') { # key => ARRAY
Branch: 2 branches
BranchTrueFalseTotal
if (ref $values eq 'ARRAY') { } 52 21 73
elsif (ref $values eq 'HASH') { } 21 0 21
1374  
1375 52 ▶ unless( @$values ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$values) 1 51 52
1376 1 ▶push @{$op->{logs}}, "~~> l.$. WARNING#7: empty ARRAY of %%%VAR:". $key if $op->{debug} or ! $op->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} or not $op->{"ignore"} 1 0 1
Condition33%1/3
$op->{"debug"} or not $op->{"ignore"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$op->{"debug"} or not $op->{"ignore"}
$op->{"debug"} not $op->{"ignore"}
Truth table33%1/3
A or not(B)
A= $op->{"debug"}B= not $op->{"ignore"}
ABresult
1X1
011
000
1377 1 return 0;
1378 }
1379  
1380 # Forming a table
1381 51 my $row = 0;
1382 51 my $nd = @$values;
1383  
1384 _var_output_M0:
1385 51 foreach my $d ( @$values ) { # loop through table rows
1386  
1387 131 ▶push @{$op->{logs}}, '--> Table row = '. $row if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 20 111 131
1388  
1389 131 my $col = 0;
1390 131 foreach my $el ( @$columns ) { # loop through table columns (for ARRAY.HASH) or rows (for ARRAY.SCALAR)
1391  
1392 453 my $ki = $el->{ki};
1393 453 ▶ my $border = ((! $row and ! $col) or ($row >= $#{ $values } and !(defined $ki and length $ki) ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!($row || $col) || $row >= $#{$values;} && !(defined $ki && length $ki) ? : 65 388 453
Condition91%11/12
not $row || $col or $row >= $#{$values;} and not defined $ki && length $ki
l!l&&r!l&&!r
5114388
$row || $col
l!l&&r!l&&!r
29710551
$row >= $#{$values;} and not defined $ki && length $ki
!ll&&!rl&&r
27910914
defined $ki && length $ki
!ll&&!rl&&r
140109
MC/DC80%4/5
not $row || $col or $row >= $#{$values;} and not defined $ki && length $ki
$row $col $row >= $#{$values;} defined $ki length $ki
Truth table77%7/9
not(A || B) or C and not(D && E)
A= $rowB= $colC= $row >= $#{$values;}D= defined $kiE= length $ki
ABCDEresult
00XXX1
1X10X1
1X1101
0110X1
011101
1X0XX0
1X1110
010XX0
011110
1394  
1395 453 my $val;
1396 453 ▶ if( defined $ki ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ki) { } 403 50 453
1397 403 ▶ if( $ki eq '%%%ADDA') {
Branch: 5 branches
BranchTrueFalseTotal
if ($ki eq '%%%ADDA') { } 7 396 403
elsif (ref \$d eq 'SCALAR' or ref $d eq 'SCALAR') { } 37 359 396
elsif (ref $d eq 'HASH') { } 185 174 359
elsif (ref $d eq 'ARRAY') { } 174 0 174
elsif ($op->{'def'}) { } 0 0 0
1398 7 $val = '';
1399 }
1400 ▶ elsif( ref \$d eq 'SCALAR' or ref $d eq 'SCALAR') { # (ARRAY.SCALAR or ARRAY.REF->SCALAR) in regular vector
Condition100%3/3
ref \$d eq "SCALAR" or ref $d eq "SCALAR"
l!l&&r!l&&!r
343359
MC/DC100%2/2
ref \$d eq "SCALAR" or ref $d eq "SCALAR"
ref \$d eq "SCALAR" ref $d eq "SCALAR"
Truth table100%3/3
A or B
A= ref \$d eq "SCALAR"B= ref $d eq "SCALAR"
ABresult
1X1
011
000
1401  
1402 37 ▶ if( $ki =~/^[\d,\-]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ki =~ /^[\d,\-]+$/) 37 0 37
1403 # mixed indices, e.g.: 1-3,6-7-9,-,4,-5,0,7- or 3- (i.e. 3..arr_end) or 0-5 (0..5) or -1- (-1,-2,..arr_start)
1404 37 ▶ last _var_output_M0 if $row;
Branch: 1 branch
BranchTrueFalseTotal
if $row 13 24 37
1405  
1406 24 ($_, $end) = &_mixed_indices( $ki, $values, $el, $op, $border );
1407 24 ▶ $col += $_ - 1 if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 22 2 24
1408 }
1409  
1410 24 ▶ $end ? last _var_output_M0 : next;
Branch: 1 branch
BranchTrueFalseTotal
$end ? : 2 22 24
1411 }
1412 elsif( ref $d eq 'HASH') { # ARRAY.HASH
1413 185 $val = $d->{$ki};
1414  
1415 185 ▶ if( defined( $val ) && ref $val eq 'ARRAY') { # ARRAY.HASH.ARRAY
Branch: 2 branches
BranchTrueFalseTotal
if (defined $val and ref $val eq 'ARRAY') { } 2 183 185
elsif (ref \$val ne 'SCALAR' and ref $val ne 'SCALAR') { } 1 364 365
Condition100%3/3
defined $val and ref $val eq "ARRAY"
!ll&&!rl&&r
151682
MC/DC100%2/2
defined $val and ref $val eq "ARRAY"
defined $val ref $val eq "ARRAY"
Truth table100%3/3
A and B
A= defined $valB= ref $val eq "ARRAY"
ABresult
0X0
100
111
1416 2 for my $vv ( @$val ) {
1417 14 ▶ next unless ref \$vv eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
unless ref \$vv eq "SCALAR" 0 14 14
1418  
1419 14 ▶ last _var_output_M0 if $end = &_hvt_print( $ki, $vv, $el, $op, $border );
Branch: 1 branch
BranchTrueFalseTotal
if $end = &_hvt_print($ki, $vv, $el, $op, $border) 0 14 14
1420 14 ++$col;
1421 }
1422  
1423 2 ▶ $end ? last _var_output_M0 : next;
Branch: 1 branch
BranchTrueFalseTotal
$end ? : 0 2 2
1424 }
1425 ▶ elsif( ref \$val ne 'SCALAR' and ref $val ne 'SCALAR') {
Condition66%2/3
ref \$val ne "SCALAR" and ref $val ne "SCALAR"
!ll&&!rl&&r
18201
MC/DC50%1/2
ref \$val ne "SCALAR" and ref $val ne "SCALAR"
ref \$val ne "SCALAR" ref $val ne "SCALAR"
Truth table66%2/3
A and B
A= ref \$val ne "SCALAR"B= ref $val ne "SCALAR"
ABresult
0X0
100
111
1426 1 next;
1427 }
1428 }
1429 elsif( ref $d eq 'ARRAY') { # ARRAY.ARRAY
1430  
1431 174 ▶ if( $ki =~/^[\d,\-]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ki =~ /^[\d,\-]+$/) 174 0 174
1432 # mixed indices, e.g.: 1-3,6-7-9,-,4,-5,0,7- or 3- (i.e. 3..arr_end) or 0-5 (0..5) or -1- (-1,-2,..arr_start)
1433 174 ($_, $end) = &_mixed_indices( $ki, $d, $el, $op, $border );
1434 174 ▶ $col += $_ - 1 if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 173 1 174
1435 }
1436  
1437 174 ▶ $end ? last _var_output_M0 : next;
Branch: 1 branch
BranchTrueFalseTotal
$end ? : 1 173 174
1438 }
1439 elsif( $op->{def} ) {
1440  
1441 0 ▶push @{$op->{logs}}, "~~> l.$. invalid data type of %%%V:". $ki if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 0 0 0
1442  
1443 0 next;
1444 }
1445 }
1446 else {
1447 # empty parameter -- at the very end of the columns (parameters)
1448 50 $ki = '';
1449 }
1450  
1451 239 ▶ last _var_output_M0 if $end = &_hvt_print( $ki, $val, $el, $op, $border );
Branch: 1 branch
BranchTrueFalseTotal
if $end = &_hvt_print($ki, $val, $el, $op, $border) 0 239 239
1452 }
1453 continue {
1454 437 ++$col;
1455 }
1456  
1457 115 ▶ last if $end;
Branch: 1 branch
BranchTrueFalseTotal
if $end 0 115 115
1458 }
1459 continue {
1460 115 ++$row;
1461 }
1462  
1463 }
1464 elsif( ref $values eq 'HASH') {
1465  
1466 21 my $col = 0;
1467 21 foreach my $el ( @$columns ) { # loop through parameters of %%%VAR-structure
1468  
1469 53 my $ki = $el->{ki};
1470 53 ▶ my $border = ( ! $col or ($col >= $#{ $columns } and (!defined( $ki ) or !length( $ki )) )) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!$col || $col >= $#{$columns;} && !(defined $ki && length $ki) ? : 23 30 53
Condition88%8/9
not $col or $col >= $#{$columns;} and not defined $ki && length $ki
l!l&&r!l&&!r
21230
$col >= $#{$columns;} and not defined $ki && length $ki
!ll&&!rl&&r
2282
defined $ki && length $ki
!ll&&!rl&&r
208
MC/DC75%3/4
not $col or $col >= $#{$columns;} and not defined $ki && length $ki
not $col $col >= $#{$columns;} defined $ki length $ki
Truth table80%4/5
not(A) or B and not(C && D)
A= not $colB= $col >= $#{$columns;}C= defined $kiD= length $ki
ABCDresult
1XXX1
010X1
01101
00XX0
01110
1471  
1472 53 my $val;
1473 53 ▶ if( defined $ki ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ki) { } 50 3 53
1474 50 ▶ if( $ki eq '%%%ADDA') {
Branch: 5 branches
BranchTrueFalseTotal
if ($ki eq '%%%ADDA') { } 3 47 50
elsif (ref \$values->{$ki} eq 'SCALAR' and !$op->{'def'} || defined $values->{$ki}) { } 37 10 47
elsif (ref $values->{$ki} eq 'SCALAR' and !$op->{'def'} || defined ${$$values{$ki};}) { } 1 9 10
elsif ($ki eq '@' and ref $values->{'@'} eq 'ARRAY') { } 3 6 9
elsif ($op->{'def'}) { } 6 0 6
1475 3 $val = '';
1476 }
1477 ▶ elsif( ref \$values->{$ki} eq 'SCALAR' and ( !$op->{def} or defined( $values->{$ki} ) ) ) { # HASH.SCALAR
Condition100%6/6
ref \$values->{$ki} eq "SCALAR" and !$op->{"def"} || defined $values->{$ki}
!ll&&!rl&&r
4637
not $op->{"def"} or defined $values->{$ki}
l!l&&r!l&&!r
7306
MC/DC100%3/3
ref \$values->{$ki} eq "SCALAR" and !$op->{"def"} || defined $values->{$ki}
ref \$values->{$ki} eq "SCALAR" not $op->{"def"} defined $values->{$ki}
Truth table100%4/4
A and not(B) or C
A= ref \$values->{$ki} eq "SCALAR"B= not $op->{"def"}C= defined $values->{$ki}
ABCresult
0XX0
1000
11X1
1011
1478 37 $val = $values->{$ki};
1479 }
1480 1 ▶ elsif( ref $values->{$ki} eq 'SCALAR' and ( !$op->{def} or defined( ${ $values->{$ki} } ) ) ) { # HASH.REF->SCALAR
Condition50%3/6
ref $values->{$ki} eq "SCALAR" and !$op->{"def"} || defined ${$$values{$ki};}
!ll&&!rl&&r
901
not $op->{"def"} or defined ${$$values{$ki};}
l!l&&r!l&&!r
010
MC/DC33%1/3
ref $values->{$ki} eq "SCALAR" and !$op->{"def"} || defined ${$$values{$ki};}
ref $values->{$ki} eq "SCALAR" not $op->{"def"} defined ${$$values{$ki};}
Truth table50%2/4
A and not(B) or C
A= ref $values->{$ki} eq "SCALAR"B= not $op->{"def"}C= defined ${$$values{$ki};}
ABCresult
0XX0
1000
11X1
1011
1481 1 $val = ${ $values->{$ki} };
1482 }
1483 ▶ elsif( $ki eq '@' and ref $values->{'@'} eq 'ARRAY') {
Condition66%2/3
$ki eq "\@" and ref $values->{"\@"} eq "ARRAY"
!ll&&!rl&&r
603
MC/DC50%1/2
$ki eq "\@" and ref $values->{"\@"} eq "ARRAY"
$ki eq "\@" ref $values->{"\@"} eq "ARRAY"
Truth table66%2/3
A and B
A= $ki eq "\@"B= ref $values->{"\@"} eq "ARRAY"
ABresult
0X0
100
111
1484 3 for my $k ( @{ $values->{'@'} } ) {
1485 13 ▶ next unless defined($k) && exists( $values->{$k} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k and exists $values->{$k} 2 11 13
Condition100%3/3
defined $k and exists $values->{$k}
!ll&&!rl&&r
1111
MC/DC100%2/2
defined $k and exists $values->{$k}
defined $k exists $values->{$k}
Truth table100%3/3
A and B
A= defined $kB= exists $values->{$k}
ABresult
0X0
100
111
1486  
1487 11 my $v;
1488 11 ▶ if( ref \$values->{$k} eq 'SCALAR') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref \$values->{$k} eq 'SCALAR') { } 9 2 11
elsif (ref $values->{$k} eq 'SCALAR') { } 1 1 2
elsif ($op->{'def'}) { } 1 0 1
1489 9 $v = $values->{$k};
1490 }
1491 elsif( ref $values->{$k} eq 'SCALAR') {
1492 1 $v = ${ $values->{$k} };
1493 }
1494 elsif( $op->{def} ) {
1495 0 ▶push @{$op->{logs}}, "-->\tl.$. ". 'NOT HASH.ARRAY.SCALAR %%%V:@->{'.$k.'} in %%%VAR:'. $key if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 0 1 1
1496  
1497 1 next;
1498 }
1499  
1500 10 ▶ last if $end = &_hvt_print( $k, $v, $el, $op, $border );
Branch: 1 branch
BranchTrueFalseTotal
if $end = &_hvt_print($k, $v, $el, $op, $border) 1 9 10
1501 9 $border = 0;
1502 }
1503  
1504 3 ▶ $end ? last : next;
Branch: 1 branch
BranchTrueFalseTotal
$end ? : 1 2 3
1505 }
1506 elsif( $op->{def} ) {
1507 0 ▶push @{$op->{logs}}, "~~> l.$. NOT HASH.SCALAR or NOT defined %%%V:". $ki if $op->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"debug"} 0 6 6
1508  
1509 6 next;
1510 }
1511 }
1512 else {
1513 # empty parameter -- at the very end of the columns (parameters)
1514 3 $ki = '';
1515 }
1516  
1517 44 ▶ last if $end = &_hvt_print( $ki, $val, $el, $op, $border );
Branch: 1 branch
BranchTrueFalseTotal
if $end = &_hvt_print($ki, $val, $el, $op, $border) 2 42 44
1518 }
1519 continue {
1520 50 ++$col;
1521 }
1522 }
1523  
1524 72 return $end;
1525 }
1526  
1527  
1528 70148 ▶sub _code2dec {
Subroutine _code2dec: called CC=7 SCAR=25.2
1529 70148 my @arr;
1530 70148 my $f16 = 0;
1531 70148 for my $h ( map{ hex } split /\s+/, $_[0] ) { # $codes
1532  
1533 70322 ▶ if( $h >= 0xD800 and $h <= 0xDBFF ) {# HIGH utf16 code
Branch: 2 branches
BranchTrueFalseTotal
if ($h >= 55296 and $h <= 56319) { } 0 70322 70322
elsif ($h >= 56320 and $h <= 57343) { } 0 70322 70322
Condition66%2/3
$h >= 55296 and $h <= 56319
!ll&&!rl&&r
53377169450
MC/DC0%0/2
$h >= 55296 and $h <= 56319
$h >= 55296 $h <= 56319
Truth table66%2/3
A and B
A= $h >= 55296B= $h <= 56319
ABresult
0X0
100
111
1534 0 push @arr, 0x10000 + (($h - 0xD800) << 10);
1535 0 $f16 = 1;
1536 }
1537 ▶ elsif( $h >= 0xDC00 and $h <= 0xDFFF ) { # LOW utf16 code
Condition66%2/3
$h >= 56320 and $h <= 57343
!ll&&!rl&&r
53377169450
MC/DC0%0/2
$h >= 56320 and $h <= 57343
$h >= 56320 $h <= 57343
Truth table66%2/3
A and B
A= $h >= 56320B= $h <= 57343
ABresult
0X0
100
111
1538 0 $h -= 0xDC00;
1539 0 ▶ if( $f16 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f16) { } 0 0 0
1540 0 $arr[-1] = $arr[-1] + $h;
1541 0 $f16 = 0;
1542 }
1543 else {
1544 0 push @arr, 0x10000 + $h;
1545 }
1546 }
1547 else {
1548 70322 push @arr, $h;
1549 70322 $f16 = 0;
1550 }
1551 }
1552  
1553 70148 return join ' ', @arr; # dec(s)
1554 }
1555  
1556  
1557 19610 ▶sub _code2sym {
Subroutine _code2sym: called CC=9 SCAR=28.1
1558 19610 my @arr;
1559 19610 my $f16 = 0;
1560 19610 for my $h ( map{ hex } split /\s+/, $_[0] ) { # $codes
1561  
1562 19697 ▶ if( $h >= 0xD800 and $h <= 0xDBFF ) {# HIGH utf16 code
Branch: 2 branches
BranchTrueFalseTotal
if ($h >= 55296 and $h <= 56319) { } 0 19697 19697
elsif ($h >= 56320 and $h <= 57343) { } 0 19697 19697
Condition66%2/3
$h >= 55296 and $h <= 56319
!ll&&!rl&&r
1516545320
MC/DC0%0/2
$h >= 55296 and $h <= 56319
$h >= 55296 $h <= 56319
Truth table66%2/3
A and B
A= $h >= 55296B= $h <= 56319
ABresult
0X0
100
111
1563 0 push @arr, 0x10000 + (($h - 0xD800) << 10);
1564 0 $f16 = 1;
1565 }
1566 ▶ elsif( $h >= 0xDC00 and $h <= 0xDFFF ) { # LOW utf16 code
Condition66%2/3
$h >= 56320 and $h <= 57343
!ll&&!rl&&r
1516545320
MC/DC0%0/2
$h >= 56320 and $h <= 57343
$h >= 56320 $h <= 57343
Truth table66%2/3
A and B
A= $h >= 56320B= $h <= 57343
ABresult
0X0
100
111
1567 0 $h -= 0xDC00;
1568 0 ▶ if( $f16 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f16) { } 0 0 0
1569 0 $arr[-1] = chr( $arr[-1] + $h );
1570 0 $f16 = 0;
1571 }
1572 else {
1573 0 push @arr, chr(0x10000 + $h);
1574 }
1575 }
1576 else {
1577 19697 ▶ $arr[-1] = chr( $arr[-1] ) if $f16;
Branch: 1 branch
BranchTrueFalseTotal
if $f16 0 19697 19697
1578 19697 push @arr, chr($h);
1579 19697 $f16 = 0;
1580 }
1581 }
1582 19610 ▶ $arr[-1] = chr( $arr[-1] ) if $f16;
Branch: 1 branch
BranchTrueFalseTotal
if $f16 0 19610 19610
1583  
1584 19610 return join '', @arr; # mate
1585 }
1586  
1587  
1588 301668 ▶sub _get_mate {
Subroutine _get_mate: called CC=6 SCAR=17.9
1589 301668 my( $glyph, $agl, $op ) = @_;
1590  
1591 301668 ▶ %$agl or return $glyph;
Branch: 1 branch
BranchTrueFalseTotal
%$agl or return $glyph 258675 42993 301668
1592  
1593 258675 ▶ return $agl->{ $glyph } if exists $agl->{ $glyph }; # && defined( $agl->{ $glyph } )
Branch: 1 branch
BranchTrueFalseTotal
if exists $agl->{$glyph} 166389 92286 258675
1594  
1595 92286 my $mate = $glyph;
1596  
1597 92286 ▶ if( $glyph =~/^uni([0-9A-F]{4}|[0-9A-F]{8})/ ) { # sprintf("uni0%X", $_)# , uniXXXX
Branch: 1 branch
BranchTrueFalseTotal
if ($glyph =~ /^uni([0-9A-F]{4}|[0-9A-F]{8})/) { } 92244 42 92286
1598 92244 my $code = $1;
1599  
1600 92244 ▶ if( $op->{mate} =~/^sym/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($op->{'mate'} =~ /^sym/) { } 15329 76915 92244
elsif ($op->{'mate'} =~ /^hex/) { } 15329 61586 76915
1601 15329 $mate = &_code2sym( $code );
1602 }
1603 elsif( $op->{mate} =~/^hex/) {
1604 15329 $mate = $code;
1605 }
1606 else { # dec
1607 61586 $mate = &_code2dec( $code );
1608 }
1609 }
1610 else {
1611 42 carp "Undefined glyph: '$glyph'";
1612 42 undef $mate;
1613 }
1614  
1615 92286 return $mate;
1616 }
1617  
1618 #-------------------
1619 # External functions
1620 #-------------------
1621 # Get kit/set of 'Adobe Glyph List'
1622 # $op->{glyphlist} -- Adobe Glyph List file: 'glyphlist.txt'
1623 # $op->{mate} = 'symbol' of Unicode | 'hex' Unicode number (native). By default, decimal Unicode number
1624  
1625 17 ▶sub AGLkit {
Subroutine AGLkit: called CC=22 SCAR=30.9
Pod documented
1626 17 my( $op ) = @_;
1627 17 my $agl = {};
1628  
1629 17 my $glyphtounicode_dump = module_file('LaTeX::Replicase', 'glyphtounicode.dump'); # LiveTeX file
1630 17 ▶ if( -e $glyphtounicode_dump ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $glyphtounicode_dump) { } 17 0 17
1631 17 $agl = retrieve $glyphtounicode_dump;
1632 }
1633 else {
1634 0 croak "Can't find the G2U file: '$glyphtounicode_dump'";
1635 }
1636  
1637 17 ▶ if( $op->{mate} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->{"mate"}) 8 9 17
1638 8 ▶ if( $op->{mate} =~/^sym/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($op->{'mate'} =~ /^sym/) { } 3 5 8
elsif ($op->{'mate'} =~ /^hex/) { } 3 2 5
1639  
1640 3 for my $v ( values %$agl ) {
1641 16518 $v = join '', map{ chr } split /\s+/, $v;
1642 }
1643 }
1644 elsif( $op->{mate} =~/^hex/) {
1645  
1646 3 for my $v ( values %$agl ) {
1647 16518 $v = join ' ', map{ sprintf("%04X", $_) } split /\s+/, $v;
1648 }
1649 }
1650 }
1651  
1652 17 ▶ $op->{glyphlist} or return $agl;
Branch: 1 branch
BranchTrueFalseTotal
$op->{"glyphlist"} or return $agl 5 12 17
1653  
1654 # Add classic Adobe Glyph List
1655 5 my $glyphfile = $op->{glyphlist};
1656  
1657 5 ▶ if( open my $AGL, '<', $glyphfile ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $AGL, '<', $glyphfile) { } 4 1 5
1658 4 ▶ while( <$AGL> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $AGL)) 17332 4 17336
1659 17332 ▶ next if /^\s*$/ or /^\s*#/; # skip empty and commented lines
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*$/ or /^\s*#/ 184 17148 17332
Condition100%3/3
/^\s*$/ or /^\s*#/
l!l&&r!l&&!r
817617148
MC/DC100%2/2
/^\s*$/ or /^\s*#/
/^\s*$/ /^\s*#/
Truth table100%3/3
A or B
A= /^\s*$/B= /^\s*#/
ABresult
1X1
011
000
1660  
1661 17148 my( $glyph, $codes ) = split /\s*;\s*/;
1662 17148 ▶ next unless $glyph && $codes;
Branch: 1 branch
BranchTrueFalseTotal
unless $glyph and $codes 8 17140 17148
Condition100%3/3
$glyph and $codes
!ll&&!rl&&r
4417140
MC/DC100%2/2
$glyph and $codes
$glyph $codes
Truth table100%3/3
A and B
A= $glyphB= $codes
ABresult
0X0
100
111
1663  
1664 17140 $glyph =~s/\s+//g;
1665 17140 $codes =~s/^\s+|\s+$//g;
1666  
1667 17140 ▶ next if $glyph =~/^\.notdef$/i or $glyph =~/[^\w.:\/\-]/o
Branch: 1 branch
BranchTrueFalseTotal
if $glyph =~ /^\.notdef$/i or $glyph =~ m[[^\w.:/\-]]o or length $codes < 4 or not $codes =~ /^[0-9A-Fa-f\t ]+$/o 16 17124 17140
Condition100%9/9
$glyph =~ /^\.notdef$/i or $glyph =~ m[[^\w.:/\-]]o or length $codes < 4 or not $codes =~ /^[0-9A-Fa-f\t ]+$/o
l!l&&r!l&&!r
12417124
$glyph =~ /^\.notdef$/i or $glyph =~ m[[^\w.:/\-]]o or length $codes < 4
l!l&&r!l&&!r
8417128
$glyph =~ /^\.notdef$/i or $glyph =~ m[[^\w.:/\-]]o
l!l&&r!l&&!r
4417132
MC/DC100%4/4
$glyph =~ /^\.notdef$/i or $glyph =~ m[[^\w.:/\-]]o or length $codes < 4 or not $codes =~ /^[0-9A-Fa-f\t ]+$/o
$glyph =~ /^\.notdef$/i $glyph =~ m[[^\w.:/\-]]o length $codes < 4 not $codes =~ /^[0-9A-Fa-f\t ]+$/o
Truth table100%5/5
A or B or C or not(D)
A= $glyph =~ /^\.notdef$/iB= $glyph =~ m[[^\w.:/\-]]oC= length $codes < 4D= not $codes =~ /^[0-9A-Fa-f\t ]+$/o
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1668 or length( $codes ) < 4 or $codes !~/^[0-9A-Fa-f\t ]+$/o;
1669  
1670 17124 my $mate;
1671 17124 ▶ if( $op->{mate} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->{"mate"}) 12843 4281 17124
1672 12843 ▶ if( $op->{mate} =~/^sym/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($op->{'mate'} =~ /^sym/) { } 4281 8562 12843
elsif ($op->{'mate'} =~ /^hex/) { } 4281 4281 8562
1673 4281 $mate = &_code2sym( $codes );
1674 }
1675 elsif( $op->{mate} =~/^hex/) {
1676 4281 ($mate = $codes) =~s/\s+/ /g;
1677 4281 $mate = uc $mate;
1678 }
1679 }
1680  
1681 17124 ▶ $agl->{ $glyph } = $mate // &_code2dec( $codes ); # By default, decimal Unicode number
Condition66%2/3
$mate // &_code2dec($codes)
l!l&&r!l&&!r
856285620
MC/DC0%0/2
$mate // &_code2dec($codes)
$mate &_code2dec($codes)
Truth table66%2/3
A // B
A= $mateB= &_code2dec($codes)
ABresult
1X1
011
000
1682 }
1683  
1684 4 close $AGL;
1685 }
1686 else {
1687 1 carp "Can't find the AGL file: '$glyphfile'";
1688 }
1689  
1690 5 return $agl;
1691 }
1692  
1693 # Get font metrics from Adobe Font Metric file
1694 # IN:
1695 # $op->{glyphlist} -- glyphlist file
1696 # $op->{noBbox} -- without 'B'-box
1697 # $op->{noKPX} -- without 'KPX'
1698 # $op->{mate} = 'glyph' of Adobe | 'symbol' of Unicode | 'hex' Unicode number (native). By default, decimal Unicode number
1699 # OUT:
1700 # $font_metrics->
1701 # {WX}{ $mate } -- symbol width of mate
1702 # {Bbox}{ $mate } -- Bounding Box of mate
1703 # {KPX}{ $mateA }{ $mateB } -- paired kerning of mateA & mateB
1704  
1705 9 ▶sub font_metrics {
Subroutine font_metrics: called CC=20 SCAR=30.1
Pod documented
1706 9 my( $AFMfile, $op ) = @_;
1707  
1708 9 ▶ $op->{mate} //= '';
Condition100%2/2
$op->{"mate"} //= ""
l!l
54
MC/DC100%1/1
$op->{"mate"} //= ""
$op->{"mate"}
Truth table100%2/2
A
A= $op->{"mate"}
Aresult
11
00
1709 9 ▶ my $agl = ($op->{mate} =~/^glyph/) ? {} : &AGLkit( $op );
Branch: 1 branch
BranchTrueFalseTotal
$op->{'mate'} =~ /^glyph/ ? : 1 8 9
1710  
1711 9 my %font_metrics;
1712  
1713 9 ▶ open( my $AFM, '<', $AFMfile ) or croak "Can't find the AFM file: $AFMfile";
Branch: 1 branch
BranchTrueFalseTotal
open my $AFM, "<", $AFMfile or croak("Can't find the AFM file: $AFMfile") 8 1 9
1714 8 ▶ while( <$AFM> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $AFM)) 177456 1 177457
1715 177456 ▶ if( /^StartCharMetrics/i .. /^EndCharMetrics/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^StartCharMetrics/i .. /^EndCharMetrics/i) 5760 171696 177456
1716 5760 ▶ /^CH?\s/ or next; # only lines that start with "C" or "CH" are parsed
Branch: 1 branch
BranchTrueFalseTotal
/^CH?\s/ or next 5744 16 5760
1717  
1718 # C 32 ; WX 300 ; N space ; B 0 0 0 0 ;
1719 5744 ▶ /;\s*WX\s*(\d+)\s*;\s*N\s+([\w.:\/\-]+)\s*;/ or next;
Branch: 1 branch
BranchTrueFalseTotal
m[;\s*WX\s*(\d+)\s*;\s*N\s+([\w.:/\-]+)\s*;] or next 5736 8 5744
1720 5736 my( $wx, $glyph ) = ($1, $2);
1721  
1722 5736 ▶ my $bbox = /;\s*B\s*([^;]+)\s*;/ ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
/;\s*B\s*([^;]+)\s*;/ ? : 5736 0 5736
1723 5736 $bbox =~ s/\s+/ /g;
1724 5736 $bbox =~ s/^\s+|\s+$//g;
1725  
1726 5736 my $mate = &_get_mate( $glyph, $agl, $op );
1727  
1728 5736 ▶ if( defined $mate ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mate) 5694 42 5736
1729 5694 $font_metrics{WX}{ $mate } = $wx;
1730 5694 ▶ $op->{noBbox} or $font_metrics{Bbox}{ $mate } = $bbox; # 'B'-box
Branch: 1 branch
BranchTrueFalseTotal
$op->{"noBbox"} or $font_metrics{"Bbox"}{$mate} = $bbox 2844 2850 5694
1731 }
1732  
1733 5736 next;
1734 }
1735  
1736 171696 ▶ next if $op->{noKPX}; # without 'KPX'
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"noKPX"} 21462 150234 171696
1737  
1738 150234 ▶ if( /^StartKernPairs/i .. /^EndKernPairs/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^StartKernPairs/i .. /^EndKernPairs/i) 150052 182 150234
1739 150052 ▶ /^KPX\s/ or next; # only lines that start with "KPX" are parsed
Branch: 1 branch
BranchTrueFalseTotal
/^KPX\s/ or next 147973 2079 150052
1740  
1741 # KPX space A -55
1742 147973 my( undef, $glyphA, $glyphB, $kpx ) = split /\s+/o;
1743  
1744 147973 $kpx =~y/0-9-//cd;
1745 147973 ▶ $kpx or next;
Branch: 1 branch
BranchTrueFalseTotal
$kpx or next 147966 7 147973
1746  
1747 147966 my $mateA = &_get_mate( $glyphA, $agl, $op );
1748 147966 my $mateB = &_get_mate( $glyphB, $agl, $op );
1749  
1750 $font_metrics{KPX}{ $mateA }{ $mateB } ||= $kpx
1751 147966 ▶ if defined( $mateA ) && defined( $mateB ) && ! exists( $font_metrics{KPX}{ $mateA }{ $mateB } );
Branch: 1 branch
BranchTrueFalseTotal
if defined $mateA and defined $mateB and not exists $font_metrics{"KPX"}{$mateA}{$mateB} 143142 4824 147966
Condition44%4/9
defined $mateA and defined $mateB and not exists $font_metrics{"KPX"}{$mateA}{$mateB}
!ll&&!rl&&r
04824143142
defined $mateA and defined $mateB
!ll&&!rl&&r
00147966
$font_metrics{"KPX"}{$mateA}{$mateB} ||= $kpx
l!l&&r!l&&!r
01431420
MC/DC33%1/3
defined $mateA and defined $mateB and not exists $font_metrics{"KPX"}{$mateA}{$mateB}
defined $mateA defined $mateB not exists $font_metrics{"KPX"}{$mateA}{$mateB}
MC/DC0%0/2
$font_metrics{"KPX"}{$mateA}{$mateB} ||= $kpx
$font_metrics{"KPX"}{$mateA}{$mateB} $kpx
Truth table50%2/4
A and B and not(C)
A= defined $mateAB= defined $mateBC= not exists $font_metrics{"KPX"}{$mateA}{$mateB}
ABCresult
0XX0
10X0
1100
1111
Truth table33%1/3
A ||= B
A= $font_metrics{"KPX"}{$mateA}{$mateB}B= $kpx
ABresult
1X1
011
000
1752  
1753 147966 next;
1754 }
1755  
1756 182 ▶ last if /^EndFontMetrics/;
Branch: 1 branch
BranchTrueFalseTotal
if /^EndFontMetrics/ 7 175 182
1757 }
1758 8 close $AFM;
1759  
1760 8 return \%font_metrics;
1761 }
1762  
1763  
1764 # IN:
1765 # $str -- string (strand)
1766 # $op->
1767 # {cell_width} -- width of cell/box (pt).
1768 # {font_metrics} -- table of font metrics with {WX} key -- for decimal Unicode number, and {KPX} key -- for paired kerning.
1769 # {documentclass} -- name of \documentclass. By default, 'classic', i.e. 'article' or 'report' or 'book' or 'letter'
1770 # {base_font_size} -- depending on the document's base font size (pt), see \documentclass[...pt].
1771 # {font_size} -- TeX-font size of text in cell/box, e.g. 'small', 'normalsize', 'large', etc.
1772 # {shrink} -- space compressibility (the extent to which a space can become narrower than its base value if the line is compressed).
1773 # {merge} = 1 -- return a combined string (paragraph) and its total width (length) in (pt), rather than an array of strings.
1774 # {offset} -- offset from the beginning of $str from which characters for cell are extracted. By default, 0.
1775 # {limit} -- the maximum allowable number of lines for a cell.
1776 # {hyphenation} => # a array of methods for hyphenating words in specified languages, e.g.:
1777 # [
1778 # { name =>'en', action => $hyp_en, },
1779 # { name =>'ru', action => $hyp_ru, },
1780 # ]
1781 # OR
1782 # [
1783 # { msk => qr/[a-zA-Z]+/o, action => $hyp_en, },
1784 # { msk => qr/[а-яА-Я]+/o, action => $hyp_ru, },
1785 # ]
1786  
1787 # OUT:
1788 # HASH with keys:
1789 # 'lines' -- array of no empty lines.
1790 # 'wxL' -- array of line widths (*100pt) from 'lines', standardized to 'base_font_size'=10pt and 'font_size'='normalsize'.
1791 # 'scale' -- of font standardization.
1792 # 'numL' -- number of no empty lines.
1793 # 'stop' -- position in $str where the extraction of symbols into cell stopped.
1794 # If all non-whitespace characters have been extracted from $str and 'limit' option is specified, then '-1' is returned.
1795 # or
1796 # SCALAR is number of lines
1797  
1798 115 ▶sub onecell {
Subroutine onecell: called CC=145 SCAR=49.8
Pod documented
1799 115 ▶ return if ! defined( $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[0] or ref \$_[0] ne "SCALAR" or not $_[1] or ref $_[1] ne "HASH" 4 111 115
Condition100%9/9
not defined $_[0] or ref \$_[0] ne "SCALAR" or not $_[1] or ref $_[1] ne "HASH"
l!l&&r!l&&!r
31111
not defined $_[0] or ref \$_[0] ne "SCALAR" or not $_[1]
l!l&&r!l&&!r
21112
not defined $_[0] or ref \$_[0] ne "SCALAR"
l!l&&r!l&&!r
11113
MC/DC100%4/4
not defined $_[0] or ref \$_[0] ne "SCALAR" or not $_[1] or ref $_[1] ne "HASH"
not defined $_[0] ref \$_[0] ne "SCALAR" not $_[1] ref $_[1] ne "HASH"
Truth table100%5/5
not(A) or B or not(C) or D
A= not defined $_[0]B= ref \$_[0] ne "SCALAR"C= not $_[1]D= ref $_[1] ne "HASH"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1800 or ref \$_[0] ne 'SCALAR'
1801 or ! $_[1]
1802 or ref $_[1] ne 'HASH';
1803  
1804 111 my $ArSc = wantarray;
1805  
1806 111 my $op = $_[1];
1807  
1808 111 ▶ if( $_[0] =~/^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\s*$/) 4 107 111
1809 4 ▶ return $ArSc ? {lines => [ $_[0] ], wxL => [0], numL => 0, stop => 0, scale => undef, } : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ArSc ? : 3 1 4
1810 }
1811  
1812 107 ▶ $op->{cell_width} or croak "Cell width is NOT specified!";
Branch: 1 branch
BranchTrueFalseTotal
$op->{"cell_width"} or croak("Cell width is NOT specified!") 105 2 107
1813  
1814 105 ▶ my $offset = $op->{offset} // 0;
Condition100%2/2
$op->{"offset"} // 0
l!l
978
MC/DC100%1/1
$op->{"offset"} // 0
$op->{"offset"}
Truth table100%2/2
A
A= $op->{"offset"}
Aresult
11
00
1815 105 my $szStr = length $_[0];
1816  
1817 105 ▶ return if $offset < 0 or $offset >= $szStr;
Branch: 1 branch
BranchTrueFalseTotal
if $offset < 0 or $offset >= $szStr 3 102 105
Condition100%3/3
$offset < 0 or $offset >= $szStr
l!l&&r!l&&!r
12102
MC/DC100%2/2
$offset < 0 or $offset >= $szStr
$offset < 0 $offset >= $szStr
Truth table100%3/3
A or B
A= $offset < 0B= $offset >= $szStr
ABresult
1X1
011
000
1818  
1819 102 our( $q, $glue );
1820 102 my $Aa = qr/^[\p{Alpha}\-]+$/o;
1821  
1822 102 ▶ my $limit = $op->{limit} // 0;
Condition100%2/2
$op->{"limit"} // 0
l!l
8814
MC/DC100%1/1
$op->{"limit"} // 0
$op->{"limit"}
Truth table100%2/2
A
A= $op->{"limit"}
Aresult
11
00
1823 102 $limit += 0;
1824 102 ▶ $limit = 0 if $limit < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $limit < 0 5 97 102
1825  
1826 # font character width table
1827 102 ▶ my $symWX = $op->{font_metrics}{WX} or croak "Font metrics are NOT specified!";
Branch: 1 branch
BranchTrueFalseTotal
my $symWX = $op->{"font_metrics"}{"WX"} or croak("Font metrics are NOT specified!") 100 2 102
1828 100 ▶ my $symKPX = $op->{font_metrics}{KPX} || {};
Condition100%2/2
$op->{'font_metrics'}{'KPX'} || {}
l!l
955
MC/DC100%1/1
$op->{'font_metrics'}{'KPX'} || {}
$op->{'font_metrics'}{'KPX'}
Truth table100%2/2
A
A= $op->{'font_metrics'}{'KPX'}
Aresult
11
00
1829  
1830 100 ▶ my $space = ($op->{space} // 0) * 100 || $symWX->{32} or croak "Base whitespace width is NOT specified!";
Branch: 1 branch
BranchTrueFalseTotal
my $space = ($op->{"space"} // 0) * 100 || $symWX->{32} or croak("Base whitespace width is NOT specified!") 98 2 100
Condition100%5/5
($op->{'space'} // 0) * 100 || $symWX->{'32'}
l!l&&r!l&&!r
9082
$op->{"space"} // 0
l!l
9010
MC/DC100%2/2
($op->{'space'} // 0) * 100 || $symWX->{'32'}
$op->{"space"} $symWX->{'32'}
Truth table100%3/3
A || B
A= $op->{"space"}B= $symWX->{'32'}
ABresult
1X1
011
000
1831 98 ▶ $space -= ($op->{shrink} // 0) * 100; # reduce by the maximum whitespace compression, if specified
Condition100%2/2
$op->{"shrink"} // 0
l!l
944
MC/DC100%1/1
$op->{"shrink"} // 0
$op->{"shrink"}
Truth table100%2/2
A
A= $op->{"shrink"}
Aresult
11
00
1832 98 ▶ my $spcKPX = $symKPX->{32} || {}; # paired kerning for whitespace
Condition100%2/2
$symKPX->{'32'} || {}
l!l
935
MC/DC100%1/1
$symKPX->{'32'} || {}
$symKPX->{'32'}
Truth table100%2/2
A
A= $symKPX->{'32'}
Aresult
11
00
1833  
1834 98 my $hyphen = $symWX->{45}; # ord('-') -- hyphen width
1835 98 my $wideS = $symWX->{64}; # ord('@') -- width of the average-to-maximum-width character
1836  
1837 98 our $fontSizeTeX;
1838 98 our $refHypMsk;
1839  
1840 98 ▶ my $font_id = $fontSizeTeX->{names}{ $op->{font_size} || 'normalsize'}; # for 'normalsize' = 4
Condition100%2/2
$op->{'font_size'} || 'normalsize'
l!l
7325
MC/DC100%1/1
$op->{'font_size'} || 'normalsize'
$op->{'font_size'}
Truth table100%2/2
A
A= $op->{'font_size'}
Aresult
11
00
1841 98 ▶ my $base_font_size = $op->{base_font_size} || 10; # base document font size (pt)
Condition100%2/2
$op->{'base_font_size'} || 10
l!l
2870
MC/DC100%1/1
$op->{'base_font_size'} || 10
$op->{'base_font_size'}
Truth table100%2/2
A
A= $op->{'base_font_size'}
Aresult
11
00
1842  
1843 98 ▶ my $documentclass = $op->{documentclass} || 'classic';
Condition100%2/2
$op->{'documentclass'} || 'classic'
l!l
1682
MC/DC100%1/1
$op->{'documentclass'} || 'classic'
$op->{'documentclass'}
Truth table100%2/2
A
A= $op->{'documentclass'}
Aresult
11
00
1844 98 for( $documentclass ) {
1845 98 ▶ if( /^(?:article|report|book|letter|classic)$/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^(?:article|report|book|letter|classic)$/i) { } 83 15 98
elsif (/^ext(?:article|report|book|sizes)$/i) { } 1 14 15
1846 83 $_ = 'classic';
1847 }
1848 elsif( /^ext(?:article|report|book|sizes)$/i ) {
1849 1 $_ = 'extsizes';
1850 }
1851 else {
1852 14 $_ = 'classic';
1853 }
1854  
1855 98 ▶ $base_font_size = 10 unless exists $fontSizeTeX->{$_}{ $base_font_size };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $LaTeX::Replicase::fontSizeTeX->{$_}{$base_font_size} 2 96 98
1856 }
1857  
1858 # cell-to-'normalsize' scaling factor
1859 my $scale = ( $font_id == 4) ?
1860 1 :
1861 98 ▶ $fontSizeTeX->{ $documentclass }{ $base_font_size }[4] / $fontSizeTeX->{ $documentclass }{ $base_font_size }[ $font_id ]; # to 'normalsize'
Branch: 1 branch
BranchTrueFalseTotal
$font_id == 4 ? : 95 3 98
1862  
1863 98 my $cell_width = $op->{cell_width} * $scale * 100; # scale the cell width to 'normalsize' (*100pt)
1864  
1865 98 my @lines = (''); # cell/box with filled lines
1866 98 my @wxL; # line width (*100pt)
1867 98 my $numL = 0; # number of lines
1868  
1869 98 my $prevKPX = {}; # KPX previous (prev) symbol
1870 98 my $curKPX = {}; # KPX current (cur) symbol
1871 98 my $curSize = 0; # width of current (fillable) string
1872  
1873 98 my $yhp = 0; # > 0 -- flag for the presence/necessity of hyphenation in $word:
1874 # 1 -- hyphenation method(s) is specified;
1875 # 2 -- hyphenation points have already been inserted in the word;
1876 # 3 -- short word (<4 characters) | 4 -- word NOT found | 5 -- NO hyphens
1877  
1878 # checking for the presence of method(s) for hyphenating words
1879 98 ▶ if( $_ = $op->{hyphenation}
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $op->{"hyphenation"} and ref $_ eq "ARRAY" and @$_) 86 12 98
Condition100%6/6
$_ = $op->{"hyphenation"} and ref $_ eq "ARRAY" and @$_
!ll&&!rl&&r
8486
$_ = $op->{"hyphenation"} and ref $_ eq "ARRAY"
!ll&&!rl&&r
4490
MC/DC100%3/3
$_ = $op->{"hyphenation"} and ref $_ eq "ARRAY" and @$_
$_ = $op->{"hyphenation"} ref $_ eq "ARRAY" @$_
Truth table100%4/4
A and B and C
A= $_ = $op->{"hyphenation"}B= ref $_ eq "ARRAY"C= @$_
ABCresult
0XX0
10X0
1100
1111
1880 and ref $_ eq 'ARRAY'
1881 and @$_
1882 ) {
1883 86 my $hyp = $_;
1884 86 @$hyp = grep{ ( ($_->{msk} or ( $_->{name} && exists( $refHypMsk->{lc $_->{name}} ) ))
1885 && exists( $_->{action} )
1886 && ( ref( $_->{action} ) eq 'CODE'
1887 174 ▶ or ( ref( $_->{action} ) =~/::Hyphen/ and $_->{action}->can('hyphenate') )
Condition61%11/18
($_->{'msk'} || $_->{'name'} && exists $$LaTeX::Replicase::refHypMsk{lc $_->{'name'}}) && exists $_->{'action'} && (ref $_->{'action'} eq 'CODE' || ref($_->{'action'}) =~ /::Hyphen/ && $_->{'action'}->can('hyphenate'))
!ll&&!rl&&r
20172
$_->{"msk"} || $_->{"name"} && exists $$LaTeX::Replicase::refHypMsk{lc $_->{"name"}} and exists $_->{"action"}
!ll&&!rl&&r
20172
$_->{"msk"} or $_->{"name"} and exists $$LaTeX::Replicase::refHypMsk{lc $_->{"name"}}
l!l&&r!l&&!r
83892
$_->{"name"} and exists $$LaTeX::Replicase::refHypMsk{lc $_->{"name"}}
!ll&&!rl&&r
0289
ref $_->{"action"} eq "CODE" or ref($_->{"action"}) =~ /::Hyphen/ and $_->{"action"}->can("hyphenate")
l!l&&r!l&&!r
01720
ref($_->{"action"}) =~ /::Hyphen/ and $_->{"action"}->can("hyphenate")
!ll&&!rl&&r
00172
MC/DC28%2/7
($_->{'msk'} || $_->{'name'} && exists $$LaTeX::Replicase::refHypMsk{lc $_->{'name'}}) && exists $_->{'action'} && (ref $_->{'action'} eq 'CODE' || ref($_->{'action'}) =~ /::Hyphen/ && $_->{'action'}->can('hyphenate'))
$_->{"msk"} $_->{"name"} exists $$LaTeX::Replicase::refHypMsk{lc $_->{"name"}} exists $_->{"action"} ref $_->{"action"} eq "CODE" ref($_->{"action"}) =~ /::Hyphen/ $_->{"action"}->can("hyphenate")
Truth table25%3/12
A or B and C and D && E or F and G
A= $_->{"msk"}B= $_->{"name"}C= exists $$LaTeX::Replicase::refHypMsk{lc $_->{"name"}}D= exists $_->{"action"}E= ref $_->{"action"} eq "CODE"F= ref($_->{"action"}) =~ /::Hyphen/G= $_->{"action"}->can("hyphenate")
ABCDEFGresult
00XXXXX0
010XXXX0
1XX0XXX0
0110XXX0
1XX100X0
1XX10100
011100X0
01110100
1XX11XX1
1XX10111
01111XX1
01110111
1888 )
1889 ) } @$hyp;
1890  
1891 86 ▶ $yhp = @$hyp ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$hyp ? : 86 0 86
1892 }
1893  
1894 98 pos $_[0] = $offset;
1895 98 my $stop = $offset;
1896 98 my $new; # 1 = new sequence
1897  
1898 _onecell_M0:
1899 98 ▶ while( $_[0] =~/(\S+)/g ) { # extracting character words from input string
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /(\S+)/g) 668 34 702
1900 668 $_ = $1;
1901 668 $stop = pos $_[0];
1902 668 $new = 1;
1903  
1904 668 my @cage = grep{ length } split /([\p{Alpha}\-]{4,})/; # to split words into alphabetic and non-alphabetic words
1905  
1906 668 ▶ $yhp &&= 1;
Condition100%2/2
$yhp &&= 1
!ll
174494
MC/DC100%1/1
$yhp &&= 1
$yhp
Truth table100%2/2
A
A= $yhp
Aresult
00
11
1907  
1908 668 ▶ while( defined( my $word = shift @cage ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $word = shift @cage)) 1050 604 1654
1909  
1910 1310 my $szl = length $lines[-1];
1911  
1912 1310 my $alpha; # 1 -- alphabetic word
1913 1310 ▶ if( $word =~/$Aa/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /$Aa/) { } 1205 105 1310
1914 1205 $alpha = 1;
1915 }
1916 else {
1917 105 $alpha = 0;
1918 105 ▶ $yhp &&= 1; # Reset settings
Condition100%2/2
$yhp &&= 1
!ll
1887
MC/DC100%1/1
$yhp &&= 1
$yhp
Truth table100%2/2
A
A= $yhp
Aresult
00
11
1919 }
1920  
1921 1310 my $delta = $cell_width - $curSize;
1922  
1923 # in a cell line, there are preceding word(s), and this is not a fragment
1924 1310 ▶ $delta -= $space if $szl
Branch: 1 branch
BranchTrueFalseTotal
if $szl and $new || !~~@cage and not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/ 569 741 1310
Condition100%9/9
$szl and $new || !~~@cage and not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
!ll&&!rl&&r
607134569
$szl and $new || !~~@cage
!ll&&!rl&&r
365242703
$new or not ~~@cage
l!l&&r!l&&!r
569134242
MC/DC50%2/4
$szl and $new || !~~@cage and not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
$szl $new not ~~@cage not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
Truth table66%4/6
A and B or not(C) and not(D)
A= $szlB= $newC= not ~~@cageD= not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
1925 and ($new or ! ~~@cage)
1926 and $lines[-1] !~/(?:\\-|$q)$/;
1927  
1928 1310 my $wS; # width of current symbol (*100pt)
1929 my $wH; # width of hyphen taking pair kerning into account (*100pt)
1930 1310 my $wW = 0; # width of word/fragment (*100pt)
1931 1310 my $f = 1; # flag that the word fits into a cell line
1932 1310 my $nS = 0; # ordinal number (position) of symbol in word
1933  
1934 1310 my @ss = split //, $word;
1935  
1936 # to split word into symbols and get its decimal ID
1937 1310 foreach my $sid ( map{ ord($_) } @ss ) { # current symbol id
1938 4010 ▶ $wH = @cage ? $hyphen : 0;
Branch: 1 branch
BranchTrueFalseTotal
@cage ? : 1127 2883 4010
1939  
1940 4010 ▶ if( exists $symWX->{ $sid } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $symWX->{$sid}) { } 4005 5 4010
1941 4005 $wS = $symWX->{ $sid };
1942 4005 ▶ $curKPX = $symKPX->{ $sid } || {};
Condition100%2/2
$symKPX->{$sid} || {}
l!l
19412064
MC/DC100%1/1
$symKPX->{$sid} || {}
$symKPX->{$sid}
Truth table100%2/2
A
A= $symKPX->{$sid}
Aresult
11
00
1943  
1944 # to take pair kerning into account: prev+cur
1945 4005 ▶ $wS += $prevKPX->{ $sid } // 0;
Condition100%2/2
$prevKPX->{$sid} // 0
l!l
4273578
MC/DC100%1/1
$prevKPX->{$sid} // 0
$prevKPX->{$sid}
Truth table100%2/2
A
A= $prevKPX->{$sid}
Aresult
11
00
1946 4005 ▶ $wH += $curKPX->{45} // 0 if @cage; # for cur+hyphen
Branch: 1 branch
BranchTrueFalseTotal
if @cage 1127 2878 4005
Condition100%2/2
$curKPX->{45} // 0
l!l
142985
MC/DC100%1/1
$curKPX->{45} // 0
$curKPX->{45}
Truth table100%2/2
A
A= $curKPX->{45}
Aresult
11
00
1947 }
1948 else {
1949 5 carp 'Undefined width for symbol with hexcode: '. sprintf("%04X", $sid);
1950 5 $wS = $wideS;
1951 5 $curKPX = {};
1952 }
1953  
1954 # say "1=> word='$word', symbol='". chr($sid) ."', curSize=$curSize, delta=$delta, wW=$wW, wS=$wS, nS=$nS, f=$f, yhp=$yhp, cage=".~~@cage;
1955 # say Dumper \@cage;
1956  
1957 # ehto: 'bykvennuj fragment/slovo' i 'ne poslednjaja bykva' i 'sledyjywhij fragment tozhe bykvennuj'
1958 4010 ▶ my $cnd = ($alpha && ($nS < $#ss or (@cage && $cage[0] =~/$Aa/)) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$alpha && ($nS < $#ss || @cage && $cage[0] =~ /$Aa/) ? : 3206 804 4010
Condition100%9/9
$alpha and $nS < $#ss || @cage && $cage[0] =~ /$Aa/
!ll&&!rl&&r
1546503206
$nS < $#ss or @cage and $cage[0] =~ /$Aa/
l!l&&r!l&&!r
2962244650
@cage and $cage[0] =~ /$Aa/
!ll&&!rl&&r
58664244
MC/DC100%4/4
$alpha and $nS < $#ss || @cage && $cage[0] =~ /$Aa/
$alpha $nS < $#ss @cage $cage[0] =~ /$Aa/
Truth table100%5/5
A and B or C and D
A= $alphaB= $nS < $#ssC= @cageD= $cage[0] =~ /$Aa/
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1959  
1960 # symbol width or (+hyphen) > cell width
1961 4010 ▶ if( $wS > $cell_width
Branch: 1 branch
BranchTrueFalseTotal
if ($wS > $cell_width or $cnd and $wS + $wH > $cell_width) 64 3946 4010
Condition100%6/6
$wS > $cell_width or $cnd and $wS + $wH > $cell_width
l!l&&r!l&&!r
5863946
$cnd and $wS + $wH > $cell_width
!ll&&!rl&&r
76731796
MC/DC100%3/3
$wS > $cell_width or $cnd and $wS + $wH > $cell_width
$wS > $cell_width $cnd $wS + $wH > $cell_width
Truth table100%4/4
A or B and C
A= $wS > $cell_widthB= $cndC= $wS + $wH > $cell_width
ABCresult
1XX1
0111
00X0
0100
1962 or ($cnd and $wS + $wH > $cell_width)
1963 ) {
1964 64 $f = -1;
1965 64 last;
1966 }
1967  
1968 # width of fragment > remaining (unfilled portion) cell width
1969 3946 ▶ if( $wW + $wS > $delta
Branch: 1 branch
BranchTrueFalseTotal
if ($wW + $wS > $delta or $cnd and $wW + $wS + $wH > $delta) 375 3571 3946
Condition100%6/6
$wW + $wS > $delta or $cnd and $wW + $wS + $wH > $delta
l!l&&r!l&&!r
316593571
$cnd and $wW + $wS + $wH > $delta
!ll&&!rl&&r
707286459
MC/DC100%3/3
$wW + $wS > $delta or $cnd and $wW + $wS + $wH > $delta
$wW + $wS > $delta $cnd $wW + $wS + $wH > $delta
Truth table100%4/4
A or B and C
A= $wW + $wS > $deltaB= $cndC= $wW + $wS + $wH > $delta
ABCresult
1XX1
0111
00X0
0100
1970 or ($cnd and $wW + $wS + $wH > $delta)
1971 ) {
1972 375 $f = 0;
1973 375 last;
1974 }
1975  
1976 3571 $wW += $wS;
1977 3571 $prevKPX = $curKPX; # for pair kerning next symbol
1978 3571 ++$nS;
1979 }
1980 1310 ▶ $numL ||= 1; # JIC
Condition100%2/2
$numL ||= 1
l!l
121298
MC/DC100%1/1
$numL ||= 1
$numL
Truth table100%2/2
A
A= $numL
Aresult
11
00
1981  
1982 1310 ▶ if( $f > 0 ) { # word (or fragment) is placed into the cell line in its entirety
Branch: 1 branch
BranchTrueFalseTotal
if ($f > 0) 871 439 1310
1983 871 ▶ if( $szl && $lines[-1] !~/(?:\\-|$q)$/ ) { # there is prev.word(s) in the cell line and it is not fragment
Branch: 1 branch
BranchTrueFalseTotal
if ($szl and not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/) 390 481 871
Condition100%3/3
$szl and not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
!ll&&!rl&&r
281200390
MC/DC100%2/2
$szl and not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
$szl not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
Truth table100%3/3
A and not(B)
A= $szlB= not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
ABresult
0X0
100
111
1984
1985 # add whitespace for prev.word
1986 390 $curSize += $space; # + ($prevKPX->{32} // 0);
1987 390 $lines[-1] .= ' ';
1988 }
1989  
1990 # add cur.word in cell line
1991 871 $curSize += $wW;
1992 871 $lines[-1] .= $word;
1993  
1994 871 ▶ if( @cage ) { # this is fragment (word continues further on)
Branch: 1 branch
BranchTrueFalseTotal
if (@cage) 273 598 871
1995 273 ▶ $lines[-1] .= ($alpha && $cage[0] =~/$Aa/) ? '\\-' : $glue; # + supposed hyphen or glue (\hskip)
Branch: 1 branch
BranchTrueFalseTotal
$alpha && $cage[0] =~ /$Aa/ ? : 213 60 273
Condition66%2/3
$alpha and $cage[0] =~ /$Aa/
!ll&&!rl&&r
060213
MC/DC50%1/2
$alpha and $cage[0] =~ /$Aa/
$alpha $cage[0] =~ /$Aa/
Truth table66%2/3
A and B
A= $alphaB= $cage[0] =~ /$Aa/
ABresult
0X0
100
111
1996 }
1997  
1998 871 next;
1999 }
2000  
2001 439 my @chunks = $word=~/(.{$nS})(.)(.*)/;
2002  
2003 439 ▶ if( $f < 0 ) { # symbol width > cell width
Branch: 1 branch
BranchTrueFalseTotal
if ($f < 0) 64 375 439
2004  
2005 64 ▶ if( (! defined( $chunks[2] ) or ! length( $chunks[2] )) && ! @cage ) { # NOT "tail" or fragments
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $chunks[2] && length $chunks[2] || @cage) { } 12 52 64
Condition83%5/6
defined $chunks[2] && length $chunks[2] || @cage
l!l&&r!l&&!r
49312
defined $chunks[2] and length $chunks[2]
!ll&&!rl&&r
01549
MC/DC66%2/3
defined $chunks[2] && length $chunks[2] || @cage
defined $chunks[2] length $chunks[2] @cage
Truth table60%3/5
A and B || C
A= defined $chunks[2]B= length $chunks[2]C= @cage
ABCresult
11X1
0X11
1011
0X00
1000
2006 # add whitespace
2007 12 $chunks[1] .= ' ';
2008 12 $wS += $space; # + ($prevKPX->{32} // 0);
2009 12 $prevKPX = $spcKPX; # for paired kerning of space + next.symbol
2010  
2011 }
2012 else { # exists "tail"
2013 52 ▶ if( $alpha && ($chunks[2] =~/$Aa/ or $cage[0] =~/$Aa/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alpha and $chunks[2] =~ /$Aa/ || $cage[0] =~ /$Aa/) { } 27 25 52
Condition100%6/6
$alpha and $chunks[2] =~ /$Aa/ || $cage[0] =~ /$Aa/
!ll&&!rl&&r
23227
$chunks[2] =~ /$Aa/ or $cage[0] =~ /$Aa/
l!l&&r!l&&!r
2612
MC/DC100%3/3
$alpha and $chunks[2] =~ /$Aa/ || $cage[0] =~ /$Aa/
$alpha $chunks[2] =~ /$Aa/ $cage[0] =~ /$Aa/
Truth table100%4/4
A and B or C
A= $alphaB= $chunks[2] =~ /$Aa/C= $cage[0] =~ /$Aa/
ABCresult
0XX0
1000
11X1
1011
2014 27 $chunks[1] .= '\\-'; # symbol + hyphen
2015 # $wS += $wH; # width of (cur.symbol + hyphen + paired kerning): cur+hyphen
2016 }
2017 else {
2018 25 $chunks[1] .= $glue;
2019 }
2020 }
2021  
2022 64 ▶ if( $nS ) { # exists "head" (prefix)
Branch: 1 branch
BranchTrueFalseTotal
if ($nS) { } 10 54 64
2023  
2024 10 $lines[-1] .= $chunks[0];
2025  
2026 10 ▶ if( $chunks[0] =~/$Aa/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunks[0] =~ /$Aa/) { } 10 0 10
2027 10 $lines[-1] .= '\\-'; # + hyphen
2028 # push @wxL, $curSize + $wW + $hyphen + ($prevKPX->{45} // 0) if $ArSc; # taking paired kerning into account: prev+hyphen
2029 }
2030 else {
2031 0 $lines[-1] .= $glue;
2032 }
2033 10 ▶ push @wxL, $curSize + $wW if $ArSc;
Branch: 1 branch
BranchTrueFalseTotal
if $ArSc 9 1 10
2034  
2035 10 ▶ if( $limit && @lines >= $limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and @lines >= $limit) 5 5 10
Condition66%2/3
$limit and @lines >= $limit
!ll&&!rl&&r
505
MC/DC50%1/2
$limit and @lines >= $limit
$limit @lines >= $limit
Truth table66%2/3
A and B
A= $limitB= @lines >= $limit
ABresult
0X0
100
111
2036 5 $stop -= (length( join('', $word, @cage) ) - $nS);
2037 5 last _onecell_M0;
2038 }
2039  
2040 # Next up is a new cell line
2041 5 ++$numL;
2042 5 push @lines, $chunks[1];
2043 }
2044 else { # NO "head" (prefix)
2045 54 ▶ if( $szl ) { # and cell line is NOT empty (partially filled)
Branch: 1 branch
BranchTrueFalseTotal
if ($szl) { } 4 50 54
2046  
2047 4 my $add = 0;
2048 4 ▶ if( $lines[-1] !~/(?:\\-|$q)$/ and ! ~~@cage ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/ or ~~@cage) 4 0 4
Condition33%1/3
$lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/ or ~~@cage
l!l&&r!l&&!r
004
MC/DC0%0/2
$lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/ or ~~@cage
$lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/ ~~@cage
Truth table33%1/3
A or B
A= $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/B= ~~@cage
ABresult
1X1
011
000
2049 # In cell line no word fragment at the beginning, but there is a complete word
2050 4 $lines[-1] .= ' ';
2051 4 $add = $space; # + ($prevKPX->{32} // 0);
2052 }
2053 4 ▶ push @wxL, $curSize + $add if $ArSc;
Branch: 1 branch
BranchTrueFalseTotal
if $ArSc 4 0 4
2054  
2055 4 ▶ if( $limit && @lines >= $limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and @lines >= $limit) 2 2 4
Condition66%2/3
$limit and @lines >= $limit
!ll&&!rl&&r
202
MC/DC50%1/2
$limit and @lines >= $limit
$limit @lines >= $limit
Truth table66%2/3
A and B
A= $limitB= @lines >= $limit
ABresult
0X0
100
111
2056 2 $stop -= length( join('', $word, @cage) );
2057 2 last _onecell_M0;
2058 }
2059  
2060 # Next up is a new cell line
2061 2 ++$numL;
2062 2 push @lines, $chunks[1]; # with hyphen or glue (see above)
2063 }
2064 else { # cell line is EMPTY
2065 50 $lines[-1] .= $chunks[1]; # with posible? hyphen or glue
2066 }
2067 }
2068  
2069 57 ▶ push @wxL, $wS if $ArSc; # width of symbol + space
Branch: 1 branch
BranchTrueFalseTotal
if $ArSc 56 1 57
2070  
2071 57 ▶ if( $limit && @lines >= $limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and @lines >= $limit) 25 32 57
Condition100%3/3
$limit and @lines >= $limit
!ll&&!rl&&r
26625
MC/DC100%2/2
$limit and @lines >= $limit
$limit @lines >= $limit
Truth table100%3/3
A and B
A= $limitB= @lines >= $limit
ABresult
0X0
100
111
2072 25 $stop -= ( length( join('', $word, @cage) ) - ($nS + 1));
2073 25 last _onecell_M0;
2074 }
2075  
2076 # Next up is a new cell line
2077 32 ++$numL;
2078 32 $curSize = 0;
2079 32 $prevKPX = {};
2080 32 push @lines, '';
2081  
2082 32 ▶ if( $chunks[2] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunks[2]) 23 9 32
2083 23 $word = $chunks[2];
2084  
2085 23 redo;
2086 }
2087  
2088 9 next;
2089 }
2090  
2091 375 ▶ if( $alpha && $yhp && $yhp < 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alpha and $yhp and $yhp < 3) 304 71 375
Condition100%6/6
$alpha and $yhp and $yhp < 3
!ll&&!rl&&r
683304
$alpha and $yhp
!ll&&!rl&&r
860307
MC/DC100%3/3
$alpha and $yhp and $yhp < 3
$alpha $yhp $yhp < 3
Truth table100%4/4
A and B and C
A= $alphaB= $yhpC= $yhp < 3
ABCresult
0XX0
10X0
1100
1111
2092 # This is alphabetic word, and a method (action) for breaking words into hyphens is specified
2093  
2094 304 ▶ if( $yhp == 2 ) { # for word it was already broken by hyphens
Branch: 2 branches
BranchTrueFalseTotal
if ($yhp == 2) { } 121 183 304
elsif ($#ss > 2) { } 125 58 183
2095  
2096 121 ▶ if( $szl ) { # and cell line is not empty (partially filled)
Branch: 1 branch
BranchTrueFalseTotal
if ($szl) 115 6 121
2097  
2098 115 my $add = 0;
2099 115 ▶ if( $lines[-1] !~/(?:\\-|$q)$/) { # there is a full word : and ! ~~@cage
Branch: 1 branch
BranchTrueFalseTotal
unless ($lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/) 43 72 115
2100 43 $lines[-1] .= ' ';
2101 43 $add = $space; # + ($prevKPX->{32} // 0);
2102 }
2103 115 ▶ push @wxL, $curSize + $add if $ArSc;
Branch: 1 branch
BranchTrueFalseTotal
if $ArSc 103 12 115
2104  
2105 115 ▶ if( $limit && @lines >= $limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and @lines >= $limit) 5 110 115
Condition100%3/3
$limit and @lines >= $limit
!ll&&!rl&&r
74365
MC/DC100%2/2
$limit and @lines >= $limit
$limit @lines >= $limit
Truth table100%3/3
A and B
A= $limitB= @lines >= $limit
ABresult
0X0
100
111
2106 5 $stop -= length( join('', $word, @cage) );
2107 5 last _onecell_M0;
2108 }
2109  
2110 # Try placing it into next up is a new cell line
2111 110 ++$numL;
2112 110 $curSize = 0;
2113  
2114 # $lines[-1] =~/.$/;
2115 110 $prevKPX = {}; # $symKPX->{ord($&)} || ;
2116 110 push @lines, '';
2117  
2118 110 redo; # repeat in a new cell line
2119 }
2120 }
2121 elsif( $#ss > 2 ) { # length of word/fragment > 3 symbols
2122 125 for my $h ( @{ $op->{hyphenation} } ) {
2123 175 my $msk;
2124 175 ▶ if( $h->{msk} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{'msk'}) { } 34 141 175
2125 34 $msk = $h->{msk};
2126 }
2127 # elsif( $h->{name} )
2128 else {
2129 141 $msk = $refHypMsk->{lc $h->{name}};
2130 }
2131  
2132 175 ▶ if( $word =~/^$msk$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /^$msk$/) { } 113 62 175
2133  
2134 my @arr = ( ref( $h->{action} ) eq 'CODE') ?
2135 $h->{action}( $word ) :
2136 113 ▶ $h->{action}->hyphenate( $word );
Branch: 1 branch
BranchTrueFalseTotal
ref $h->{'action'} eq 'CODE' ? : 0 113 113
2137  
2138 113 ▶ if( @arr > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arr > 1) { } 106 7 113
2139 106 $yhp = 2; # YES word breaks (hyphenations)
2140  
2141 # JIC: ispravljaem slogi s perenosami '-'
2142 106 ▶ for( my $i = $#arr; $i >= 0; --$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 318 106 424
2143 318 ▶ splice @arr,$i,1, grep{length} split /(\-+)/, $arr[$i] if $arr[$i]=~/\-/;
Branch: 1 branch
BranchTrueFalseTotal
if $arr[$i] =~ /\-/ 3 315 318
2144 }
2145  
2146 106 unshift @cage, @arr;
2147 }
2148 else {
2149 7 $yhp = 3; # NO word breaks (hyphenations)
2150 }
2151 113 last;
2152 }
2153 else {
2154 62 $yhp = 4; # word NOT found
2155 }
2156 }
2157 125 ▶ next if $yhp == 2; # hyphenation has been added to the words
Branch: 1 branch
BranchTrueFalseTotal
if $yhp == 2 106 19 125
2158 }
2159 else {
2160 58 $yhp = 5; # a small word (<4 symbols)
2161 }
2162  
2163 }
2164  
2165 # symbol < cell width, but did not fit into the current cell line
2166  
2167 154 ▶ if( $szl && $lines[-1] !~/(?:\\-|$q)$/) { # In cell line no word fragment at the beginning, but there is a complete word.
Branch: 1 branch
BranchTrueFalseTotal
if ($szl and not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/) 132 22 154
Condition100%3/3
$szl and not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
!ll&&!rl&&r
211132
MC/DC100%2/2
$szl and not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
$szl not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
Truth table100%3/3
A and not(B)
A= $szlB= not $lines[-1] =~ /(?:\\-|$LaTeX::Replicase::q)$/
ABresult
0X0
100
111
2168 132 $lines[-1] .= ' ';
2169 132 $curSize += $space; # + ($prevKPX->{32} // 0);
2170 }
2171  
2172 154 ▶ my $alpha_0 = $chunks[0] =~/^\p{Alpha}+$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$chunks[0] =~ /^\p{Alpha}+$/ ? : 80 74 154
2173  
2174 154 ▶ if( $nS && ($nS > 1 or ! $curSize or ! $alpha_0) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nS and $nS > 1 || !$curSize || !$alpha_0) { } 66 88 154
elsif ($ArSc) { } 78 10 88
Condition100%9/9
$nS and $nS > 1 || !$curSize || !$alpha_0
!ll&&!rl&&r
642466
$nS > 1 or not $curSize or not $alpha_0
l!l&&r!l&&!r
65124
$nS > 1 or not $curSize
l!l&&r!l&&!r
471825
MC/DC100%4/4
$nS and $nS > 1 || !$curSize || !$alpha_0
$nS $nS > 1 not $curSize not $alpha_0
Truth table100%5/5
A and B or not(C) or not(D)
A= $nSB= $nS > 1C= not $curSizeD= not $alpha_0
ABCDresult
0XXX0
10000
11XX1
101X1
10011
2175 # hyphenation allowed only after the first 2 letters, or cell is EMPTY, or if the character is not a letter
2176 66 $lines[-1] .= $chunks[0];
2177  
2178 # my $add = 0;
2179 66 ▶ if( $alpha_0 && $alpha ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alpha_0 and $alpha) { } 52 14 66
Condition100%3/3
$alpha_0 and $alpha
!ll&&!rl&&r
10452
MC/DC100%2/2
$alpha_0 and $alpha
$alpha_0 $alpha
Truth table100%3/3
A and B
A= $alpha_0B= $alpha
ABresult
0X0
100
111
2180 52 $lines[-1] .= '\\-'; # + hyphen
2181 # $add = $hyphen + ($prevKPX->{45} // 0);
2182 }
2183 else {
2184 14 $lines[-1] .= $glue;
2185 }
2186  
2187 66 ▶ push @wxL, $curSize + $wW if $ArSc; # taking into account kerning pairs prev+hyphen
Branch: 1 branch
BranchTrueFalseTotal
if $ArSc 66 0 66
2188  
2189 66 $word = $chunks[1].$chunks[2];
2190 }
2191 elsif( $ArSc ) { # current synbol is the 1st character of the word/fragment
2192 78 push @wxL, $curSize;
2193 }
2194  
2195 154 ▶ if( $limit && @lines >= $limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and @lines >= $limit) 27 127 154
Condition100%3/3
$limit and @lines >= $limit
!ll&&!rl&&r
775027
MC/DC100%2/2
$limit and @lines >= $limit
$limit @lines >= $limit
Truth table100%3/3
A and B
A= $limitB= @lines >= $limit
ABresult
0X0
100
111
2196 27 $stop -= length( join('', $word, @cage) );
2197 27 last _onecell_M0;
2198 }
2199  
2200 # Next up is a new cell line
2201 127 ++$numL;
2202 127 $curSize = 0;
2203 127 $prevKPX = $curKPX; # for paired kerning of the next symbol
2204 127 push @lines, '';
2205  
2206 127 redo; # repeat in a new cell line
2207 }
2208 continue {
2209 986 $new = 0;
2210 }
2211 }
2212  
2213 98 ▶ push @wxL, $curSize if $ArSc && $curSize && $#wxL < $#lines;
Branch: 1 branch
BranchTrueFalseTotal
if $ArSc and $curSize and $#wxL < $#lines 27 71 98
Condition100%6/6
$ArSc and $curSize and $#wxL < $#lines
!ll&&!rl&&r
492227
$ArSc and $curSize
!ll&&!rl&&r
34649
MC/DC100%3/3
$ArSc and $curSize and $#wxL < $#lines
$ArSc $curSize $#wxL < $#lines
Truth table100%4/4
A and B and C
A= $ArScB= $curSizeC= $#wxL < $#lines
ABCresult
0XX0
10X0
1100
1111
2214  
2215 98 ▶ $stop = -1 if $limit
Branch: 1 branch
BranchTrueFalseTotal
if $limit and $stop >= $szStr || @lines < $limit || $_[0] =~ /\A.{$stop}\s+\z/ 17 81 98
Condition100%9/9
$limit and $stop >= $szStr || @lines < $limit || $_[0] =~ /\A.{$stop}\s+\z/
!ll&&!rl&&r
206117
$stop >= $szStr or @lines < $limit or $_[0] =~ /\A.{$stop}\s+\z/
l!l&&r!l&&!r
15261
$stop >= $szStr or @lines < $limit
l!l&&r!l&&!r
7863
MC/DC100%4/4
$limit and $stop >= $szStr || @lines < $limit || $_[0] =~ /\A.{$stop}\s+\z/
$limit $stop >= $szStr @lines < $limit $_[0] =~ /\A.{$stop}\s+\z/
Truth table100%5/5
A and B or C or D
A= $limitB= $stop >= $szStrC= @lines < $limitD= $_[0] =~ /\A.{$stop}\s+\z/
ABCDresult
0XXX0
10000
11XX1
101X1
10011
2216 and ( $stop >= $szStr or @lines < $limit or $_[0] =~/\A.{$stop}\s+\z/ );
2217  
2218 # Final preparations
2219 98 @lines = grep{ ! /^\s*$/ } @lines;
2220  
2221 98 my $i = 0;
2222 98 for( @lines ) {
2223 369 s/(?<=[[:alpha:]])$q(?=[.,?!:;%'])//g; #'
2224 369 ▶ s/(?<=[[:alpha:]])$q$// if $i < $#lines and $lines[$i+1] =~/^[.,?!:;%']/; #'
Branch: 1 branch
BranchTrueFalseTotal
if $i < $#lines and $lines[$i + 1] =~ /^[.,?!:;%']/ 1 368 369
Condition100%3/3
$i < $#lines and $lines[$i + 1] =~ /^[.,?!:;%']/
!ll&&!rl&&r
982701
MC/DC100%2/2
$i < $#lines and $lines[$i + 1] =~ /^[.,?!:;%']/
$i < $#lines $lines[$i + 1] =~ /^[.,?!:;%']/
Truth table100%3/3
A and B
A= $i < $#linesB= $lines[$i + 1] =~ /^[.,?!:;%']/
ABresult
0X0
100
111
2225 369 s/(?:\\-|$q)(?=\S+\s\S)//g;
2226 369 s/(?:\\-)+(?=\-)//g;
2227 369 s/(?<=\-)(?:\\-)+/$glue/g;
2228  
2229 369 ▶ if( $i && $lines[$i-1] !~/\\-$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i and not $lines[$i - 1] =~ /\\-$/) 140 229 369
Condition100%3/3
$i and not $lines[$i - 1] =~ /\\-$/
!ll&&!rl&&r
98131140
MC/DC100%2/2
$i and not $lines[$i - 1] =~ /\\-$/
$i not $lines[$i - 1] =~ /\\-$/
Truth table100%3/3
A and not(B)
A= $iB= not $lines[$i - 1] =~ /\\-$/
ABresult
0X0
100
111
2230 140 ▶ 1 while s/^(\S+?)\\-(?=\S+\s)/$1/;
Branch: 1 branch
BranchTrueFalseTotal
s/^(\S+?)\\-(?=\S+\s)/$1/ and do { '???' } 8 140 148
2231 }
2232 369 ++$i;
2233 }
2234 98 ▶ $wxL[-1] -= $space if $lines[-1] =~s/ $// && $ArSc;
Branch: 1 branch
BranchTrueFalseTotal
if $lines[-1] =~ s/ $// and $ArSc 23 75 98
Condition100%3/3
$lines[-1] =~ s/ $// and $ArSc
!ll&&!rl&&r
74123
MC/DC100%2/2
$lines[-1] =~ s/ $// and $ArSc
$lines[-1] =~ s/ $// $ArSc
Truth table100%3/3
A and B
A= $lines[-1] =~ s/ $//B= $ArSc
ABresult
0X0
100
111
2235  
2236  
2237 98 my $wxLsum = 0;
2238 98 ▶ if( $ArSc && $op->{merge} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ArSc and $op->{"merge"}) 77 21 98
Condition100%3/3
$ArSc and $op->{"merge"}
!ll&&!rl&&r
31877
MC/DC100%2/2
$ArSc and $op->{"merge"}
$ArSc $op->{"merge"}
Truth table100%3/3
A and B
A= $ArScB= $op->{"merge"}
ABresult
0X0
100
111
2239 77 $wxLsum += $_ for @wxL;
2240 }
2241  
2242 return $ArSc ?
2243 {
2244 lines => ($op->{merge} ? [ join '', @lines ] : \@lines),
2245 98 ▶ wxL => ($op->{merge} ? [ $wxLsum ] : \@wxL),
Branch: 3 branches
BranchTrueFalseTotal
$ArSc ? : 95 3 98
$op->{'merge'} ? : 77 18 95
$op->{'merge'} ? : 77 18 95
2246 numL => ~~@lines, # $numL,
2247 stop => $stop,
2248 scale => $scale,
2249 } :
2250 ~~@lines; # $numL
2251 }
2252  
2253 # IN:
2254 # $str -- string (strand)
2255 # $op->
2256 # {done_lines} -- number of lines already occupied in the 1st cell (for example, in a table column). By default is 0.
2257 # {cell_limit} -- maximum permissible number of cells (positive number). By default, undef, i.e. unlimited.
2258 # {orphan} = 1 -- allow a single ("orphaned") line within a cell. By default is 0 (disallow "orphaned" lines).
2259  
2260 # The remaining options are the same as for onecell():
2261 # {cell_width} -- width of cell/box (pt).
2262 # {font_metrics} -- table of font metrics with {WX} key -- for decimal Unicode number, and {KPX} key -- for paired kerning.
2263 # {base_font_size} -- depending on the document's base font size (pt), see \documentclass[...pt].
2264 # {font_size} -- TeX-font size of text in cell/box, e.g. 'small', 'normalsize', 'large', etc.
2265 # {shrink} -- space compressibility (the extent to which a space can become narrower than its base value if the line is compressed).
2266 # {merge} = 1 -- return a combined string (paragraph) and its total width (length) in (pt), rather than an array of strings.
2267 # {offset} -- offset from the beginning of $str from which characters for cell are extracted. By default, 0.
2268 # {limit} -- the maximum allowable number of lines for a cell. By default is 1.
2269 # {hyphenation} => # a array of methods for hyphenating words in specified languages.
2270  
2271 # OUT:
2272 # HASH with keys:
2273 # 'cells' -- array of cells (or table column) to be populated with lines, running from top to bottom.
2274 # 'wxC' -- array of line widths (*100pt) from 'cells', standardized to 'base_font_size'=10pt and 'font_size'='normalsize'.
2275 # 'scale' -- of font standardization.
2276 # 'numL' -- array containing the number of lines in each cell.
2277 # 'stopC' -- array of positions in $str where the extraction of symbols into cell stopped.
2278 # If all non-whitespace characters have been extracted from $str and 'limit' option is specified, then '-1' is returned.
2279 # 'numС' -- number of no empty cells, i.e. size of 'cells' array.
2280 # 'done_lines' -- number of lines occupied by the last cell. This could be greater than the number in the last element of 'numL' array.
2281 # 'end' -- end position in $str where the extraction of symbols into cell stopped. This value corresponds to the last element of 'stopC' array.
2282 # If all non-whitespace characters have been extracted from $str and 'limit' option is specified, then '-1' is returned.
2283 # or
2284 # SCALAR is number of no empty cells (i.e. 'numC')
2285  
2286 29 ▶sub multicell {
Subroutine multicell: called CC=32 SCAR=34.7
Pod documented
2287 29 ▶ return if ! defined( $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[0] or ref \$_[0] ne "SCALAR" or not $_[1] or ref $_[1] ne "HASH" 4 25 29
Condition100%9/9
not defined $_[0] or ref \$_[0] ne "SCALAR" or not $_[1] or ref $_[1] ne "HASH"
l!l&&r!l&&!r
3125
not defined $_[0] or ref \$_[0] ne "SCALAR" or not $_[1]
l!l&&r!l&&!r
2126
not defined $_[0] or ref \$_[0] ne "SCALAR"
l!l&&r!l&&!r
1127
MC/DC100%4/4
not defined $_[0] or ref \$_[0] ne "SCALAR" or not $_[1] or ref $_[1] ne "HASH"
not defined $_[0] ref \$_[0] ne "SCALAR" not $_[1] ref $_[1] ne "HASH"
Truth table100%5/5
not(A) or B or not(C) or D
A= not defined $_[0]B= ref \$_[0] ne "SCALAR"C= not $_[1]D= ref $_[1] ne "HASH"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
2288 or ref \$_[0] ne 'SCALAR'
2289 or ! $_[1]
2290 or ref $_[1] ne 'HASH';
2291  
2292 25 my $ArSc = wantarray;
2293  
2294 25 my $op = $_[1];
2295  
2296 # Sets
2297 25 for('cell_limit') {
2298 25 ▶ $op->{$_} = undef if ! exists( $op->{$_} ) or ! defined( $op->{$_} ) or $op->{$_} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $op->{$_} && defined $op->{$_} or $op->{$_} < 0 24 1 25
Condition100%6/6
not exists $op->{$_} && defined $op->{$_} or $op->{$_} < 0
l!l&&r!l&&!r
2311
exists $op->{$_} && defined $op->{$_}
!ll&&!rl&&r
2212
MC/DC100%3/3
not exists $op->{$_} && defined $op->{$_} or $op->{$_} < 0
exists $op->{$_} defined $op->{$_} $op->{$_} < 0
Truth table100%4/4
not(A && B) or C
A= exists $op->{$_}B= defined $op->{$_}C= $op->{$_} < 0
ABCresult
0XX1
10X1
1111
1100
2299 }
2300  
2301 25 my %saved; # prev.options
2302 25 my %k2v = (
2303 merge => 1,
2304 done_lines => 0,
2305 offset => 0,
2306 );
2307  
2308 25 ▶ while( my( $k, $v ) = each %k2v ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %k2v) 75 25 100
2309 75 for( $op->{$k} ) {
2310 75 ▶ $saved{$k} = $_ || undef;
Condition100%2/2
$_ || undef
l!l
1461
MC/DC100%1/1
$_ || undef
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
2311 75 ▶ $_ ||= $v;
Condition100%3/3
$_ ||= $v
l!l&&r!l&&!r
141348
MC/DC100%2/2
$_ ||= $v
$_ $v
Truth table100%3/3
A ||= B
A= $_B= $v
ABresult
1X1
011
000
2312 75 ▶ $_ = $v if $_ < $v;
Branch: 1 branch
BranchTrueFalseTotal
if $_ < $v 1 74 75
2313 }
2314 }
2315  
2316 25 my( @cells, @wxC, @numL, @stopC );
2317 25 my( $numCells, $doneL, $scale );
2318 25 my $end = -1;
2319  
2320 25 ▶ if( $op->{limit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->{'limit'}) { } 23 2 25
2321  
2322 23 for( $op->{limit} ) {
2323 23 $saved{limit} = $_;
2324 23 ▶ $_ = 1 if $_ < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $_ < 1 7 16 23
2325 }
2326  
2327 23 my $limit_ini = $op->{limit};
2328 23 ▶ $doneL = $op->{done_lines} < $limit_ini ? $op->{done_lines} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$op->{'done_lines'} < $limit_ini ? : 23 0 23
2329  
2330 23 ▶ $op->{orphan} //= 0;
Condition100%2/2
$op->{"orphan"} //= 0
l!l
221
MC/DC100%1/1
$op->{"orphan"} //= 0
$op->{"orphan"}
Truth table100%2/2
A
A= $op->{"orphan"}
Aresult
11
00
2331 23 ▶ my $orphan = $op->{orphan} ? 0 : 1;# 'yes' : 'no' orphan line
Branch: 1 branch
BranchTrueFalseTotal
$op->{'orphan'} ? : 0 23 23
2332 23 ▶ $orphan = 0 if $op->{limit} < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"limit"} < 2 10 13 23
2333  
2334 23 ▶ while( $op->{offset} > $end and (! $op->{cell_limit} or @cells < $op->{cell_limit}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->{"offset"} > $end and !$op->{"cell_limit"} || @cells < $op->{"cell_limit"}) 81 17 98
Condition100%6/6
$op->{"offset"} > $end and !$op->{"cell_limit"} || @cells < $op->{"cell_limit"}
!ll&&!rl&&r
16181
not $op->{"cell_limit"} or @cells < $op->{"cell_limit"}
l!l&&r!l&&!r
7921
MC/DC100%3/3
$op->{"offset"} > $end and !$op->{"cell_limit"} || @cells < $op->{"cell_limit"}
$op->{"offset"} > $end not $op->{"cell_limit"} @cells < $op->{"cell_limit"}
Truth table100%4/4
A and not(B) or C
A= $op->{"offset"} > $endB= not $op->{"cell_limit"}C= @cells < $op->{"cell_limit"}
ABCresult
0XX0
1000
11X1
1011
2335 81 $end = $op->{offset};
2336  
2337 81 my $delta = $op->{limit} - $doneL;
2338 81 ▶ $op->{limit} = $delta > $orphan ? $delta : $limit_ini;
Branch: 1 branch
BranchTrueFalseTotal
$delta > $orphan ? : 23 58 81
2339  
2340 81 my( $arr ) = onecell( $_[0], $op );
2341  
2342 78 $op->{offset} = $arr->{stop};
2343 78 ▶ $arr->{wxL}[0] or last;
Branch: 1 branch
BranchTrueFalseTotal
$arr->{"wxL"}[0] or last 75 3 78
2344  
2345 75 push @cells, $arr->{lines}[0];
2346 75 push @wxC, $arr->{wxL}[0];
2347  
2348 75 $doneL = $arr->{numL}; # number of lines
2349 75 push @numL, $doneL;
2350  
2351 75 push @stopC, $arr->{stop};
2352 75 $scale = $arr->{scale};
2353 }
2354  
2355 20 $end = $op->{offset};
2356 20 $numCells = ~~@cells;
2357 }
2358 else {
2359 2 ▶ if( $ArSc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ArSc) { } 1 1 2
2360 1 my( $arr ) = onecell( $_[0], $op );
2361  
2362 1 push @cells, $arr->{lines}[0];
2363 1 push @wxC, $arr->{wxL}[0];
2364  
2365 1 $doneL = $arr->{numL}; # number of lines
2366 1 push @numL, $doneL;
2367  
2368 1 $end = $arr->{stop};
2369 1 push @stopC, $end;
2370  
2371 1 $numCells = ~~@cells;
2372 1 $scale = $arr->{scale};
2373 }
2374 else {
2375 1 $numCells = onecell( $_[0], $op );
2376 }
2377 }
2378  
2379 # number of lines occupied by the last cell
2380 22 ▶ $doneL += ($saved{done_lines} // 0) if @cells < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @cells < 2 9 13 22
Condition50%1/2
$saved{"done_lines"} // 0
l!l
09
MC/DC0%0/1
$saved{"done_lines"} // 0
$saved{"done_lines"}
Truth table50%1/2
A
A= $saved{"done_lines"}
Aresult
11
00
2381  
2382 # Restorе options
2383 22 ▶ while( my( $k, $v ) = each %saved ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %saved) 86 22 108
2384 86 ▶ if( defined $v ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 32 54 86
2385 32 $op->{$k} = $v;
2386 }
2387 else {
2388 54 delete $op->{$k};
2389 }
2390 }
2391  
2392 22 ▶ return $ArSc ?
Branch: 1 branch
BranchTrueFalseTotal
$ArSc ? : 18 4 22
2393 {
2394 cells => \@cells,
2395 wxC => \@wxC,
2396 numL => \@numL,
2397 stopC => \@stopC,
2398 numC => $numCells,
2399 done_lines => $doneL,
2400 end => $end,
2401 scale => $scale,
2402 } :
2403 $numCells;
2404 }
2405  
2406 7 1;
2407  
2408 __END__
↑ Summary