Data/Unixish/wrap.pm

filter: Statementstmt 91.6% 44 / 48 Branchbran 50.0% 5 / 10 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 80.7% 63 / 78 CC 8 SCAR 15.3
CC
8
Cov
81%
_wrap_item
11.2
_wrap_begin
2.1
wrap
2.0
CRAP 4.6
« Data/Unixish/shuf.pm ↑ Summary Data/Unixish/count.pm »
1 package Data::Unixish::wrap;
2  
3 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use syntax 'each_on_array'; # to support perl < 5.12
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #use Log::Any '$log';
8  
9 2 ▶use Data::Unixish::Util qw(%common_args);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Text::ANSI::Util qw(ta_wrap);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Text::ANSI::WideUtil qw(ta_mbwrap);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Text::WideChar::Util qw(mbwrap);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
15 2 our $DATE = '2025-02-24'; # DATE
16 2 our $DIST = 'Data-Unixish'; # DIST
17 2 our $VERSION = '1.574'; # VERSION
18  
19 2 our %SPEC;
20  
21 $SPEC{wrap} = {
22 2 v => 1.1,
23 summary => 'Wrap text',
24 args => {
25 %common_args,
26 width => {
27 summary => 'Target column width',
28 schema =>[int => {default=>80, min=>1}],
29 cmdline_aliases => { c=>{} },
30 pos => 0,
31 },
32 ansi => {
33 summary => 'Whether to handle ANSI escape codes',
34 schema => ['bool', default => 0],
35 },
36 mb => {
37 summary => 'Whether to handle wide characters',
38 schema => ['bool', default => 0],
39 },
40 },
41 tags => [qw/text itemfunc/],
42 };
43 1 ▶sub wrap {
Subroutine wrap: called CC=2 SCAR=6.9
Pod documented
44 1 my %args = @_;
45 1 my ($in, $out) = ($args{in}, $args{out});
46  
47 1 _wrap_begin(\%args);
48 1 ▶ while (my ($index, $item) = each @$in) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @$in) 1 1 2
49 1 push @$out, _wrap_item($item, \%args);
50 }
51  
52 1 [200, "OK"];
53 }
54  
55 2 ▶sub _wrap_begin {
Subroutine _wrap_begin: called CC=2 SCAR=7.2
56 2 my $args = shift;
57 2 ▶ $args->{width} //= 80;
Condition50%1/2
$args->{"width"} //= 80
l!l
20
MC/DC0%0/1
$args->{"width"} //= 80
$args->{"width"}
Truth table50%1/2
A
A= $args->{"width"}
Aresult
11
00
58 }
59  
60 2 ▶sub _wrap_item {
Subroutine _wrap_item: called CC=6 SCAR=24.1
61 2 my ($item, $args) = @_;
62 {
63 2 ▶ last if !defined($item) || ref($item);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $item or ref $item 0 2 2
Condition33%1/3
not defined $item or ref $item
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $item or ref $item
not defined $item ref $item
Truth table33%1/3
not(A) or B
A= not defined $itemB= ref $item
ABresult
1X1
011
000
64 2 ▶ if ($args->{ansi}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args->{'ansi'}) { } 0 2 2
elsif ($args->{'mb'}) { } 0 2 2
65 0 ▶ if ($args->{mb}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'mb'}) { } 0 0 0
66 0 $item = ta_mbwrap($item, $args->{width});
67 } else {
68 0 $item = ta_wrap ($item, $args->{width});
69 }
70 } elsif ($args->{mb}) {
71 0 $item = mbwrap($item, $args->{width});
72 } else {
73 2 $item = Text::WideChar::Util::wrap($item, $args->{width});
74 }
75 }
76 2 return $item;
77 }
78  
79 2 1;
80 # ABSTRACT: Wrap text
81  
82 __END__
« Data/Unixish/shuf.pm ↑ Summary Data/Unixish/count.pm »