lib/OODoc/Format/Pod3.pm

filter: Statementstmt 28.3% 32 / 113 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 28.5% 8 / 28 Podpod 22.2% 2 / 9 totaltotal 20.2% 42 / 207 CC 23 SCAR 31.5
CC
23
Cov
20%
structure
72.0
chapters
42.0
subroutines
42.0
CRAP 23.4
« lib/OODoc/Text.pm ↑ Summary lib/OODoc/Text/Chapter.pm »
1 # This code is part of Perl distribution OODoc version 3.05.
2 # The POD got stripped from this file by OODoc version 3.05.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2003-2025 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package OODoc::Format::Pod3;{
13 1 our $VERSION = '3.05';
14 }
15  
16 1 ▶use parent 'OODoc::Format::Pod';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use Log::Report 'oodoc';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶use OODoc::Template ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Encode qw/decode/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 #--------------------
29  
30 sub init($)
31 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
32 0 ▶ $args->{format} //= 'pod3';
Condition0%0/2
$args->{"format"} //= "pod3"
l!l
00
MC/DC0%0/1
$args->{"format"} //= "pod3"
$args->{"format"}
Truth table0%0/2
A
A= $args->{"format"}
Aresult
11
00
33 0 $self->SUPER::init($args);
34 }
35  
36 #--------------------
37  
38 1 my $default_template;
39 1 { local $/;
40 1 $default_template = <DATA>;
41 1 close DATA;
42 }
43  
44 sub createManual(@)
45 0 ▶{ my ($self, %args) = @_;
Subroutine createManual: not called CC=2 SCAR=17.9
Pod documented
46 0 ▶ $self->{OFP_template} = delete $args{template} || \$default_template;
Condition0%0/2
delete $args{'template'} || \$default_template
l!l
00
MC/DC0%0/1
delete $args{'template'} || \$default_template
delete $args{'template'}
Truth table0%0/2
A
A= delete $args{'template'}
Aresult
11
00
47 0 $self->SUPER::createManual(%args);
48 }
49  
50 sub _formatManual(@)
51 0 ▶{ my ($self, %args) = @_;
Subroutine _formatManual: not called CC=1 SCAR=6.9
52 0 my $output = delete $args{output};
53  
54 my $template = OODoc::Template->new(
55 markers => [ '<{', '}>' ],
56 manual_obj => delete $args{manual},
57 0 chapter_order => [ qw/
58 NAME INHERITANCE SYNOPSIS DESCRIPTION OVERLOADED METHODS
59 FUNCTIONS CONSTANTS EXPORTS DIAGNOSTICS DETAILS REFERENCES
60 COPYRIGHTS
61 / ],
62 %args,
63 );
64  
65 $output->print(scalar $template->process(
66 $self->{OFP_template},
67 0 ▶ manual => sub { shift; ( {}, @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 0 ▶ chapters => sub { $self->chapters($template, @_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 ▶ sections => sub { $self->sections($template, @_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 ▶ subsections => sub { $self->subsections($template, @_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 0 ▶ subsubsections => sub { $self->subsubsections($template, @_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 ▶ subroutines => sub { $self->subroutines($template, @_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 0 ▶ diagnostics => sub { $self->diagnostics($template, @_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 0 ));
75 }
76  
77 sub structure($$$)
78 0 ▶{ my ($self, $template, $type, $object) = @_;
Subroutine structure: not called CC=8 SCAR=42.8
Pod undocumented
79  
80 0 my $manual = $template->valueFor('manual_obj');
81 0 my $descr = $self->cleanup($manual, $object->description);
82 0 my $name = $object->name;
83  
84 0 ▶ $descr =~ s/\n*$/\n\n/
Branch: 1 branch
BranchTrueFalseTotal
if defined $descr and length $descr 0 0 0
Condition0%0/3
defined $descr and length $descr
!ll&&!rl&&r
000
MC/DC0%0/2
defined $descr and length $descr
defined $descr length $descr
Truth table0%0/3
A and B
A= defined $descrB= length $descr
ABresult
0X0
100
111
85 if defined $descr && length $descr;
86  
87 0 my @examples;
88 0 foreach my $example ($object->examples)
89 0 ▶ { my $title = $example->name || 'Example';
Condition0%0/2
$example->name || 'Example'
l!l
00
MC/DC0%0/1
$example->name || 'Example'
$example->name
Truth table0%0/2
A
A= $example->name
Aresult
11
00
90 0 ▶ $title = "Example: $example" if $title !~ /example/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $title =~ /example/i 0 0 0
91 0 $title =~ s/\s+$//;
92  
93 0 push @examples, +{
94 title => $title,
95 descr => $self->cleanup($manual, $example->description)
96 };
97 }
98  
99 0 my @extends;
100 0 ▶ @extends = map +{manual => $_->manual, header => $name}, $object->extends
Branch: 1 branch
BranchTrueFalseTotal
if $name ne "NAME" and $name ne "SYNOPSIS" 0 0 0
Condition0%0/3
$name ne "NAME" and $name ne "SYNOPSIS"
!ll&&!rl&&r
000
MC/DC0%0/2
$name ne "NAME" and $name ne "SYNOPSIS"
$name ne "NAME" $name ne "SYNOPSIS"
Truth table0%0/3
A and B
A= $name ne "NAME"B= $name ne "SYNOPSIS"
ABresult
0X0
100
111
101 if $name ne 'NAME' && $name ne 'SYNOPSIS';
102  
103 0 +{ $type => $name,
104 $type.'_obj' => $object,
105 description => $descr,
106 examples => \@examples,
107 extends => \@extends,
108 };
109 }
110  
111 sub chapters($$$$$)
112 0 ▶{ my ($self, $template, $tag, $attrs, $then, $else) = @_;
Subroutine chapters: not called CC=6 SCAR=37.4
Pod undocumented
113 0 my $manual = $template->valueFor('manual_obj');
114 0 my @chapters = map $self->structure($template, chapter => $_), $manual->chapters;
115  
116 0 ▶ if(my $order = $attrs->{order})
Branch: 1 branch
BranchTrueFalseTotal
if (my $order = $attrs->{"order"}) 0 0 0
117 0 ▶ { my @order = ref $order eq 'ARRAY' ? @$order : split( /\,\s*/, $order);
Branch: 1 branch
BranchTrueFalseTotal
ref $order eq 'ARRAY' ? : 0 0 0
118 0 my %order;
119  
120 # first the pre-defined names, then the other
121 0 my $count = 1;
122 0 $order{$_} = $count++ for @order;
123 0 ▶ $order{$_->{chapter}} ||= $count++ for @chapters;
Condition0%0/3
$order{$_->{"chapter"}} ||= $count++
l!l&&r!l&&!r
000
MC/DC0%0/2
$order{$_->{"chapter"}} ||= $count++
$order{$_->{"chapter"}} $count++
Truth table0%0/3
A ||= B
A= $order{$_->{"chapter"}}B= $count++
ABresult
1X1
011
000
124  
125 0 @chapters = sort { $order{$a->{chapter}} <=> $order{$b->{chapter}} } @chapters;
126 }
127  
128 0 ( \@chapters, $attrs, $then, $else );
129 }
130  
131 sub sections($$$$$)
132 0 ▶{ my ($self, $template, $tag, $attrs, $then, $else) = @_;
Subroutine sections: not called CC=2 SCAR=17.9
Pod undocumented
133 0 my $chapter = $template->valueFor('chapter_obj');
134  
135 0 ▶ first {!$_->isEmpty} $chapter->sections
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { not $_->isEmpty; } , $chapter->sections) or return [], $attrs, $then, $else 0 0 0
136 or return ([], $attrs, $then, $else);
137  
138 0 my @sections = map $self->structure($template, section => $_), $chapter->sections;
139  
140 0 ( \@sections, $attrs, $then, $else );
141 }
142  
143 sub subsections($$$$$)
144 0 ▶{ my ($self, $template, $tag, $attrs, $then, $else) = @_;
Subroutine subsections: not called CC=2 SCAR=17.9
Pod undocumented
145 0 my $section = $template->valueFor('section_obj');
146  
147 0 ▶ first {!$_->isEmpty} $section->subsections
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { not $_->isEmpty; } , $section->subsections) or return [], $attrs, $then, $else 0 0 0
148 or return ([], $attrs, $then, $else);
149  
150 0 my @subsections = map $self->structure($template, subsection => $_), $section->subsections;
151  
152 0 ( \@subsections, $attrs, $then, $else );
153 }
154  
155 sub subsubsections($$$$$)
156 0 ▶{ my ($self, $template, $tag, $attrs, $then, $else) = @_;
Subroutine subsubsections: not called CC=2 SCAR=17.9
Pod undocumented
157 0 my $subsection = $template->valueFor('subsection_obj');
158  
159 0 ▶ first {!$_->isEmpty} $subsection->subsubsections
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { not $_->isEmpty; } , $subsection->subsubsections) or return [], $attrs, $then, $else 0 0 0
160 or return ([], $attrs, $then, $else);
161  
162 0 my @subsubsections = map $self->structure($template, subsubsection => $_), $subsection->subsubsections;
163  
164 0 ( \@subsubsections, $attrs, $then, $else );
165 }
166  
167 sub subroutines($$$$$$)
168 0 ▶{ my ($self, $template, $tag, $attrs, $then, $else) = @_;
Subroutine subroutines: not called CC=6 SCAR=37.4
Pod documented
169  
170 0 ▶ my $parent
Condition0%0/9
$template->valueFor('subsubsection_obj') || $template->valueFor('subsection_obj') || $template->valueFor('section_obj') || $template->valueFor('chapter_obj')
l!l&&r!l&&!r
000
$template->valueFor("subsubsection_obj") or $template->valueFor("subsection_obj") or $template->valueFor("section_obj")
l!l&&r!l&&!r
000
$template->valueFor("subsubsection_obj") or $template->valueFor("subsection_obj")
l!l&&r!l&&!r
000
MC/DC0%0/4
$template->valueFor('subsubsection_obj') || $template->valueFor('subsection_obj') || $template->valueFor('section_obj') || $template->valueFor('chapter_obj')
$template->valueFor("subsubsection_obj") $template->valueFor("subsection_obj") $template->valueFor("section_obj") $template->valueFor('chapter_obj')
Truth table0%0/5
A or B or C || D
A= $template->valueFor("subsubsection_obj")B= $template->valueFor("subsection_obj")C= $template->valueFor("section_obj")D= $template->valueFor('chapter_obj')
ABCDresult
1XXX1
01XX1
001X1
00011
00000
171 = $template->valueFor('subsubsection_obj')
172 || $template->valueFor('subsection_obj')
173 || $template->valueFor('section_obj')
174 || $template->valueFor('chapter_obj');
175  
176 0 ▶ defined $parent
Branch: 1 branch
BranchTrueFalseTotal
defined $parent or return () 0 0 0
177 or return ();
178  
179 0 my $out = '';
180 0 open my $fh, '>:encoding(utf8)', \$out;
181  
182 0 my @show = map +($_ => scalar $template->valueFor($_)), qw/
183 show_described_options show_described_subs show_diagnostics
184 show_examples show_inherited_options show_inherited_subs
185 show_option_table show_subs_index
186 /;
187  
188 # This is quite weak: the whole POD section for a sub description
189 # is produced outside the template. In the future, this may get
190 # changed: if there is a need for it: of course, we can do everything
191 # in the template system.
192  
193 0 $self->showSubroutines(
194 subroutines => [ $parent->subroutines ],
195 manual => $parent->manual,
196 output => $fh,
197 @show,
198 );
199  
200 0 $fh->close;
201 0 ▶ length $out or return ();
Branch: 1 branch
BranchTrueFalseTotal
length $out or return () 0 0 0
202  
203 0 $out =~ s/\n*$/\n\n/;
204 0 decode 'UTF-8', $out;
205 }
206  
207 sub diagnostics($$$$$$)
208 0 ▶{ my ($self, $template, $tag, $attrs, $then, $else) = @_;
Subroutine diagnostics: not called CC=1 SCAR=6.9
Pod undocumented
209 0 my $manual = $template->valueFor('manual_obj');
210  
211 0 my $out = '';
212 0 open my $fh, '>:encoding(utf8)', \$out;
213 0 $self->chapterDiagnostics(%$attrs, manual => $manual, output => $fh);
214 0 $fh->close;
215  
216 0 $out =~ s/\n*$/\n\n/;
217 0 decode 'UTF-8', $out;
218 }
219  
220 1 1;
221  
222 __DATA__
« lib/OODoc/Text.pm ↑ Summary lib/OODoc/Text/Chapter.pm »