To/Doc/Role/Section.pm

filter: Statementstmt 71.2% 52 / 73 Branchbran 67.8% 19 / 28 Conditioncond 33.3% 4 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 70.0% 7 / 10 Podpod 100% 6 / 6 totaltotal 66.1% 90 / 136 CC 21 SCAR 22.7
CC
21
Cov
66%
gen_doc
30.0
dec_doc_indent
12.0
add_doc_section_before
6.0
CRAP 9.7
« To/PackageBase.pm ↑ Summary To/Doc.pm »
1 package Perinci::To::Doc::Role::Section;
2  
3 8 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 has doc_sections => (is=>'rw');
8 8 has doc_lines => (is => 'rw'); # store final result, array
9 8 has doc_indent_level => (is => 'rw');
10 1 ▶has doc_indent_str => (is => 'rw', default => sub{" "}); # indent characters
Subroutine __ANON__: called CC=1 SCAR=0.0
11  
12 8 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13 8 our $DATE = '2023-07-09'; # DATE
14 8 our $DIST = 'Perinci-To-Doc'; # DIST
15 8 our $VERSION = '0.881'; # VERSION
16  
17 3 ▶sub add_doc_section_before {
Subroutine add_doc_section_before: called CC=6 SCAR=18.0
Pod documented
18 3 my ($self, $name, $before) = @_;
19 3 my $ss = $self->doc_sections;
20 3 ▶ return unless $ss;
Branch: 1 branch
BranchTrueFalseTotal
unless $ss 0 3 3
21 3 my $i = 0;
22 3 my $added;
23 3 ▶ while ($i < @$ss && defined($before)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$ss and defined $before) 8 1 9
Condition66%2/3
$i < @$ss and defined $before
!ll&&!rl&&r
108
MC/DC50%1/2
$i < @$ss and defined $before
$i < @$ss defined $before
Truth table66%2/3
A and B
A= $i < @$ssB= defined $before
ABresult
0X0
100
111
24 8 ▶ if ($ss->[$i] eq $before) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss->[$i] eq $before) 2 6 8
25 2 my $pos = $i;
26 2 splice @$ss, $pos, 0, $name;
27 2 $added++;
28 2 last;
29 }
30 6 $i++;
31 }
32 3 ▶ unshift @$ss, $name unless $added;
Branch: 1 branch
BranchTrueFalseTotal
unless $added 1 2 3
33 }
34  
35 3 ▶sub add_doc_section_after {
Subroutine add_doc_section_after: called CC=6 SCAR=18.0
Pod documented
36 3 my ($self, $name, $after) = @_;
37 3 my $ss = $self->doc_sections;
38 3 ▶ return unless $ss;
Branch: 1 branch
BranchTrueFalseTotal
unless $ss 0 3 3
39 3 my $i = 0;
40 3 my $added;
41 3 ▶ while ($i < @$ss && defined($after)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$ss and defined $after) 11 1 12
Condition66%2/3
$i < @$ss and defined $after
!ll&&!rl&&r
1011
MC/DC50%1/2
$i < @$ss and defined $after
$i < @$ss defined $after
Truth table66%2/3
A and B
A= $i < @$ssB= defined $after
ABresult
0X0
100
111
42 11 ▶ if ($ss->[$i] eq $after) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss->[$i] eq $after) 2 9 11
43 2 my $pos = $i+1;
44 2 splice @$ss, $pos, 0, $name;
45 2 $added++;
46 2 last;
47 }
48 9 $i++;
49 }
50 3 ▶ push @$ss, $name unless $added;
Branch: 1 branch
BranchTrueFalseTotal
unless $added 1 2 3
51 }
52  
53 3 ▶sub delete_doc_section {
Subroutine delete_doc_section: called CC=4 SCAR=13.9
Pod documented
54 3 my ($self, $name) = @_;
55 3 my $ss = $self->doc_sections;
56 3 ▶ return unless $ss;
Branch: 1 branch
BranchTrueFalseTotal
unless $ss 0 3 3
57 3 my $i = 0;
58 3 ▶ while ($i < @$ss) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$ss) 6 3 9
59 6 ▶ if ($ss->[$i] eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss->[$i] eq $name) { } 2 4 6
60 2 splice @$ss, $i, 1;
61 } else {
62 4 $i++;
63 }
64 }
65 }
66  
67 0 ▶sub inc_doc_indent {
Subroutine inc_doc_indent: not called CC=2 SCAR=17.9
Pod documented
68 0 my ($self, $n) = @_;
69 0 ▶ $n //= 1;
Condition0%0/2
$n //= 1
l!l
00
MC/DC0%0/1
$n //= 1
$n
Truth table0%0/2
A
A= $n
Aresult
11
00
70 0 $self->{doc_indent_level} += $n;
71 }
72  
73 0 ▶sub dec_doc_indent {
Subroutine dec_doc_indent: not called CC=3 SCAR=24.8
Pod documented
74 0 my ($self, $n) = @_;
75 0 ▶ $n //= 1;
Condition0%0/2
$n //= 1
l!l
00
MC/DC0%0/1
$n //= 1
$n
Truth table0%0/2
A
A= $n
Aresult
11
00
76 0 $self->{doc_indent_level} -= $n;
77 0 ▶ die "BUG: Negative doc indent level" unless $self->{doc_indent_level} >=0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"doc_indent_level"} >= 0 0 0 0
78 }
79  
80 0 ▶sub gen_doc {
Subroutine gen_doc: not called CC=5 SCAR=34.0
Pod documented
81 0 my ($self, %opts) = @_;
82 0 log_trace("-> gen_doc(opts=%s)", \%opts);
83  
84 0 $self->doc_lines([]);
85 0 $self->doc_indent_level(0);
86  
87 0 ▶ $self->before_gen_doc(%opts) if $self->can("before_gen_doc");
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("before_gen_doc") 0 0 0
88  
89 0 ▶ for my $s (@{ $self->doc_sections // [] }) {
Condition0%0/2
$self->doc_sections // []
l!l
00
MC/DC0%0/1
$self->doc_sections // []
$self->doc_sections
Truth table0%0/2
A
A= $self->doc_sections
Aresult
11
00
90 0 my $meth = "gen_doc_section_$s";
91 0 log_trace("=> $meth(%s)", \%opts);
92 0 $self->$meth(%opts);
93 }
94  
95 0 ▶ $self->after_gen_doc(%opts) if $self->can("after_gen_doc");
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("after_gen_doc") 0 0 0
96  
97 0 log_trace("<- gen_doc()");
98 0 join("", @{ $self->doc_lines });
99 }
100  
101 8 1;
102 # ABSTRACT: Role for class that generates documentation with sections
103  
104 __END__
« To/PackageBase.pm ↑ Summary To/Doc.pm »