| 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
| |||||||||||||||||||||||||||||
| 21 | 3 | my $i = 0; | |||||||||||||||||||||||||||
| 22 | 3 | my $added; | |||||||||||||||||||||||||||
| 23 | 3 | ▶ | while ($i < @$ss && defined($before)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i < @$ss and defined $before
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
| |||||||||||||||||||||||||||||
| 24 | 8 | ▶ | if ($ss->[$i] eq $before) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 39 | 3 | my $i = 0; | |||||||||||||||||||||||||||
| 40 | 3 | my $added; | |||||||||||||||||||||||||||
| 41 | 3 | ▶ | while ($i < @$ss && defined($after)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i < @$ss and defined $after
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
| |||||||||||||||||||||||||||||
| 42 | 11 | ▶ | if ($ss->[$i] eq $after) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 57 | 3 | my $i = 0; | |||||||||||||||||||||||||||
| 58 | 3 | ▶ | while ($i < @$ss) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 6 | ▶ | if ($ss->[$i] eq $name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$n //= 1
$n
Truth table0%0/2
A
A= $n
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$n //= 1
$n
Truth table0%0/2
A
A= $n
| |||||||||||||||||||||||||||||
| 76 | 0 | $self->{doc_indent_level} -= $n; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | die "BUG: Negative doc indent level" unless $self->{doc_indent_level} >=0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | for my $s (@{ $self->doc_sections // [] }) { | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->doc_sections // []
MC/DC0%0/1
$self->doc_sections // []
$self->doc_sections
Truth table0%0/2
A
A= $self->doc_sections
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||