blib/lib/OODoc/Format.pm untested

filter: Statementstmt 0.0% 0 / 176 Branchbran 0.0% 0 / 84 Conditioncond 0.0% 0 / 98 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 40 Podpod 0.0% 0 / 34 totaltotal 0.0% 0 / 432 CC 43 SCAR 52.6
CC
43
Cov
0%
showSubroutine
600.0
showChapter
110.0
showSubroutines
20.0
CRAP 192.5
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  
6 package OODoc::Format;
7 use vars '$VERSION';
8 $VERSION = '2.01';
9  
10 use base 'OODoc::Object';
11  
12 use strict;
13 use warnings;
14  
15 use OODoc::Manifest;
16 use Log::Report 'oodoc';
17  
18  
19 sub init($)
20 { my ($self, $args) = @_;
21 $self->SUPER::init($args) or return;
22  
23 my $name = $self->{OF_project} = delete $args->{project}
24 or error __x"formatter knows no project name";
25  
26 $self->{OF_version} = delete $args->{version}
27 or error __x"formatter for {name} does not know the version", name => $name;
28  
29 $self->{OF_workdir} = delete $args->{workdir}
30 or error __x"no working directory specified for {name}", name => $name;
31  
32 $self->{OF_manifest} = delete $args->{manifest} || OODoc::Manifest->new;
33  
34 $self;
35 }
36  
37 #-------------------------------------------
38  
39  
40 sub project() {shift->{OF_project}}
41  
42  
43 sub version() {shift->{OF_version}}
44 sub workdir() {shift->{OF_workdir}}
45 sub manifest() {shift->{OF_manifest}}
46  
47 #-------------------------------------------
48  
49  
50 sub createManual(@) {panic}
51  
52  
53 sub cleanup($$)
54 { my ($self, $manual, $string) = @_;
55 $manual->parser->cleanup($self, $manual, $string);
56 }
57  
58  
59 sub showChapter(@)
60 { my ($self, %args) = @_;
61 my $chapter = $args{chapter} or panic;
62 my $manual = $args{manual} or panic;
63 my $show_ch = $args{show_inherited_chapter} || 'REFER';
64 my $show_sec = $args{show_inherited_section} || 'REFER';
65 my $show_ssec= $args{show_inherited_subsection} || 'REFER';
66 warn "show $chapter in $manual ($show_ch, $show_sec, ", ref($self), ")\n"
67 if ref $self =~ m/pod/i;
68  
69 if($manual->inherited($chapter))
70 { return $self if $show_ch eq 'NO';
71 $self->showStructureRefer(%args, structure => $chapter);
72 return $self;
73 }
74  
75 $self->showStructureExpand(%args, structure => $chapter);
76  
77 foreach my $section ($chapter->sections)
78 { if($manual->inherited($section))
79 { next if $show_sec eq 'NO';
80 $self->showStructureRefer(%args, structure => $section), next
81 unless $show_sec eq 'REFER';
82 }
83  
84 $self->showStructureExpand(%args, structure => $section);
85  
86 foreach my $subsection ($section->subsections)
87 { if($manual->inherited($subsection))
88 { next if $show_ssec eq 'NO';
89 $self->showStructureRefer(%args, structure=>$subsection), next
90 unless $show_ssec eq 'REFER';
91 }
92  
93 $self->showStructureExpand(%args, structure => $subsection);
94 }
95 }
96 }
97  
98 #-------------------------------------------
99  
100  
101 sub showStructureExpanded(@) {panic}
102  
103  
104 sub showStructureRefer(@) {panic}
105  
106 #-------------------------------------------
107  
108 sub chapterName(@) {shift->showRequiredChapter(NAME => @_)}
109 sub chapterSynopsis(@) {shift->showOptionalChapter(SYNOPSIS => @_)}
110 sub chapterInheritance(@) {shift->showOptionalChapter(INHERITANCE => @_)}
111 sub chapterDescription(@) {shift->showRequiredChapter(DESCRIPTION => @_)}
112 sub chapterOverloaded(@) {shift->showOptionalChapter(OVERLOADED => @_)}
113 sub chapterMethods(@) {shift->showOptionalChapter(METHODS => @_)}
114 sub chapterExports(@) {shift->showOptionalChapter(EXPORTS => @_)}
115 sub chapterDiagnostics(@) {shift->showOptionalChapter(DIAGNOSTICS => @_)}
116 sub chapterDetails(@) {shift->showOptionalChapter(DETAILS => @_)}
117 sub chapterReferences(@) {shift->showOptionalChapter(REFERENCES => @_)}
118 sub chapterCopyrights(@) {shift->showOptionalChapter(COPYRIGHTS => @_)}
119  
120 #-------------------------------------------
121  
122  
123 sub showRequiredChapter($@)
124 { my ($self, $name, %args) = @_;
125 my $manual = $args{manual} or panic;
126 my $chapter = $manual->chapter($name);
127  
128 unless(defined $chapter)
129 { alert "missing required chapter $name in $manual";
130 return;
131 }
132  
133 $self->showChapter(chapter => $chapter, %args);
134 }
135  
136  
137 sub showOptionalChapter($@)
138 { my ($self, $name, %args) = @_;
139 my $manual = $args{manual} or panic;
140  
141 my $chapter = $manual->chapter($name);
142 return unless defined $chapter;
143  
144 $self->showChapter(chapter => $chapter, %args);
145 }
146  
147  
148 sub createOtherPages(@) {shift}
149  
150  
151 sub showSubroutines(@)
152 { my ($self, %args) = @_;
153  
154 my @subs = $args{subroutines} ? sort @{$args{subroutines}} : [];
155 return unless @subs;
156  
157 my $manual = $args{manual} or panic;
158 my $output = $args{output} || select;
159  
160 # list is also in ::Pod3
161 $args{show_described_options} ||= 'EXPAND';
162 $args{show_described_subs} ||= 'EXPAND';
163 $args{show_diagnostics} ||= 'NO';
164 $args{show_examples} ||= 'EXPAND';
165 $args{show_inherited_options} ||= 'USE';
166 $args{show_inherited_subs} ||= 'USE';
167 $args{show_option_table} ||= 'ALL';
168 $args{show_subs_index} ||= 'NO';
169  
170 $self->showSubsIndex(%args, subroutines => \@subs);
171  
172 for(my $index=0; $index<@subs; $index++)
173 { my $subroutine = $subs[$index];
174 my $show = $manual->inherited($subroutine)
175 ? $args{show_inherited_subs}
176 : $args{show_described_subs};
177  
178 $self->showSubroutine
179 ( %args
180 , subroutine => $subroutine
181 , show_subroutine => $show
182 , last => ($index==$#subs)
183 );
184 }
185 }
186  
187  
188 sub showSubroutine(@)
189 { my ($self, %args) = @_;
190  
191 my $subroutine = $args{subroutine} or panic;
192 my $manual = $args{manual} or panic;
193 my $output = $args{output} || select;
194  
195 #
196 # Method use
197 #
198  
199 my $use = $args{show_subroutine} || 'EXPAND';
200 my ($show_use, $expand)
201 = $use eq 'EXPAND' ? ('showSubroutineUse', 1)
202 : $use eq 'USE' ? ('showSubroutineUse', 0)
203 : $use eq 'NAMES' ? ('showSubroutineName', 0)
204 : $use eq 'NO' ? (undef, 0)
205 : error __x"illegal value for show_subroutine: {value}", value => $use;
206  
207 $self->$show_use(%args, subroutine => $subroutine)
208 if defined $show_use;
209
210 return unless $expand;
211  
212 $args{show_inherited_options} ||= 'USE';
213 $args{show_described_options} ||= 'EXPAND';
214  
215 #
216 # Subroutine descriptions
217 #
218  
219 my $descr = $args{show_sub_description} || 'DESCRIBED';
220 my $description = $subroutine->findDescriptionObject;
221 my $show_descr = 'showSubroutineDescription';
222  
223 if(not $description || $descr eq 'NO') { $show_descr = undef }
224 elsif($descr eq 'REFER')
225 { $show_descr = 'showSubroutineDescriptionRefer'
226 if $manual->inherited($description);
227 }
228 elsif($descr eq 'DESCRIBED')
229 { $show_descr = undef if $manual->inherited($description) }
230 elsif($descr eq 'ALL') {;}
231 else { error __x"illegal value for show_sub_description: {v}", v => $descr}
232
233 $self->$show_descr(%args, subroutine => $description)
234 if defined $show_descr;
235  
236 #
237 # Options
238 #
239  
240 my $options = $subroutine->collectedOptions;
241  
242 my $opttab = $args{show_option_table} || 'NAMES';
243 my @options = @{$options}{ sort keys %$options };
244  
245 # Option table
246  
247 my @opttab
248 = $opttab eq 'NO' ? ()
249 : $opttab eq 'DESCRIBED'? (grep {not $manual->inherits($_->[0])} @options)
250 : $opttab eq 'INHERITED'? (grep {$manual->inherits($_->[0])} @options)
251 : $opttab eq 'ALL' ? @options
252 : error __x"illegal value for show_option_table: {v}", v => $opttab;
253
254 $self->showOptionTable(%args, options => \@opttab)
255 if @opttab;
256  
257 # Option expanded
258  
259 my @optlist;
260 foreach (@options)
261 { my ($option, $default) = @$_;
262 my $check
263 = $manual->inherited($option) ? $args{show_inherited_options}
264 : $args{show_described_options};
265 push @optlist, $_ if $check eq 'USE' || $check eq 'EXPAND';
266 }
267  
268 $self->showOptions(%args, options => \@optlist)
269 if @optlist;
270  
271 # Examples
272  
273 my @examples = $subroutine->examples;
274 my $show_ex = $args{show_examples} || 'EXPAND';
275 $self->showExamples(%args, examples => \@examples)
276 if $show_ex eq 'EXPAND';
277
278 # Diagnostics
279  
280 my @diags = $subroutine->diagnostics;
281 my $show_diag= $args{show_diagnostics} || 'NO';
282 $self->showDiagnostics(%args, diagnostics => \@diags)
283 if $show_diag eq 'EXPAND';
284 }
285  
286  
287 sub showExamples(@) {shift}
288  
289  
290 sub showSubroutineUse(@) {shift}
291  
292  
293 sub showSubroutineName(@) {shift}
294  
295  
296 sub showSubroutineDescription(@) {shift}
297  
298  
299 sub showOptionTable(@)
300 { my ($self, %args) = @_;
301 my $options = $args{options} or panic;
302 my $manual = $args{manual} or panic;
303 my $output = $args{output} or panic;
304  
305 my @rows;
306 foreach (@$options)
307 { my ($option, $default) = @$_;
308 my $optman = $option->manual;
309 my $link = $manual->inherited($option)
310 ? $self->link(undef, $optman)
311 : '';
312 push @rows, [ $self->cleanup($manual, $option->name)
313 , $link
314 , $self->cleanup($manual, $default->value)
315 ];
316 }
317  
318 my @header = ('Option', 'Defined in', 'Default');
319 unless(grep {length $_->[1]} @rows)
320 { # removed empty "defined in" column
321 splice @$_, 1, 1 for @rows, \@header;
322 }
323  
324 $output->print("\n");
325 $self->writeTable
326 ( output => $output
327 , header => \@header
328 , rows => \@rows
329 , widths => [undef, 15, undef]
330 );
331  
332 $self
333 }
334  
335  
336 sub showOptions(@)
337 { my ($self, %args) = @_;
338  
339 my $options = $args{options} or panic;
340 my $manual = $args{manual} or panic;
341  
342 foreach (@$options)
343 { my ($option, $default) = @$_;
344 my $show = $manual->inherited($option)
345 ? $args{show_inherited_options}
346 : $args{show_described_options};
347  
348 my $action
349 = $show eq 'USE' ? 'showOptionUse'
350 : $show eq 'EXPAND'? 'showOptionExpand'
351 : error __x"illegal show option choice: {v}", v => $show;
352
353 $self->$action(%args, option => $option, default => $default);
354 }
355 $self;
356 }
357  
358  
359 sub showOptionUse(@) {shift}
360  
361  
362 sub showOptionExpand(@) {shift}
363  
364  
365 1;
366