Data/Unixish/indent.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 6 / 6 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 96.4% 54 / 56 CC 6 SCAR 7.3
CC
6
Cov
98%
_indent_item
3.0
_indent_begin
3.0
indent
2.0
CRAP 2.1
« Data/Unixish/avg.pm ↑ Summary Data/Unixish/lc.pm »
1 package Data::Unixish::indent;
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  
11 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
12 2 our $DATE = '2025-02-24'; # DATE
13 2 our $DIST = 'Data-Unixish'; # DIST
14 2 our $VERSION = '1.574'; # VERSION
15  
16 2 our %SPEC;
17  
18 $SPEC{indent} = {
19 2 v => 1.1,
20 summary => 'Add spaces or tabs to the beginnning of each line of text',
21 args => {
22 %common_args,
23 num => {
24 summary => 'Number of spaces to add',
25 schema => ['int*', default=>4],
26 cmdline_aliases => {
27 n => {},
28 },
29 },
30 tab => {
31 summary => 'Number of spaces to add',
32 schema => ['bool' => default => 0],
33 cmdline_aliases => {
34 t => {},
35 },
36 },
37 },
38 tags => [qw/text itemfunc/],
39 };
40 3 ▶sub indent {
Subroutine indent: called CC=2 SCAR=6.9
Pod documented
41 3 my %args = @_;
42 3 my ($in, $out) = ($args{in}, $args{out});
43  
44 3 _indent_begin(\%args);
45 3 ▶ while (my ($index, $item) = each @$in) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @$in) 12 3 15
46 12 push @$out, _indent_item($item, \%args);
47 }
48  
49 3 [200, "OK"];
50 }
51  
52 6 ▶sub _indent_begin {
Subroutine _indent_begin: called CC=3 SCAR=11.0
53 6 my $args = shift;
54  
55 # args abused to store state
56 6 ▶ $args->{_indent} = ($args->{tab} ? "\t" : " ") x ($args->{num} // 4);
Branch: 1 branch
BranchTrueFalseTotal
$args->{'tab'} ? : 2 4 6
Condition100%2/2
$args->{"num"} // 4
l!l
42
MC/DC100%1/1
$args->{"num"} // 4
$args->{"num"}
Truth table100%2/2
A
A= $args->{"num"}
Aresult
11
00
57 }
58  
59 24 ▶sub _indent_item {
Subroutine _indent_item: called CC=3 SCAR=11.0
60 24 my ($item, $args) = @_;
61  
62 24 ▶ if (defined($item) && !ref($item)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $item and not ref $item) 18 6 24
Condition66%2/3
defined $item and not ref $item
!ll&&!rl&&r
0618
MC/DC50%1/2
defined $item and not ref $item
defined $item not ref $item
Truth table66%2/3
A and not(B)
A= defined $itemB= not ref $item
ABresult
0X0
100
111
63 18 $item =~ s/^/$args->{_indent}/mg;
64 }
65 24 return $item;
66 }
67  
68 2 1;
69 # ABSTRACT: Add spaces or tabs to the beginnning of each line of text
70  
71 __END__
« Data/Unixish/avg.pm ↑ Summary Data/Unixish/lc.pm »