blib/lib/App/ansifold.pm

filter: Statementstmt 92.4% 283 / 306 Branchbran 77.8% 95 / 122 Conditioncond 62.2% 33 / 53 MC/DCmcdc 40.6% 13 / 32 Subroutinesub 87.7% 43 / 49 Podpod 0.0% 0 / 16 totaltotal 80.8% 467 / 578 CC 83 SCAR 24.9
CC
83
Cov
85%
doit
26.6
options
25.5
cut_to_width
11.1
CRAP 12.1
↑ Summary
1 package App::ansifold;
2 135 our $VERSION = "1.42";
3  
4 135 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 135 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 135 ▶use open IO => 'utf8', ':std';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 135 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 135 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 135 ▶use List::Util qw(min);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 135 ▶use Hash::Util qw(lock_keys);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 135 ▶use Text::ANSI::Fold qw(:constants ansi_unfold);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 135 ▶use Text::ANSI::Fold::Util qw(ansi_width); {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 135 Text::ANSI::Fold->configure(expand => 1);
16 }
17 135 ▶use Unicode::EastAsianWidth;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 135 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 135 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 135 our @EXPORT_OK = qw(ansifold ansiexpand ansicolrm ansicut);
22  
23 135 ▶our $DEFAULT_WIDTH //= 72;
Condition100%2/2
our $DEFAULT_WIDTH //= 72
l!l
4131
MC/DC100%1/1
our $DEFAULT_WIDTH //= 72
our $DEFAULT_WIDTH
Truth table100%2/2
A
A= our $DEFAULT_WIDTH
Aresult
11
00
24 135 ▶our $DEFAULT_SEPARATE //= "\n";
Condition100%2/2
our $DEFAULT_SEPARATE //= " "
l!l
3132
MC/DC100%1/1
our $DEFAULT_SEPARATE //= " "
our $DEFAULT_SEPARATE
Truth table100%2/2
A
A= our $DEFAULT_SEPARATE
Aresult
11
00
25 135 ▶our $DEFAULT_EXPAND //= 0;
Condition100%2/2
our $DEFAULT_EXPAND //= 0
l!l
4131
MC/DC100%1/1
our $DEFAULT_EXPAND //= 0
our $DEFAULT_EXPAND
Truth table100%2/2
A
A= our $DEFAULT_EXPAND
Aresult
11
00
26 135 ▶our $DEFAULT_COLRM //= 0;
Condition100%2/2
our $DEFAULT_COLRM //= 0
l!l
3132
MC/DC100%1/1
our $DEFAULT_COLRM //= 0
our $DEFAULT_COLRM
Truth table100%2/2
A
A= our $DEFAULT_COLRM
Aresult
11
00
27 135 ▶our $DEFAULT_CUT //= 0;
Condition50%1/2
our $DEFAULT_CUT //= 0
l!l
0135
MC/DC0%0/1
our $DEFAULT_CUT //= 0
our $DEFAULT_CUT
Truth table50%1/2
A
A= our $DEFAULT_CUT
Aresult
11
00
28 135 our $DEFAULT_SPLITWIDE;
29  
30 7 ▶sub ansifold {
Subroutine ansifold: called CC=1 SCAR=0.0
Pod undocumented
31 7 __PACKAGE__->new->perform(@_);
32 }
33  
34 1 ▶sub ansiexpand {
Subroutine ansiexpand: called CC=1 SCAR=0.0
Pod undocumented
35 1 local $DEFAULT_WIDTH = -1;
36 1 local $DEFAULT_EXPAND = -1;
37 1 ansifold(@_);
38 }
39  
40 4 ▶sub ansicolrm {
Subroutine ansicolrm: called CC=1 SCAR=0.0
Pod undocumented
41 4 local $DEFAULT_SEPARATE = "";
42 4 local $DEFAULT_COLRM = 1;
43 4 ansifold(@_);
44 }
45  
46 1 ▶sub ansicut {
Subroutine ansicut: called CC=1 SCAR=0.0
Pod undocumented
47 1 local $DEFAULT_SEPARATE = "";
48 1 ansifold(@_);
49 }
50  
51 135 ▶use Getopt::EX::Hashed 'has'; {
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 135 Getopt::EX::Hashed->configure(DEFAULT => [ is => 'rw' ]);
54  
55 135 has width => ' w =s@ ' , default => [];
56 135 has boundary => ' =s ' , default => 'none';
57 3 ▶ has padding => ' :s ' , action => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
58 3 $_->padding = 1;
59 3 ▶ $_->padchar = $_[1] if $_[1] ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] ne "" 0 3 3
60 135 };
61 135 has padchar => ' =s ' ;
62 135 has trim => ' ! ' ;
63 135 has prefix => ' =s ' ;
64 135 has autoindent => ' =s ' ;
65 135 has keepindent => ' :s ' ; # '' or all: the whole match, group: captures, named: named captures
66 1 ▶ has no_keepindent => '' , action => sub { $_->keepindent = undef };
Subroutine __ANON__: called CC=1 SCAR=0.0
67 135 has indentchar => ' =s ' , default => ' ';
68 135 has ambiguous => ' =s ' ;
69 135 has paragraph => ' p + ' , default => 0;
70 135 has refill => ' r + ' , default => 0;
71 124 ▶ has separate => ' =s ' , default => sub { $DEFAULT_SEPARATE };
Subroutine __ANON__: called CC=1 SCAR=0.0
72 135 has linebreak => ' =s ' , alias => 'lb';
73 135 has runin => ' =i ' , min => 0, default => 4;
74 135 has runout => ' =i ' , min => 0, default => 4;
75 135 has runlen => ' =i ' , min => 0;
76 135 has margin => ' =i ' , min => 0;
77 135 has nonewline => ' n ' ;
78 135 has splitwide => ' :s ' , default => $DEFAULT_SPLITWIDE;
79 135 ▶ has lefthalf => ' =s ' , default => "\N{LEFT HALF BLACK CIRCLE}";
Subroutine BEGIN: called CC=1 SCAR=0.0
80 135 has righthalf => ' =s ' , default => "\N{RIGHT HALF BLACK CIRCLE}";
81 135 has smart => ' s ! ' ;
82 135 has crmode => ' ! ' ;
83  
84 20 ▶ has '+crmode' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
85 20 $_->{$_[0]} = $_[1];
86 20 ▶ $_->separate = "\r" if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 19 1 20
87 135 };
88 124 ▶ has expand => ' x :-1 ' , default => sub { $DEFAULT_EXPAND };
Subroutine __ANON__: called CC=1 SCAR=0.0
89 135 has tabstop => ' =i ' , min => 1;
90 135 has tabhead => ' =s ' ;
91 135 has tabspace => ' =s ' ;
92 135 has tabstyle => ' =s ' ;
93 135 has discard => ' =s@ ' , default => [];
94 124 ▶ has colrm => ' ' , default => sub { $DEFAULT_COLRM };
Subroutine __ANON__: called CC=1 SCAR=0.0
95 135 has cut => ' c =s ' ;
96 135 has debug => ' d ' ;
97 135 has help => ' h ' ;
98 135 has version => ' v ' ;
99  
100 135 has '+boundary' => any => [ qw(none word space) ];
101 135 has '+ambiguous' => any => [ qw(wide narrow) ] ;
102  
103 0 ▶ has '+help' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 0 pod2usage
105 -verbose => 99,
106 -sections => [ qw(SYNOPSIS VERSION) ];
107 135 };
108  
109 0 ▶ has '+version' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 0 print "Version: $VERSION\n";
111 0 exit;
112 135 };
113  
114 14 ▶ has '+nonewline' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
115 14 $_->separate = "";
116 135 };
117  
118 has '+linebreak' =>
119 default => LINEBREAK_NONE,
120 24 ▶ action => sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
121 24 my($name, $value) = @_;
122 24 $_->$name = do {
123 24 local $_ = $value;
124 24 my $v = LINEBREAK_NONE;
125 24 ▶ $v |= LINEBREAK_ALL if /all/i;
Branch: 1 branch
BranchTrueFalseTotal
if /all/iu 24 0 24
126 24 ▶ $v |= LINEBREAK_RUNIN if /runin/i;
Branch: 1 branch
BranchTrueFalseTotal
if /runin/iu 0 24 24
127 24 ▶ $v |= LINEBREAK_RUNOUT if /runout/i;
Branch: 1 branch
BranchTrueFalseTotal
if /runout/iu 0 24 24
128 24 $v;
129 };
130 135 };
131  
132 ### --runlen
133 1 ▶ has '+runlen' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
134 1 $_->runin = $_->runout = $_[1];
135 135 };
136 # for backward compatibility, would be deplicated
137 135 has run => '=i';
138 0 ▶ has '+run' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
139 0 $_->runin = $_->runout = $_[1];
140 135 };
141  
142 26 ▶ has '+smart' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
143 26 my $smart = $_->{$_[0]} = $_[1];
144 26 ($_->boundary, $_->linebreak, $_->trim) = do {
145 26 ▶ if ($smart) {
Branch: 1 branch
BranchTrueFalseTotal
if ($smart) { } 25 1 26
146 25 ('word', LINEBREAK_ALL, 1);
147 } else {
148 1 ('none', LINEBREAK_NONE, 0);
149 }
150 };
151 135 };
152  
153 # internal use
154 135 has width_index => default => [];
155 135 has indent_pat => ;
156 135 has min_width => ;
157  
158 135 ▶} no Getopt::EX::Hashed;
Subroutine BEGIN: called CC=1 SCAR=0.0
159  
160 122 ▶sub perform {
Subroutine perform: called CC=1 SCAR=0.0
Pod undocumented
161 122 my $app = shift;
162 122 local @ARGV = @_;
163 122 $app->options->params->doit;
164 116 return 0;
165 }
166  
167 122 ▶sub options {
Subroutine options: called CC=20 SCAR=32.4
Pod undocumented
168 122 my $app = shift;
169  
170 122 for (@ARGV) {
171 401 ▶ $_ = decode 'utf8', $_ unless utf8::is_utf8($_);
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($_) 401 0 401
172 }
173  
174 135 ▶ use Getopt::EX::Long qw(:DEFAULT ExConfigure Configure);
Subroutine BEGIN: called CC=1 SCAR=0.0
175 122 ExConfigure BASECLASS => [ __PACKAGE__, 'Getopt::EX' ];
176 122 Configure "bundling";
177 122 ▶ $app->getopt || pod2usage();
Branch: 1 branch
BranchTrueFalseTotal
$app->getopt or pod2usage() 116 6 122
178  
179 ## --colrm
180 116 ▶ if ($app->colrm) {
Branch: 2 branches
BranchTrueFalseTotal
if ($app->colrm) { } 11 105 116
elsif ($app->cut) { } 7 98 105
181 11 my @params;
182 11 ▶ while (@ARGV > 0 and $ARGV[0] =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV > 0 and $ARGV[0] =~ /^\d+$/u) 19 11 30
Condition66%2/3
@ARGV > 0 and $ARGV[0] =~ /^\d+$/u
!ll&&!rl&&r
11019
MC/DC50%1/2
@ARGV > 0 and $ARGV[0] =~ /^\d+$/u
@ARGV > 0 $ARGV[0] =~ /^\d+$/u
Truth table66%2/3
A and B
A= @ARGV > 0B= $ARGV[0] =~ /^\d+$/u
ABresult
0X0
100
111
183 19 push @params, shift @ARGV;
184 }
185 11 @{$app->width} = colrm_to_width(@params);
186 }
187 ## --cut
188 elsif ($app->cut) {
189 7 @{$app->width} = cut_to_width($app->cut);
190 }
191  
192 116 ▶ if ($app->expand > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->expand > 0) 0 116 116
193 0 $app->tabstop = $app->expand;
194 }
195  
196 116 ▶ $app->separate //= $DEFAULT_SEPARATE;
Condition33%1/3
$app->separate //= $App::ansifold::DEFAULT_SEPARATE
l!l&&r!l&&!r
11600
MC/DC0%0/2
$app->separate //= $App::ansifold::DEFAULT_SEPARATE
$app->separate $App::ansifold::DEFAULT_SEPARATE
Truth table33%1/3
A //= B
A= $app->separateB= $App::ansifold::DEFAULT_SEPARATE
ABresult
1X1
011
000
197  
198 135 ▶ use charnames ':loose';
Subroutine BEGIN: called CC=1 SCAR=0.0
199 116 for (@{$app}{qw(tabhead tabspace)}) {
200 232 ▶ defined && length > 1 or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ > 1 or next 0 232 232
Condition33%1/3
defined $_ and length $_ > 1
!ll&&!rl&&r
23200
MC/DC0%0/2
defined $_ and length $_ > 1
defined $_ length $_ > 1
Truth table33%1/3
A and B
A= defined $_B= length $_ > 1
ABresult
0X0
100
111
201 0 ▶ $_ = charnames::string_vianame($_) || die "$_: invalid name\n";
Condition0%0/2
charnames::string_vianame($_) || die("${_}: invalid name\n")
l!l
00
MC/DC0%0/1
charnames::string_vianame($_) || die("${_}: invalid name\n")
charnames::string_vianame($_)
Truth table0%0/2
A
A= charnames::string_vianame($_)
Aresult
11
00
202 }
203  
204 116 ▶ if (my $indent = $app->autoindent) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $indent = $app->autoindent) 16 100 116
205 16 ▶ if (($app->keepindent // '') eq 'named') {
Branch: 1 branch
BranchTrueFalseTotal
if (($app->keepindent // "") eq "named") 2 14 16
Condition100%2/2
$app->keepindent // ""
l!l
133
MC/DC100%1/1
$app->keepindent // ""
$app->keepindent
Truth table100%2/2
A
A= $app->keepindent
Aresult
11
00
206 # only named groups capture, so plain parentheses just group
207 2 $indent = "(?n)$indent";
208 }
209 16 $app->indent_pat = qr/$indent/;
210 }
211  
212 116 ▶ if (defined (my $char = $app->splitwide)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $char = $app->splitwide)) 4 112 116
213 4 $app->splitwide = 1;
214 4 ▶ if ($char =~ s/\A(\X)(\X)?//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ s/\A(\X)(\X)?//u) 0 4 4
215 0 $app->lefthalf = $1;
216 0 ▶ $app->righthalf = $2 // $1;
Condition0%0/3
$2 // $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$2 // $1
$2 $1
Truth table0%0/3
A // B
A= $2B= $1
ABresult
1X1
011
000
217 }
218 }
219  
220 116 return $app;
221 }
222  
223 116 ▶sub params {
Subroutine params: called CC=9 SCAR=23.2
Pod undocumented
224 116 my $app = shift;
225  
226 135 ▶ use Getopt::EX::Numbers;
Subroutine BEGIN: called CC=1 SCAR=0.0
227 116 my $numbers = Getopt::EX::Numbers->new;
228  
229 116 my @width = do {
230 map {
231 184 ▶ if (/^$/) { 0 } # empty
Branch: 4 branches
BranchTrueFalseTotal
if (/^$/u) { } 28 156 184
elsif (/^-?\d+$/u) { } 156 0 156
elsif (/^(-?[-\d:]+) (?:\{(\d+)\})? $/ux) { } 0 0 0
elsif (/^=(.*)/u) { } 0 0 0
232 156 elsif (/^-?\d+$/) { $_ } # number
233 elsif (/^(-?[-\d:]+) (?:\{(\d+)\})? $/x) { # a:b:c:d{e}
234 0 ▶ ($numbers->parse($1)->sequence) x ($2 // 1);
Condition0%0/2
$2 // 1
l!l
00
MC/DC0%0/1
$2 // 1
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
235 }
236 elsif (/^=(.*)/) {
237 0 require Getopt::EX::RPN;
238 0 int Getopt::EX::RPN::rpn_calc(terminal_width(), $1);
239 }
240 0 else { die "$_: width format error.\n" }
241 }
242 107 map { split /,/, $_, -1 }
243 116 @{$app->width};
244 };
245  
246 116 $app->width = do {
247 116 ▶ if (@width == 0) { $DEFAULT_WIDTH }
Branch: 2 branches
BranchTrueFalseTotal
if (@width == 0) { } 9 107 116
elsif (@width == 1) { } 62 45 107
248 62 elsif (@width == 1) { $width[0] }
249 else {
250 45 my @map = map [ abs $_ => $_ >= 0 ], @width;
251 45 $map[-1] = [ $width[-1] => $width[-1] ];
252 45 @width = map $_->[0], @map;
253 45 $app->width_index = [ grep { $map[$_][1] != 0 } keys @map ];
254 45 \@width;
255 }
256 };
257  
258 116 ▶ $app->min_width = ref $app->width ? min @{$app->width} : $app->width;
Branch: 1 branch
BranchTrueFalseTotal
ref $app->width ? : 45 71 116
259  
260 116 return $app;
261 }
262  
263 # The prefix of the continuation lines from the string that --autoindent
264 # matched: spaces of the same width, the string itself (--keepindent),
265 # or the string with everything outside the capture groups blanked
266 # (--keepindent=group, =named). $spans are the [start, end] offsets of
267 # the groups in $matched.
268 16 ▶sub indent_prefix {
Subroutine indent_prefix: called CC=9 SCAR=22.0
Pod undocumented
269 16 my($app, $matched, $spans) = @_;
270 16 my $keep = $app->keepindent;
271 16 ▶ return $app->indentchar x ansi_width($matched) if not defined $keep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keep 3 13 16
272 13 ▶ return $matched if $keep eq '' or $keep eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $keep eq "" or $keep eq "all" 3 10 13
Condition100%3/3
$keep eq "" or $keep eq "all"
l!l&&r!l&&!r
2110
MC/DC100%2/2
$keep eq "" or $keep eq "all"
$keep eq "" $keep eq "all"
Truth table100%3/3
A or B
A= $keep eq ""B= $keep eq "all"
ABresult
1X1
011
000
273 10 ▶ $keep eq 'group' or $keep eq 'named'
Branch: 1 branch
BranchTrueFalseTotal
$keep eq "group" or $keep eq "named" or die "${keep}: unknown --keepindent value (all, group or named)\n" 10 0 10
Condition66%2/3
$keep eq "group" or $keep eq "named"
l!l&&r!l&&!r
820
MC/DC0%0/2
$keep eq "group" or $keep eq "named"
$keep eq "group" $keep eq "named"
Truth table66%2/3
A or B
A= $keep eq "group"B= $keep eq "named"
ABresult
1X1
011
000
274 or die "$keep: unknown --keepindent value (all, group or named)\n";
275 10 my $mask = '0' x length $matched;
276 10 substr($mask, $_->[0], $_->[1] - $_->[0]) = '1' x ($_->[1] - $_->[0]) for @$spans;
277 10 my $prefix = '';
278 10 ▶ while ($mask =~ /\G(0+|1+)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mask =~ /\G(0+|1+)/gu) 14 10 24
279 14 my $part = substr $matched, $-[0], $+[0] - $-[0];
280 14 ▶ $prefix .= $1 =~ /1/ ? $part : $app->indentchar x ansi_width($part);
Branch: 1 branch
BranchTrueFalseTotal
$1 =~ /1/u ? : 7 7 14
281 }
282 10 $prefix;
283 }
284  
285 116 ▶sub doit {
Subroutine doit: called CC=24 SCAR=32.8
Pod undocumented
286 116 my $app = shift;
287  
288 my $fold = Text::ANSI::Fold->new(
289 1085 map { $_ => $app->$_ }
290 116 grep { defined $app->$_ }
291 qw(width boundary padding trim padchar prefix ambiguous
292 margin linebreak runin runout
293 splitwide lefthalf righthalf
294 expand tabstyle tabstop tabhead tabspace discard)
295 );
296  
297 116 ▶ my $separator = eval sprintf(qq["%s"], $app->separate) // do {
Subroutine BEGIN: called CC=1 SCAR=0.2
Condition33%1/3
eval sprintf(""%s"", $app->separate) // do { warn $@ =~ s/ at .*//ru; $App::ansifold::DEFAULT_SEPARATE }
l!l&&r!l&&!r
11600
MC/DC0%0/2
eval sprintf(""%s"", $app->separate) // do { warn $@ =~ s/ at .*//ru; $App::ansifold::DEFAULT_SEPARATE }
eval sprintf(""%s"", $app->separate) do { warn $@ =~ s/ at .*//ru; $App::ansifold::DEFAULT_SEPARATE }
Truth table33%1/3
A // B
A= eval sprintf(""%s"", $app->separate)B= do { warn $@ =~ s/ at .*//ru; $App::ansifold::DEFAULT_SEPARATE }
ABresult
1X1
011
000
298 0 warn $@ =~ s/ at .*//r;
299 0 $DEFAULT_SEPARATE;
300 };
301  
302 116 my @index = @{$app->width_index};
303  
304 116 ▶ local $/ = "\n\n" if $app->refill;
Branch: 1 branch
BranchTrueFalseTotal
if $app->refill 6 110 116
305 116 ▶ while (<>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 118 116 234
306 118 ▶ if (not $app->padding and s/\A(\n+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $app->padding and s/\A(\n+)//u) 0 118 118
Condition66%2/3
not $app->padding and s/\A(\n+)//u
!ll&&!rl&&r
31150
MC/DC0%0/2
not $app->padding and s/\A(\n+)//u
not $app->padding s/\A(\n+)//u
Truth table66%2/3
not(A) and B
A= not $app->paddingB= s/\A(\n+)//u
ABresult
0X0
100
111
307 0 print $1;
308 0 ▶ next if length == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ == 0 0 0 0
309 }
310 # chomp() does not remove single "\n" when $/ is "\n\n"
311 118 ▶ my $chomped = s/(\R+)\z// ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
s/(\R+)\z//u ? : 88 30 118
312 118 ▶ my $eol = $chomped =~ /\r/ ? "\r\n" : "\n";
Branch: 1 branch
BranchTrueFalseTotal
$chomped =~ /\r/u ? : 1 117 118
313 118 ▶ fill_paragraph() if $app->refill;
Branch: 1 branch
BranchTrueFalseTotal
if $app->refill 8 110 118
314 118 ▶ fill_cr() if $app->crmode;
Branch: 1 branch
BranchTrueFalseTotal
if $app->crmode 23 95 118
315 118 ▶ if ($app->{indent_pat} && /^$app->{indent_pat}/p) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->{"indent_pat"} and /^$app->{"indent_pat"}/pu) 17 101 118
Condition66%2/3
$app->{"indent_pat"} and /^$app->{"indent_pat"}/pu
!ll&&!rl&&r
101017
MC/DC50%1/2
$app->{"indent_pat"} and /^$app->{"indent_pat"}/pu
$app->{"indent_pat"} /^$app->{"indent_pat"}/pu
Truth table66%2/3
A and B
A= $app->{"indent_pat"}B= /^$app->{"indent_pat"}/pu
ABresult
0X0
100
111
316 17 my $matched = ${^MATCH};
317 # an indent which leaves no room for the text is given up,
318 # and the line is folded without it
319 17 ▶ if (ansi_width($matched) >= $app->min_width) {
Branch: 1 branch
BranchTrueFalseTotal
if (ansi_width($matched) >= $app->min_width) { } 1 16 17
320 1 $fold->configure(prefix => '');
321 } else {
322 16 my @spans = map { [ $-[$_], $+[$_] ] } grep { defined $-[$_] } 1 .. $#-;
323 16 $fold->configure(prefix => $app->indent_prefix($matched, \@spans));
324 }
325 }
326 118 my @chops = $fold->text($_)->chops;
327 118 ▶ if (ref $app->width eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $app->width eq "ARRAY") 45 73 118
328 45 ▶ while (my($i, $w) = each @{$app->width}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @{$app->width;}) 122 45 167
329 122 ▶ $w = 0 if not $app->padding or $w < 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $app->padding or $w < 0 122 0 122
Condition33%1/3
not $app->padding or $w < 0
l!l&&r!l&&!r
12200
MC/DC0%0/2
not $app->padding or $w < 0
not $app->padding $w < 0
Truth table33%1/3
not(A) or B
A= not $app->paddingB= $w < 0
ABresult
1X1
011
000
330 122 ▶ $chops[$i] //= ' ' x $w;
Condition100%2/2
$chops[$i] //= " " x $w
l!l
1211
MC/DC100%1/1
$chops[$i] //= " " x $w
$chops[$i]
Truth table100%2/2
A
A= $chops[$i]
Aresult
11
00
331 }
332 }
333 118 ▶ if (@index > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@index > 0) 45 73 118
334 45 @chops = grep { defined } @chops[@index];
335 }
336 # the text has newlines if it has paragraphs divided by white space
337 118 ▶ /\R\z/ or $_ .= $separator for @chops[0 .. $#chops - 1];
Branch: 1 branch
BranchTrueFalseTotal
/\R\z/u or $_ .= $separator 6 90 96
338 118 print @chops;
339 118 ▶ print $chomped if $chomped;
Branch: 1 branch
BranchTrueFalseTotal
if $chomped 88 30 118
340 118 ▶ print $eol x $app->paragraph if $app->paragraph > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $app->paragraph > 0 0 118 118
341 }
342  
343 116 return $app;
344 }
345  
346 # These properties are used by App::mdee
347 # utf8::Hangul is Script_Extensions, which takes CJK punctuation as well
348 0 ▶sub InConcatScript {
Subroutine InConcatScript: not called CC=1 SCAR=6.9
Pod undocumented
349 0 return <<"END";
350 +App::ansifold::InFullwidth
351 -utf8::Script=Hangul
352 END
353 }
354  
355 0 ▶sub InFullwidthPunctuation {
Subroutine InFullwidthPunctuation: not called CC=1 SCAR=6.9
Pod undocumented
356 0 return <<"END";
357 +App::ansifold::InFullwidth
358 &utf8::Punctuation
359 END
360 }
361  
362 8 ▶sub fill_paragraph {
Subroutine fill_paragraph: called CC=1 SCAR=0.0
Pod undocumented
363 8 $_ = ansi_unfold($_);
364 }
365  
366 23 ▶sub fill_cr {
Subroutine fill_cr: called CC=1 SCAR=0.0
Pod undocumented
367 23 $_ = ansi_unfold($_, newline => qr{\r});
368 }
369  
370 0 ▶sub terminal_width {
Subroutine terminal_width: not called CC=3 SCAR=19.2
Pod undocumented
371 135 ▶ use Term::ReadKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
372 0 my $default = 80;
373 0 my @size;
374 0 ▶ if (open my $tty, ">", "/dev/tty") {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $tty, ">", "/dev/tty") 0 0 0
375 # Term::ReadKey 2.31 on macOS 10.15 has a bug in argument handling
376 # and the latest version 2.38 fails to install.
377 # This code should work on both versions.
378 0 @size = GetTerminalSize $tty, $tty;
379 }
380 0 ▶ $size[0] or $default;
Branch: 1 branch
BranchTrueFalseTotal
$size[0] or $default 0 0 0
381 }
382  
383 11 ▶sub colrm_to_width {
Subroutine colrm_to_width: called CC=7 SCAR=19.5
Pod undocumented
384 11 my @width;
385 11 my $pos = 0;
386 11 ▶ while (my($start, $end) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 12 6 18
387 12 ▶ $pos < $start or die "$start: invalid arg\n";
Branch: 1 branch
BranchTrueFalseTotal
$pos < $start or die "${start}: invalid arg\n" 12 0 12
388 12 $start--;
389 12 ▶ push @width,
Branch: 1 branch
BranchTrueFalseTotal
defined $end ? : 7 5 12
390 $start - $pos,
391 defined $end ? $start - $end : '';
392 12 ▶ $pos = $end // last;
Condition100%2/2
$end // (last)
l!l
75
MC/DC100%1/1
$end // (last)
$end
Truth table100%2/2
A
A= $end
Aresult
11
00
393 }
394 11 ▶ push @width, -1 if @width == 0 or $width[-1] ne '';
Branch: 1 branch
BranchTrueFalseTotal
if @width == 0 or $width[-1] ne "" 6 5 11
Condition100%3/3
@width == 0 or $width[-1] ne ""
l!l&&r!l&&!r
155
MC/DC100%2/2
@width == 0 or $width[-1] ne ""
@width == 0 $width[-1] ne ""
Truth table100%3/3
A or B
A= @width == 0B= $width[-1] ne ""
ABresult
1X1
011
000
395 11 join ',', @width;
396 }
397  
398 7 ▶sub cut_to_width {
Subroutine cut_to_width: called CC=11 SCAR=24.0
Pod undocumented
399 7 my $list = shift;
400 7 my @params = split /[\s,]+/, $list;
401 7 my @width;
402 7 my $pos = 1;
403 7 for (@params) {
404 12 ▶ next if $_ eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "" 0 12 12
405 12 ▶ my($start, $end) =
Branch: 4 branches
BranchTrueFalseTotal
/^(\d+)$/u ? : 6 6 12
/^-(\d+)/u ? : 1 5 6
/^(\d+)-$/u ? : 1 4 5
/^(\d+)-(\d+)$/u ? : 4 0 4
406 /^(\d+)$/ ? ( $1, $1 ) :
407 /^-(\d+)/ ? ( $pos, $1 ) :
408 /^(\d+)-$/ ? ( $1, -1 ) :
409 /^(\d+)-(\d+)$/ ? ( $1, $2 ) : die "$list: format error";
410 12 ▶ $pos <= $start or die "$start: invalid arg\n";
Branch: 1 branch
BranchTrueFalseTotal
$pos <= $start or die "${start}: invalid arg\n" 12 0 12
411 12 ▶ if ($start > $pos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start > $pos) 8 4 12
412 8 push @width, $pos - $start;
413 }
414 12 ▶ if ($end < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end < 0) { } 1 11 12
415 1 push @width, -1;
416 1 last;
417 } else {
418 11 push @width, $end - $start + 1;
419 }
420 11 $pos = $end + 1;
421 }
422 7 ▶ push @width, 0 if $width[-1] != -1;
Branch: 1 branch
BranchTrueFalseTotal
if $width[-1] != -1 6 1 7
423 7 join ',', @width;
424 }
425  
426 135 1;
427  
428 __END__
↑ Summary