line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SHARYANTO::Role::Doc::Section; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
11097
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
876
|
use Log::Any '$log'; |
|
1
|
|
|
|
|
2610
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
86
|
use Moo::Role; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.72'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has doc_sections => (is=>'rw'); |
10
|
|
|
|
|
|
|
has doc_lines => (is => 'rw'); # store final result, array |
11
|
|
|
|
|
|
|
has doc_indent_level => (is => 'rw'); |
12
|
|
|
|
|
|
|
has doc_indent_str => (is => 'rw', default => sub{" "}); # indent characters |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub add_doc_section_before { |
15
|
3
|
|
|
3
|
1
|
1240
|
my ($self, $name, $before) = @_; |
16
|
3
|
|
|
|
|
8
|
my $ss = $self->doc_sections; |
17
|
3
|
50
|
|
|
|
9
|
return unless $ss; |
18
|
3
|
|
|
|
|
4
|
my $i = 0; |
19
|
3
|
|
|
|
|
4
|
my $added; |
20
|
3
|
|
66
|
|
|
22
|
while ($i < @$ss && defined($before)) { |
21
|
8
|
100
|
|
|
|
17
|
if ($ss->[$i] eq $before) { |
22
|
2
|
|
|
|
|
2
|
my $pos = $i; |
23
|
2
|
|
|
|
|
6
|
splice @$ss, $pos, 0, $name; |
24
|
2
|
|
|
|
|
2
|
$added++; |
25
|
2
|
|
|
|
|
4
|
last; |
26
|
|
|
|
|
|
|
} |
27
|
6
|
|
|
|
|
21
|
$i++; |
28
|
|
|
|
|
|
|
} |
29
|
3
|
100
|
|
|
|
12
|
unshift @$ss, $name unless $added; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub add_doc_section_after { |
33
|
3
|
|
|
3
|
1
|
1613
|
my ($self, $name, $after) = @_; |
34
|
3
|
|
|
|
|
7
|
my $ss = $self->doc_sections; |
35
|
3
|
50
|
|
|
|
8
|
return unless $ss; |
36
|
3
|
|
|
|
|
4
|
my $i = 0; |
37
|
3
|
|
|
|
|
6
|
my $added; |
38
|
3
|
|
66
|
|
|
24
|
while ($i < @$ss && defined($after)) { |
39
|
11
|
100
|
|
|
|
26
|
if ($ss->[$i] eq $after) { |
40
|
2
|
|
|
|
|
2
|
my $pos = $i+1; |
41
|
2
|
|
|
|
|
6
|
splice @$ss, $pos, 0, $name; |
42
|
2
|
|
|
|
|
10
|
$added++; |
43
|
2
|
|
|
|
|
4
|
last; |
44
|
|
|
|
|
|
|
} |
45
|
9
|
|
|
|
|
32
|
$i++; |
46
|
|
|
|
|
|
|
} |
47
|
3
|
100
|
|
|
|
12
|
push @$ss, $name unless $added; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub delete_doc_section { |
51
|
3
|
|
|
3
|
1
|
1682
|
my ($self, $name) = @_; |
52
|
3
|
|
|
|
|
16
|
my $ss = $self->doc_sections; |
53
|
3
|
50
|
|
|
|
9
|
return unless $ss; |
54
|
3
|
|
|
|
|
6
|
my $i = 0; |
55
|
3
|
|
|
|
|
9
|
while ($i < @$ss) { |
56
|
6
|
100
|
|
|
|
14
|
if ($ss->[$i] eq $name) { |
57
|
2
|
|
|
|
|
8
|
splice @$ss, $i, 1; |
58
|
|
|
|
|
|
|
} else { |
59
|
4
|
|
|
|
|
10
|
$i++; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub inc_doc_indent { |
65
|
0
|
|
|
0
|
1
|
|
my ($self, $n) = @_; |
66
|
0
|
|
0
|
|
|
|
$n //= 1; |
67
|
0
|
|
|
|
|
|
$self->{doc_indent_level} += $n; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub dec_doc_indent { |
71
|
0
|
|
|
0
|
1
|
|
my ($self, $n) = @_; |
72
|
0
|
|
0
|
|
|
|
$n //= 1; |
73
|
0
|
|
|
|
|
|
$self->{doc_indent_level} -= $n; |
74
|
0
|
0
|
|
|
|
|
die "BUG: Negative doc indent level" unless $self->{doc_indent_level} >=0; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub gen_doc { |
78
|
0
|
|
|
0
|
1
|
|
my ($self, %opts) = @_; |
79
|
0
|
|
|
|
|
|
$log->tracef("-> gen_doc(opts=%s)", \%opts); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->doc_lines([]); |
82
|
0
|
|
|
|
|
|
$self->doc_indent_level(0); |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
$self->before_gen_doc(%opts) if $self->can("before_gen_doc"); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
0
|
|
|
|
for my $s (@{ $self->doc_sections // [] }) { |
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $meth = "gen_doc_section_$s"; |
88
|
0
|
|
|
|
|
|
$log->tracef("=> $meth(%s)", \%opts); |
89
|
0
|
|
|
|
|
|
$self->$meth(%opts); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
$self->after_gen_doc(%opts) if $self->can("after_gen_doc"); |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
$log->tracef("<- gen_doc()"); |
95
|
0
|
|
|
|
|
|
join("", @{ $self->doc_lines }); |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
#ABSTRACT: Role for class that generates documentation with sections |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |