To/POD.pm

filter: Statementstmt 17.3% 17 / 98 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 28.5% 4 / 14 Podpod 0.0% 0 / 7 totaltotal 11.2% 21 / 186 CC 33 SCAR 42.5
CC
33
Cov
11%
gen_doc_section_links
156.0
gen_doc_section_functions
72.0
gen_doc_section_methods
72.0
CRAP 70.0
« Sub/To/FuncBase.pm ↑ Summary To/Text.pm »
1 package Perinci::To::POD;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Locale::TextDomain::UTF8 'Perinci-To-Doc';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 extends 'Perinci::To::PackageBase';
10  
11 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
12 1 our $DATE = '2023-07-09'; # DATE
13 1 our $DIST = 'Perinci-To-Doc'; # DIST
14 1 our $VERSION = '0.881'; # VERSION
15  
16 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
17 0 my ($self, $args) = @_;
18 }
19  
20 0 ▶sub _podquote {
Subroutine _podquote: not called CC=1 SCAR=6.9
21 0 require String::PodQuote;
22 0 String::PodQuote::pod_quote($_[0]);
23 }
24  
25 0 ▶sub _md2pod {
Subroutine _md2pod: not called CC=1 SCAR=6.9
26 0 require Markdown::To::POD;
27  
28 0 my ($self, $md) = @_;
29 0 my $pod = Markdown::To::POD::markdown_to_pod($md);
30 # make sure we add a couple of blank lines in the end
31 0 $pod =~ s/\s+\z//s;
32 0 $pod . "\n\n\n";
33 }
34  
35 0 ▶sub gen_doc_section_summary {
Subroutine gen_doc_section_summary: not called CC=5 SCAR=34.0
Pod undocumented
36 0 my ($self) = @_;
37  
38 0 my $dres = $self->{_doc_res};
39  
40 0 $self->SUPER::gen_doc_section_summary;
41  
42 my $name_summary = join(
43 "",
44 $dres->{name} // "",
45 ($dres->{name} && $dres->{summary} ? ' - ' : ''),
46 0 ▶ $dres->{summary} // ""
Branch: 1 branch
BranchTrueFalseTotal
$dres->{'name'} && $dres->{'summary'} ? : 0 0 0
Condition0%0/7
$dres->{"name"} // ""
l!l
00
$dres->{"name"} and $dres->{"summary"}
!ll&&!rl&&r
000
$dres->{"summary"} // ""
l!l
00
MC/DC0%0/1
$dres->{"name"} // ""
$dres->{"name"}
MC/DC0%0/2
$dres->{"name"} and $dres->{"summary"}
$dres->{"name"} $dres->{"summary"}
MC/DC0%0/1
$dres->{"summary"} // ""
$dres->{"summary"}
Truth table0%0/2
A
A= $dres->{"name"}
Aresult
11
00
Truth table0%0/3
A and B
A= $dres->{"name"}B= $dres->{"summary"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $dres->{"summary"}
Aresult
11
00
47 );
48  
49 0 $self->add_doc_lines(
50 "=head1 " . uc(__("Name")),
51 "",
52 $self->_podquote($name_summary),
53 "",
54 );
55 }
56  
57 0 ▶sub gen_doc_section_version {
Subroutine gen_doc_section_version: not called CC=2 SCAR=17.9
Pod undocumented
58 0 my ($self) = @_;
59  
60 0 my $meta = $self->meta;
61  
62 $self->add_doc_lines(
63 "=head1 " . uc(__("Version")),
64 "",
65 0 ▶ $meta->{entity_v} // '?',
Condition0%0/2
$meta->{"entity_v"} // "?"
l!l
00
MC/DC0%0/1
$meta->{"entity_v"} // "?"
$meta->{"entity_v"}
Truth table0%0/2
A
A= $meta->{"entity_v"}
Aresult
11
00
66 "",
67 );
68 }
69  
70 0 ▶sub gen_doc_section_description {
Subroutine gen_doc_section_description: not called CC=2 SCAR=17.9
Pod undocumented
71 0 my ($self) = @_;
72  
73 0 my $dres = $self->{_doc_res};
74  
75 0 $self->add_doc_lines(
76 "=head1 " . uc(__("Description")),
77 ""
78 );
79  
80 0 $self->SUPER::gen_doc_section_description;
81  
82 0 ▶ if ($dres->{description}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dres->{"description"}) 0 0 0
83 $self->add_doc_lines(
84 0 $self->_md2pod($dres->{description}),
85 "",
86 );
87 }
88  
89 #$self->add_doc_lines(
90 # __("This module has L<Rinci> metadata") . ".",
91 # "",
92 #);
93 }
94  
95 0 ▶sub _gen_func_doc {
Subroutine _gen_func_doc: not called CC=2 SCAR=17.9
96 0 my $self = shift;
97 0 my %args = @_;
98  
99 my $o = Perinci::Sub::To::POD->new(
100 _pa => $self->{_pa},
101 export => $self->{exports} ? $self->{exports}{$args{name}} : undef,
102 0 ▶ %args,
Branch: 1 branch
BranchTrueFalseTotal
$self->{'exports'} ? : 0 0 0
103 );
104 0 $o->gen_doc;
105 0 $o->doc_lines;
106 }
107  
108 0 ▶sub gen_doc_section_functions {
Subroutine gen_doc_section_functions: not called CC=8 SCAR=42.8
Pod undocumented
109 0 require Perinci::Sub::To::POD;
110  
111 0 my ($self) = @_;
112 0 my $dres = $self->{_doc_res};
113  
114 0 $self->add_doc_lines(
115 "=head1 " . uc(__("Functions")),
116 );
117  
118 0 $self->SUPER::gen_doc_section_functions;
119  
120 # XXX categorize functions based on tags?
121 0 my $i;
122 0 for my $furi (sort keys %{ $dres->{functions} }) {
123 0 ▶ $self->add_doc_lines('') if $i++;
Branch: 1 branch
BranchTrueFalseTotal
if $i++ 0 0 0
124 0 my $meta = $dres->{function_metas}{$furi};
125 0 ▶ next if ($meta->{is_meth} || $meta->{is_class_meth}) && !($meta->{is_func} // 1);
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"is_meth"} || $meta->{"is_class_meth"} and not $meta->{"is_func"} // 1 0 0 0
Condition0%0/8
$meta->{"is_meth"} || $meta->{"is_class_meth"} and not $meta->{"is_func"} // 1
!ll&&!rl&&r
000
$meta->{"is_meth"} or $meta->{"is_class_meth"}
l!l&&r!l&&!r
000
$meta->{"is_func"} // 1
l!l
00
MC/DC0%0/3
$meta->{"is_meth"} || $meta->{"is_class_meth"} and not $meta->{"is_func"} // 1
$meta->{"is_meth"} $meta->{"is_class_meth"} $meta->{"is_func"}
Truth table0%0/5
A or B and not(C)
A= $meta->{"is_meth"}B= $meta->{"is_class_meth"}C= $meta->{"is_func"}
ABCresult
00X0
1X10
0110
1X01
0101
126 0 $self->add_doc_lines("");
127 0 for (@{ $dres->{functions}{$furi} }) {
128 0 chomp;
129 0 $self->add_doc_lines($_);
130 }
131 }
132 0 $self->add_doc_lines('');
133 }
134  
135 0 ▶sub gen_doc_section_methods {
Subroutine gen_doc_section_methods: not called CC=8 SCAR=42.8
Pod undocumented
136 0 require Perinci::Sub::To::POD;
137  
138 0 my ($self) = @_;
139 0 my $dres = $self->{_doc_res};
140  
141 0 $self->add_doc_lines(
142 "=head1 " . uc(__("Methods")),
143 );
144  
145 0 $self->SUPER::gen_doc_section_methods;
146  
147 # XXX categorize methods based on tags?
148 0 my $i;
149 0 for my $furi (sort keys %{ $dres->{functions} }) {
150 0 ▶ $self->add_doc_lines('') if $i++;
Branch: 1 branch
BranchTrueFalseTotal
if $i++ 0 0 0
151 0 my $meta = $dres->{function_metas}{$furi};
152 0 ▶ next unless ($meta->{is_meth} || $meta->{is_class_meth}) && !($meta->{is_func} // 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->{"is_meth"} || $meta->{"is_class_meth"} and not $meta->{"is_func"} // 1 0 0 0
Condition0%0/8
$meta->{"is_meth"} || $meta->{"is_class_meth"} and not $meta->{"is_func"} // 1
!ll&&!rl&&r
000
$meta->{"is_meth"} or $meta->{"is_class_meth"}
l!l&&r!l&&!r
000
$meta->{"is_func"} // 1
l!l
00
MC/DC0%0/3
$meta->{"is_meth"} || $meta->{"is_class_meth"} and not $meta->{"is_func"} // 1
$meta->{"is_meth"} $meta->{"is_class_meth"} $meta->{"is_func"}
Truth table0%0/5
A or B and not(C)
A= $meta->{"is_meth"}B= $meta->{"is_class_meth"}C= $meta->{"is_func"}
ABCresult
00X0
1X10
0110
1X01
0101
153 0 $self->add_doc_lines("");
154 0 for (@{ $dres->{functions}{$furi} }) {
155 0 chomp;
156 0 $self->add_doc_lines($_);
157 }
158 }
159 0 $self->add_doc_lines('');
160 }
161  
162 0 ▶sub gen_doc_section_links {
Subroutine gen_doc_section_links: not called CC=12 SCAR=50.5
Pod undocumented
163 0 my $self = shift;
164  
165 0 my %seen_urls;
166 0 my $meta = $self->meta;
167 0 my $child_metas = $self->child_metas;
168  
169 0 my @links;
170 0 ▶ push @links, @{ $meta->{links} } if $meta->{links};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"links"} 0 0 0
171 0 for my $m (values %$child_metas) {
172 0 ▶ for my $link (@{ $m->{links} || [] }) {
Condition0%0/2
$m->{'links'} || []
l!l
00
MC/DC0%0/1
$m->{'links'} || []
$m->{'links'}
Truth table0%0/2
A
A= $m->{'links'}
Aresult
11
00
173 # skip function that links to a prog: URL; this is probably not
174 # relevant for module doc
175 0 ▶ next if $link->{url} =~ /\Aprog:/;
Branch: 1 branch
BranchTrueFalseTotal
if $link->{"url"} =~ /\Aprog:/ 0 0 0
176  
177 0 push @links, $link;
178 }
179 }
180  
181 0 ▶ if (@links) {
Branch: 1 branch
BranchTrueFalseTotal
if (@links) 0 0 0
182 0 $self->add_doc_lines("=head1 " . __("SEE ALSO"), "");
183 0 for my $link0 (@links) {
184 0 ▶ my $link = ref($link0) ? $link0 : {url=>$link0};
Branch: 1 branch
BranchTrueFalseTotal
ref $link0 ? : 0 0 0
185 0 my $url = $link->{url};
186 0 ▶ next if $seen_urls{$url}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_urls{$url}++ 0 0 0
187 0 $url =~ s!\A(pm|pod|prog):(//?)?!!;
188 $self->add_doc_lines(
189 "L<$url>." .
190 (defined $link->{summary} ? " ".$self->_podquote($link->{summary})."." : "") .
191 0 ▶ (defined $link->{description} ? " " . $self->_md2pod($link->{description}) : ""),
Branch: 2 branches
BranchTrueFalseTotal
defined $link->{'summary'} ? : 0 0 0
defined $link->{'description'} ? : 0 0 0
192 "");
193 }
194 }
195 }
196  
197 1 1;
198 # ABSTRACT: Generate POD documentation for a package from Rinci metadata
199  
200 __END__
« Sub/To/FuncBase.pm ↑ Summary To/Text.pm »