Data/Sah/Compiler/TextResultRole.pm

filter: Statementstmt 77.2% 34 / 44 Branchbran 75.0% 3 / 4 Conditioncond 33.3% 5 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 66.6% 8 / 12 Podpod 100% 5 / 5 totaltotal 61.8% 55 / 89 CC 9 SCAR 16.8
CC
9
Cov
67%
_indent
10.4
add_result
6.0
inc_indent
2.0
CRAP 5.4
« Data/Sah/Compiler/perl/TH/num.pm ↑ Summary Data/Sah/Compiler/perl/TH/bool.pm »
1 package Data::Sah::Compiler::TextResultRole;
2  
3 29 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 29 ▶use Mo qw(default);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 29 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # can be changed to tab, for example
11 0 ▶has indent_character => (is => 'rw', default => sub {''});
Subroutine __ANON__: not called CC=1 SCAR=1.2
12  
13 29 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
14 29 our $DATE = '2024-02-16'; # DATE
15 29 our $DIST = 'Data-Sah'; # DIST
16 29 our $VERSION = '0.917'; # VERSION
17  
18 0 ▶sub add_result {
Subroutine add_result: not called CC=2 SCAR=17.9
Pod documented
19 0 my ($self, $cd, @args) = @_;
20  
21 0 ▶ $cd->{result} //= [];
Condition0%0/2
$cd->{"result"} //= []
l!l
00
MC/DC0%0/1
$cd->{"result"} //= []
$cd->{"result"}
Truth table0%0/2
A
A= $cd->{"result"}
Aresult
11
00
22 0 push @{ $cd->{result} }, $self->indent($cd, join("", @args));
23 0 $self;
24 }
25  
26 # BEGIN COPIED FROM String::Indent
27 5199 ▶sub _indent {
Subroutine _indent: called CC=8 SCAR=23.4
28 5199 my ($indent, $str, $opts) = @_;
29 5199 ▶ $opts //= {};
Condition50%1/2
$opts //= {}
l!l
05199
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
30  
31 5199 ▶ my $ibl = $opts->{indent_blank_lines} // 1;
Condition50%1/2
$opts->{"indent_blank_lines"} // 1
l!l
05199
MC/DC0%0/1
$opts->{"indent_blank_lines"} // 1
$opts->{"indent_blank_lines"}
Truth table50%1/2
A
A= $opts->{"indent_blank_lines"}
Aresult
11
00
32 5199 ▶ my $fli = $opts->{first_line_indent} // $indent;
Condition33%1/3
$opts->{"first_line_indent"} // $indent
l!l&&r!l&&!r
051990
MC/DC0%0/2
$opts->{"first_line_indent"} // $indent
$opts->{"first_line_indent"} $indent
Truth table33%1/3
A // B
A= $opts->{"first_line_indent"}B= $indent
ABresult
1X1
011
000
33 5199 ▶ my $sli = $opts->{subsequent_lines_indent} // $indent;
Condition33%1/3
$opts->{"subsequent_lines_indent"} // $indent
l!l&&r!l&&!r
051990
MC/DC0%0/2
$opts->{"subsequent_lines_indent"} // $indent
$opts->{"subsequent_lines_indent"} $indent
Truth table33%1/3
A // B
A= $opts->{"subsequent_lines_indent"}B= $indent
ABresult
1X1
011
000
34 #say "D:ibl=<$ibl>, fli=<$fli>, sli=<$sli>";
35  
36 5199 my $i = 0;
37 5199 ▶ $str =~ s/^([^\r\n]?)/$i++; !$ibl && !$1 ? "$1" : $i==1 ? "$fli$1" : "$sli$1"/egm;
Branch: 2 branches
BranchTrueFalseTotal
!($ibl || $1) ? : 0 70983 70983
$i == 1 ? : 5199 65784 70983
Condition33%1/3
$ibl || $1
l!l&&r!l&&!r
7098300
MC/DC0%0/2
$ibl || $1
$ibl $1
Truth table33%1/3
A || B
A= $iblB= $1
ABresult
1X1
011
000
38 5199 $str;
39 }
40 # END COPIED FROM String::Indent
41  
42 5199 ▶sub indent {
Subroutine indent: called CC=1 SCAR=0.0
Pod documented
43 5199 my ($self, $cd, $str) = @_;
44 _indent(
45 $self->indent_character x $cd->{indent_level},
46 5199 $str,
47 );
48 }
49  
50 0 ▶sub inc_indent {
Subroutine inc_indent: not called CC=1 SCAR=6.9
Pod documented
51 0 my ($self, $cd) = @_;
52 0 $cd->{indent_level}++;
53 }
54  
55 0 ▶sub dec_indent {
Subroutine dec_indent: not called CC=1 SCAR=6.9
Pod documented
56 0 my ($self, $cd) = @_;
57 0 $cd->{indent_level}--;
58 }
59  
60 566 ▶sub indent_str {
Subroutine indent_str: called CC=1 SCAR=0.0
Pod documented
61 566 my ($self, $cd) = @_;
62 566 $self->indent_character x $cd->{indent_level};
63 }
64  
65 29 1;
66 # ABSTRACT: Role for compilers that produce text result (array of lines)
67  
68 __END__
« Data/Sah/Compiler/perl/TH/num.pm ↑ Summary Data/Sah/Compiler/perl/TH/bool.pm »