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

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 10 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 99 SCAR 24.8
CC
3
Cov
0%
templateChapter
12.0
createManual
2.0
formatManual
2.0
CRAP 12.0
1 # Copyrights 2003-2021 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.02.
5 # This code is part of perl distribution OODoc. It is licensed under the
6 # same terms as Perl itself: https://spdx.org/licenses/Artistic-2.0.html
7  
8 package OODoc::Format::Pod2;
9 use vars '$VERSION';
10 $VERSION = '2.02';
11  
12 use base qw/OODoc::Format::Pod OODoc::Format::TemplateMagic/;
13  
14 use strict;
15 use warnings;
16  
17 use Log::Report 'oodoc';
18 use Template::Magic;
19  
20 use File::Spec;
21 use IO::Scalar;
22  
23  
24 my $default_template;
25 { local $/;
26 $default_template = <DATA>;
27 close DATA;
28 }
29  
30 sub createManual(@)
31 { my ($self, %args) = @_;
32 $self->{O_template} = delete $args{template} || \$default_template;
33 $self->SUPER::createManual(%args) or return;
34 }
35  
36 sub formatManual(@)
37 { my ($self, %args) = @_;
38 my $output = delete $args{output};
39  
40 my %permitted =
41 ( chapter => sub {$self->templateChapter(shift, \%args) }
42 , diagnostics => sub {$self->templateDiagnostics(shift, \%args) }
43 , append => sub {$self->templateAppend(shift, \%args) }
44 , comment => sub { '' }
45 );
46  
47 my $template = Template::Magic->new
48 ( { -lookups => \%permitted }
49 );
50  
51 my $layout = ${$self->{O_template}}; # Copy needed by template!
52 my $created = $template->output(\$layout);
53 $output->print($$created);
54 }
55  
56  
57 sub templateChapter($$)
58 { my ($self, $zone, $args) = @_;
59 my $contained = $zone->content;
60 defined $contained && length $contained
61 or warning __x"no meaning for container {c} in chapter block"
62 , c => $contained;
63  
64 my $attrs = $zone->attributes;
65 my $name = $attrs =~ s/^\s*(\w+)\s*\,?// ? $1 : undef;
66  
67 unless(defined $name)
68 { error __x"chapter without name in template.";
69 return '';
70 }
71  
72 my @attrs = $self->zoneGetParameters($attrs);
73 my $out = '';
74  
75 $self->showOptionalChapter($name, %$args
76 , output => IO::Scalar->new(\$out), @attrs);
77  
78 $out;
79 }
80  
81 sub templateDiagnostics($$)
82 { my ($self, $zone, $args) = @_;
83 my $out = '';
84 $self->chapterDiagnostics(%$args, output => IO::Scalar->new(\$out));
85 $out;
86 }
87  
88 sub templateAppend($$)
89 { my ($self, $zone, $args) = @_;
90 my $out = '';
91 $self->showAppend(%$args, output => IO::Scalar->new(\$out));
92 $out;
93 }
94  
95  
96 1;
97  
98 __DATA__