blib/lib/App/ansifold.pm

filter: Statementstmt 92.5% 287 / 310 Branchbran 74.1% 89 / 120 Conditioncond 61.8% 34 / 55 MC/DCmcdc 39.3% 13 / 33 Subroutinesub 90.0% 45 / 50 Podpod 0.0% 0 / 17 totaltotal 80.0% 468 / 585 CC 82 SCAR 24.7
CC
82
Cov
85%
doit
27.5
options
25.5
cut_to_width
11.1
CRAP 11.9
↑ Summary
1 package App::ansifold;
2 124 our $VERSION = "1.39";
3  
4 124 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 124 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 124 ▶use open IO => 'utf8', ':std';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 124 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 124 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 124 ▶use List::Util qw(min);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 124 ▶use Hash::Util qw(lock_keys);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 124 ▶use Text::ANSI::Fold qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 124 ▶use Text::ANSI::Fold::Util qw(ansi_width); {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 124 Text::ANSI::Fold->configure(expand => 1);
16 }
17 124 ▶use Unicode::EastAsianWidth;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 124 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 124 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 124 our @EXPORT_OK = qw(ansifold ansiexpand ansicolrm ansicut);
22  
23 124 ▶our $DEFAULT_WIDTH //= 72;
Condition100%2/2
our $DEFAULT_WIDTH //= 72
l!l
4120
MC/DC100%1/1
our $DEFAULT_WIDTH //= 72
our $DEFAULT_WIDTH
Truth table100%2/2
A
A= our $DEFAULT_WIDTH
Aresult
11
00
24 124 ▶our $DEFAULT_SEPARATE //= "\n";
Condition100%2/2
our $DEFAULT_SEPARATE //= " "
l!l
3121
MC/DC100%1/1
our $DEFAULT_SEPARATE //= " "
our $DEFAULT_SEPARATE
Truth table100%2/2
A
A= our $DEFAULT_SEPARATE
Aresult
11
00
25 124 ▶our $DEFAULT_EXPAND //= 0;
Condition100%2/2
our $DEFAULT_EXPAND //= 0
l!l
4120
MC/DC100%1/1
our $DEFAULT_EXPAND //= 0
our $DEFAULT_EXPAND
Truth table100%2/2
A
A= our $DEFAULT_EXPAND
Aresult
11
00
26 124 ▶our $DEFAULT_COLRM //= 0;
Condition100%2/2
our $DEFAULT_COLRM //= 0
l!l
3121
MC/DC100%1/1
our $DEFAULT_COLRM //= 0
our $DEFAULT_COLRM
Truth table100%2/2
A
A= our $DEFAULT_COLRM
Aresult
11
00
27 124 ▶our $DEFAULT_CUT //= 0;
Condition50%1/2
our $DEFAULT_CUT //= 0
l!l
0124
MC/DC0%0/1
our $DEFAULT_CUT //= 0
our $DEFAULT_CUT
Truth table50%1/2
A
A= our $DEFAULT_CUT
Aresult
11
00
28 124 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 124 ▶use Getopt::EX::Hashed 'has'; {
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 124 Getopt::EX::Hashed->configure(DEFAULT => [ is => 'rw' ]);
54  
55 124 has width => ' w =s@ ' , default => [];
56 124 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 124 };
61 124 has padchar => ' =s ' ;
62 124 has trim => ' ! ' ;
63 124 has prefix => ' =s ' ;
64 124 has autoindent => ' =s ' ;
65 124 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 124 has indentchar => ' =s ' , default => ' ';
68 124 has ambiguous => ' =s ' ;
69 124 has paragraph => ' p + ' , default => 0;
70 124 has refill => ' r + ' , default => 0;
71 113 ▶ has separate => ' =s ' , default => sub { $DEFAULT_SEPARATE };
Subroutine __ANON__: called CC=1 SCAR=0.0
72 124 has linebreak => ' =s ' , alias => 'lb';
73 124 has runin => ' =i ' , min => 0, default => 4;
74 124 has runout => ' =i ' , min => 0, default => 4;
75 124 has runlen => ' =i ' , min => 0;
76 124 has margin => ' =i ' , min => 0;
77 124 has nonewline => ' n ' ;
78 124 has splitwide => ' :s ' , default => $DEFAULT_SPLITWIDE;
79 124 ▶ has lefthalf => ' =s ' , default => "\N{LEFT HALF BLACK CIRCLE}";
Subroutine BEGIN: called CC=1 SCAR=0.0
80 124 has righthalf => ' =s ' , default => "\N{RIGHT HALF BLACK CIRCLE}";
81 124 has smart => ' s ! ' ;
82 124 has crmode => ' ! ' ;
83  
84 16 ▶ has '+crmode' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
85 16 $_->{$_[0]} = $_[1];
86 16 ▶ $_->separate = "\r" if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 15 1 16
87 124 };
88 113 ▶ has expand => ' x :-1 ' , default => sub { $DEFAULT_EXPAND };
Subroutine __ANON__: called CC=1 SCAR=0.0
89 124 has tabstop => ' =i ' , min => 1;
90 124 has tabhead => ' =s ' ;
91 124 has tabspace => ' =s ' ;
92 124 has tabstyle => ' =s ' ;
93 124 has discard => ' =s@ ' , default => [];
94 113 ▶ has colrm => ' ' , default => sub { $DEFAULT_COLRM };
Subroutine __ANON__: called CC=1 SCAR=0.0
95 124 has cut => ' c =s ' ;
96 124 has debug => ' d ' ;
97 124 has help => ' h ' ;
98 124 has version => ' v ' ;
99  
100 124 has '+boundary' => any => [ qw(none word space) ];
101 124 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 124 };
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 124 };
113  
114 14 ▶ has '+nonewline' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
115 14 $_->separate = "";
116 124 };
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 124 };
131  
132 ### --runlen
133 1 ▶ has '+runlen' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
134 1 $_->runin = $_->runout = $_[1];
135 124 };
136 # for backward compatibility, would be deplicated
137 124 has run => '=i';
138 0 ▶ has '+run' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
139 0 $_->runin = $_->runout = $_[1];
140 124 };
141  
142 24 ▶ has '+smart' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
143 24 my $smart = $_->{$_[0]} = $_[1];
144 24 ($_->boundary, $_->linebreak, $_->trim) = do {
145 24 ▶ if ($smart) {
Branch: 1 branch
BranchTrueFalseTotal
if ($smart) { } 23 1 24
146 23 ('word', LINEBREAK_ALL, 1);
147 } else {
148 1 ('none', LINEBREAK_NONE, 0);
149 }
150 };
151 124 };
152  
153 # internal use
154 124 has width_index => default => [];
155 124 has indent_pat => ;
156 124 has min_width => ;
157  
158 124 ▶} no Getopt::EX::Hashed;
Subroutine BEGIN: called CC=1 SCAR=0.0
159  
160 111 ▶sub perform {
Subroutine perform: called CC=1 SCAR=0.0
Pod undocumented
161 111 my $app = shift;
162 111 local @ARGV = @_;
163 111 $app->options->params->doit;
164 105 return 0;
165 }
166  
167 111 ▶sub options {
Subroutine options: called CC=20 SCAR=32.4
Pod undocumented
168 111 my $app = shift;
169  
170 111 for (@ARGV) {
171 376 ▶ $_ = decode 'utf8', $_ unless utf8::is_utf8($_);
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($_) 376 0 376
172 }
173  
174 124 ▶ use Getopt::EX::Long qw(:DEFAULT ExConfigure Configure);
Subroutine BEGIN: called CC=1 SCAR=0.0
175 111 ExConfigure BASECLASS => [ __PACKAGE__, 'Getopt::EX' ];
176 111 Configure "bundling";
177 111 ▶ $app->getopt || pod2usage();
Branch: 1 branch
BranchTrueFalseTotal
$app->getopt or pod2usage() 105 6 111
178  
179 ## --colrm
180 105 ▶ if ($app->colrm) {
Branch: 2 branches
BranchTrueFalseTotal
if ($app->colrm) { } 11 94 105
elsif ($app->cut) { } 7 87 94
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 105 ▶ if ($app->expand > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->expand > 0) 0 105 105
193 0 $app->tabstop = $app->expand;
194 }
195  
196 105 ▶ $app->separate //= $DEFAULT_SEPARATE;
Condition33%1/3
$app->separate //= $App::ansifold::DEFAULT_SEPARATE
l!l&&r!l&&!r
10500
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 124 ▶ use charnames ':loose';
Subroutine BEGIN: called CC=1 SCAR=0.0
199 105 for (@{$app}{qw(tabhead tabspace)}) {
200 210 ▶ defined && length > 1 or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ > 1 or next 0 210 210
Condition33%1/3
defined $_ and length $_ > 1
!ll&&!rl&&r
21000
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 105 ▶ if (my $indent = $app->autoindent) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $indent = $app->autoindent) 15 90 105
205 15 ▶ if (($app->keepindent // '') eq 'named') {
Branch: 1 branch
BranchTrueFalseTotal
if (($app->keepindent // "") eq "named") 2 13 15
Condition100%2/2
$app->keepindent // ""
l!l
132
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 15 $app->indent_pat = qr/$indent/;
210 }
211  
212 105 ▶ if (defined (my $char = $app->splitwide)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $char = $app->splitwide)) 4 101 105
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 105 return $app;
221 }
222  
223 105 ▶sub params {
Subroutine params: called CC=9 SCAR=23.2
Pod undocumented
224 105 my $app = shift;
225  
226 124 ▶ use Getopt::EX::Numbers;
Subroutine BEGIN: called CC=1 SCAR=0.0
227 105 my $numbers = Getopt::EX::Numbers->new;
228  
229 105 my @width = do {
230 map {
231 173 ▶ if (/^$/) { 0 } # empty
Branch: 4 branches
BranchTrueFalseTotal
if (/^$/u) { } 28 145 173
elsif (/^-?\d+$/u) { } 145 0 145
elsif (/^(-?[-\d:]+) (?:\{(\d+)\})? $/ux) { } 0 0 0
elsif (/^=(.*)/u) { } 0 0 0
232 145 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 96 map { split /,/, $_, -1 }
243 105 @{$app->width};
244 };
245  
246 105 $app->width = do {
247 105 ▶ if (@width == 0) { $DEFAULT_WIDTH }
Branch: 2 branches
BranchTrueFalseTotal
if (@width == 0) { } 9 96 105
elsif (@width == 1) { } 51 45 96
248 51 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 105 ▶ $app->min_width = ref $app->width ? min @{$app->width} : $app->width;
Branch: 1 branch
BranchTrueFalseTotal
ref $app->width ? : 45 60 105
259  
260 105 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 15 ▶sub indent_prefix {
Subroutine indent_prefix: called CC=9 SCAR=22.0
Pod undocumented
269 15 my($app, $matched, $spans) = @_;
270 15 my $keep = $app->keepindent;
271 15 ▶ return $app->indentchar x ansi_width($matched) if not defined $keep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keep 2 13 15
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 105 ▶sub doit {
Subroutine doit: called CC=22 SCAR=33.1
Pod undocumented
286 105 my $app = shift;
287  
288 my $fold = Text::ANSI::Fold->new(
289 984 map { $_ => $app->$_ }
290 105 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 105 ▶ 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
10500
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 105 my @index = @{$app->width_index};
303  
304 105 ▶ local $/ = "\n\n" if $app->refill;
Branch: 1 branch
BranchTrueFalseTotal
if $app->refill 0 105 105
305 105 ▶ while (<>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 104 105 209
306 104 ▶ if (not $app->padding and s/\A(\n+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $app->padding and s/\A(\n+)//u) 0 104 104
Condition66%2/3
not $app->padding and s/\A(\n+)//u
!ll&&!rl&&r
31010
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 104 ▶ my $chomped = s/(\R+)\z// ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
s/(\R+)\z//u ? : 74 30 104
312 104 ▶ my $eol = $chomped =~ /\r/ ? "\r\n" : "\n";
Branch: 1 branch
BranchTrueFalseTotal
$chomped =~ /\r/u ? : 0 104 104
313 104 ▶ fill_paragraph() if $app->refill;
Branch: 1 branch
BranchTrueFalseTotal
if $app->refill 0 104 104
314 104 ▶ fill_cr() if $app->crmode;
Branch: 1 branch
BranchTrueFalseTotal
if $app->crmode 19 85 104
315 104 ▶ if ($app->{indent_pat} && /^$app->{indent_pat}/p) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->{"indent_pat"} and /^$app->{"indent_pat"}/pu) 15 89 104
Condition66%2/3
$app->{"indent_pat"} and /^$app->{"indent_pat"}/pu
!ll&&!rl&&r
89015
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 15 my $matched = ${^MATCH};
317 15 my $indent = ansi_width $matched;
318 15 ▶ if ($indent >= $app->min_width) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indent >= $app->min_width) 0 15 15
319 0 die sprintf("%s\n%s\n%s\n", $_, ("^" x $indent),
320 "ERROR: Autoindent pattern is longer than folding width.");
321 }
322 15 my @spans = map { [ $-[$_], $+[$_] ] } grep { defined $-[$_] } 1 .. $#-;
323 15 $fold->configure(prefix => $app->indent_prefix($matched, \@spans));
324 }
325 104 my @chops = $fold->text($_)->chops;
326 104 ▶ if (ref $app->width eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $app->width eq "ARRAY") 45 59 104
327 45 ▶ while (my($i, $w) = each @{$app->width}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @{$app->width;}) 122 45 167
328 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
329 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
330 }
331 }
332 104 ▶ if (@index > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@index > 0) 45 59 104
333 45 @chops = grep { defined } @chops[@index];
334 }
335 104 print join $separator, @chops;
336 104 ▶ print $chomped if $chomped;
Branch: 1 branch
BranchTrueFalseTotal
if $chomped 74 30 104
337 104 ▶ print $eol x $app->paragraph if $app->paragraph > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $app->paragraph > 0 0 104 104
338 }
339  
340 105 return $app;
341 }
342  
343 15 ▶sub InConcatScript {
Subroutine InConcatScript: called CC=1 SCAR=0.0
Pod undocumented
344 15 return <<"END";
345 +App::ansifold::InFullwidth
346 -utf8::Hangul
347 END
348 }
349  
350 15 ▶sub InFullwidthPunctuation {
Subroutine InFullwidthPunctuation: called CC=1 SCAR=0.0
Pod undocumented
351 15 return <<"END";
352 +App::ansifold::InFullwidth
353 &utf8::Punctuation
354 END
355 }
356  
357 19 ▶sub fill_up {
Subroutine fill_up: called CC=2 SCAR=7.0
Pod undocumented
358 19 ▶ my $pat = shift // qr/\R/;
Condition50%1/2
shift() // qr/\R/u
l!l
190
MC/DC0%0/1
shift() // qr/\R/u
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
359 19 s/(?<=\p{InFullwidthPunctuation})$pat//g;
360 19 s/(?<=\p{InConcatScript})$pat(?=\p{InConcatScript})//g;
361 19 s/[ ]*$pat[ ]*/ /g;
362 }
363  
364 0 ▶sub fill_paragraph {
Subroutine fill_paragraph: not called CC=1 SCAR=6.9
Pod undocumented
365 0 fill_up(qr/\R/);
366 }
367  
368 19 ▶sub fill_cr {
Subroutine fill_cr: called CC=1 SCAR=0.0
Pod undocumented
369 19 fill_up(qr/\r/);
370 }
371  
372 0 ▶sub terminal_width {
Subroutine terminal_width: not called CC=3 SCAR=19.2
Pod undocumented
373 124 ▶ use Term::ReadKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
374 0 my $default = 80;
375 0 my @size;
376 0 ▶ if (open my $tty, ">", "/dev/tty") {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $tty, ">", "/dev/tty") 0 0 0
377 # Term::ReadKey 2.31 on macOS 10.15 has a bug in argument handling
378 # and the latest version 2.38 fails to install.
379 # This code should work on both versions.
380 0 @size = GetTerminalSize $tty, $tty;
381 }
382 0 ▶ $size[0] or $default;
Branch: 1 branch
BranchTrueFalseTotal
$size[0] or $default 0 0 0
383 }
384  
385 11 ▶sub colrm_to_width {
Subroutine colrm_to_width: called CC=7 SCAR=19.5
Pod undocumented
386 11 my @width;
387 11 my $pos = 0;
388 11 ▶ while (my($start, $end) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 12 6 18
389 12 ▶ $pos < $start or die "$start: invalid arg\n";
Branch: 1 branch
BranchTrueFalseTotal
$pos < $start or die "${start}: invalid arg\n" 12 0 12
390 12 $start--;
391 12 ▶ push @width,
Branch: 1 branch
BranchTrueFalseTotal
defined $end ? : 7 5 12
392 $start - $pos,
393 defined $end ? $start - $end : '';
394 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
395 }
396 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
397 11 join ',', @width;
398 }
399  
400 7 ▶sub cut_to_width {
Subroutine cut_to_width: called CC=11 SCAR=24.0
Pod undocumented
401 7 my $list = shift;
402 7 my @params = split /[\s,]+/, $list;
403 7 my @width;
404 7 my $pos = 1;
405 7 for (@params) {
406 12 ▶ next if $_ eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "" 0 12 12
407 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
408 /^(\d+)$/ ? ( $1, $1 ) :
409 /^-(\d+)/ ? ( $pos, $1 ) :
410 /^(\d+)-$/ ? ( $1, -1 ) :
411 /^(\d+)-(\d+)$/ ? ( $1, $2 ) : die "$list: format error";
412 12 ▶ $pos <= $start or die "$start: invalid arg\n";
Branch: 1 branch
BranchTrueFalseTotal
$pos <= $start or die "${start}: invalid arg\n" 12 0 12
413 12 ▶ if ($start > $pos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start > $pos) 8 4 12
414 8 push @width, $pos - $start;
415 }
416 12 ▶ if ($end < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end < 0) { } 1 11 12
417 1 push @width, -1;
418 1 last;
419 } else {
420 11 push @width, $end - $start + 1;
421 }
422 11 $pos = $end + 1;
423 }
424 7 ▶ push @width, 0 if $width[-1] != -1;
Branch: 1 branch
BranchTrueFalseTotal
if $width[-1] != -1 6 1 7
425 7 join ',', @width;
426 }
427  
428 124 1;
429  
430 __END__
↑ Summary