blib/lib/OODoc/Format/Pod3.pm untested

filter: Statementstmt 0.0% 0 / 114 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 24 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 177 CC 8 SCAR 17.3
CC
8
Cov
0%
structure
12.0
chapters
12.0
sections
6.0
CRAP 5.7
1 # Copyrights 2003-2015 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.01.
5 use strict;
6 use warnings;
7  
8 package OODoc::Format::Pod3;
9 use vars '$VERSION';
10 $VERSION = '2.01';
11  
12 use base 'OODoc::Format::Pod';
13  
14 use Log::Report 'oodoc';
15  
16 use OODoc::Template ();
17 use List::Util qw/first/;
18  
19  
20 my $default_template;
21 { local $/;
22 $default_template = <DATA>;
23 close DATA;
24 }
25  
26 sub createManual(@)
27 { my ($self, %args) = @_;
28 $self->{O_template} = delete $args{template} || \$default_template;
29 $self->SUPER::createManual(%args);
30 }
31  
32 sub formatManual(@)
33 { my ($self, %args) = @_;
34 my $output = delete $args{output};
35  
36 my $template = OODoc::Template->new
37 ( markers => [ '<{', '}>' ]
38 , manual_obj => delete $args{manual}
39 , chapter_order =>
40 [ qw/NAME INHERITANCE SYNOPSIS DESCRIPTION OVERLOADED METHODS
41 FUNCTIONS CONSTANTS EXPORTS DIAGNOSTICS DETAILS REFERENCES
42 COPYRIGHTS/
43 ]
44 , %args
45 );
46  
47 $output->print
48 ( scalar $template->process
49 ( $self->{O_template}
50 , manual => sub { shift; ( {}, @_ ) }
51 , chapters => sub { $self->chapters($template, @_) }
52 , sections => sub { $self->sections($template, @_) }
53 , subsections => sub { $self->subsections($template, @_) }
54 , subsubsections => sub { $self->subsubsections($template, @_) }
55 , subroutines => sub { $self->subroutines($template, @_) }
56 , diagnostics => sub { $self->diagnostics($template, @_) }
57 )
58 );
59 }
60  
61  
62 sub structure($$$)
63 { my ($self, $template, $type, $object) = @_;
64  
65 my $manual = $template->valueFor('manual_obj');
66 my $descr = $self->cleanup($manual, $object->description);
67 my $name = $object->name;
68  
69 $descr =~ s/\n*$/\n\n/
70 if defined $descr && length $descr;
71  
72 my @examples = $object->examples;
73 my @extends;
74  
75 unless($name eq 'NAME' || $name eq 'SYNOPSIS')
76 { @extends = map +{manual => $_->manual, header => $name}
77 , $object->extends;
78 }
79  
80 +{ $type => $name
81 , $type.'_obj' => $object
82 , description => $descr
83 , examples => \@examples
84 , extends => \@extends
85 };
86 }
87  
88 sub chapters($$$$$)
89 { my ($self, $template, $tag, $attrs, $then, $else) = @_;
90 my $manual = $template->valueFor('manual_obj');
91  
92 my @chapters
93 = map $self->structure($template, chapter => $_)
94 , $manual->chapters;
95  
96 if(my $order = $attrs->{order})
97 { my @order = ref $order eq 'ARRAY' ? @$order : split( /\,\s*/, $order);
98 my %order;
99  
100 # first the pre-defined names, then the other
101 my $count = 1;
102 $order{$_} = $count++ for @order;
103 $order{$_->{chapter}} ||= $count++ for @chapters;
104  
105 @chapters = sort { $order{$a->{chapter}} <=> $order{$b->{chapter}} }
106 @chapters;
107 }
108  
109 ( \@chapters, $attrs, $then, $else );
110 }
111  
112 sub sections($$$$$)
113 { my ($self, $template, $tag, $attrs, $then, $else) = @_;
114 my $chapter = $template->valueFor('chapter_obj');
115  
116 return ([], $attrs, $then, $else)
117 unless first {!$_->isEmpty} $chapter->sections;
118  
119 my @sections
120 = map { $self->structure($template, section => $_) }
121 $chapter->sections;
122  
123 ( \@sections, $attrs, $then, $else );
124 }
125  
126 sub subsections($$$$$)
127 { my ($self, $template, $tag, $attrs, $then, $else) = @_;
128 my $section = $template->valueFor('section_obj');
129  
130 return ([], $attrs, $then, $else)
131 unless first {!$_->isEmpty} $section->subsections;
132  
133 my @subsections
134 = map { $self->structure($template, subsection => $_) }
135 $section->subsections;
136  
137 ( \@subsections, $attrs, $then, $else );
138 }
139  
140 sub subsubsections($$$$$)
141 { my ($self, $template, $tag, $attrs, $then, $else) = @_;
142 my $subsection = $template->valueFor('subsection_obj');
143  
144 return ([], $attrs, $then, $else)
145 unless first {!$_->isEmpty} $subsection->subsubsections;
146  
147 my @subsubsections
148 = map { $self->structure($template, subsubsection => $_) }
149 $subsection->subsubsections;
150  
151 ( \@subsubsections, $attrs, $then, $else );
152 }
153  
154 sub subroutines($$$$$$)
155 { my ($self, $template, $tag, $attrs, $then, $else) = @_;
156  
157 my $parent
158 = $template->valueFor('subsubsection_obj')
159 || $template->valueFor('subsection_obj')
160 || $template->valueFor('section_obj')
161 || $template->valueFor('chapter_obj');
162  
163 defined $parent
164 or return ();
165  
166 my $out = '';
167 open OUT, '>',\$out;
168  
169 my @show = map +($_ => scalar $template->valueFor($_)),
170 qw/show_described_options show_described_subs show_diagnostics
171 show_examples show_inherited_options show_inherited_subs
172 show_option_table show_subs_index/;
173  
174 # This is quite weak: the whole POD section for a sub description
175 # is produced outside the template. In the future, this may get
176 # changed: if there is a need for it: of course, we can do everything
177 # in the template system.
178  
179 $self->showSubroutines
180 ( subroutines => [ $parent->subroutines ]
181 , manual => $parent->manual
182 , output => \*OUT
183 , @show
184 );
185  
186 close OUT;
187 length $out or return;
188  
189 $out =~ s/\n*$/\n\n/;
190 ($out);
191 }
192  
193 sub diagnostics($$$$$$)
194 { my ($self, $template, $tag, $attrs, $then, $else) = @_;
195 my $manual = $template->valueFor('manual_obj');
196
197 my $out = '';
198 open OUT, '>',\$out;
199 $self->chapterDiagnostics(%$attrs, manual => $manual, output => \*OUT);
200 close OUT;
201  
202 $out =~ s/\n*$/\n\n/;
203 ($out);
204 }
205  
206 1;
207  
208 __DATA__