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

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 113 CC 2 SCAR 9.4
CC
2
Cov
0%
templateChapter
6.0
init
2.0
createManual
2.0
CRAP 2.6
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::Pod2;{
13 our $VERSION = '3.05';
14 }
15  
16 use parent 'OODoc::Format::Pod', 'OODoc::Format::TemplateMagic';
17  
18 use strict;
19 use warnings;
20  
21 use Log::Report 'oodoc';
22  
23 use Template::Magic ();
24 use File::Spec ();
25 use Encode qw/decode/;
26  
27 #--------------------
28  
29 sub init($)
30 { my ($self, $args) = @_;
31 $args->{format} //= 'pod2';
32 $self->SUPER::init($args);
33 }
34  
35 #--------------------
36  
37 my $default_template;
38 { local $/;
39 $default_template = <DATA>;
40 close DATA;
41 }
42  
43 sub createManual(@)
44 { my ($self, %args) = @_;
45 $self->{OFP_template} = delete $args{template} || \$default_template;
46 $self->SUPER::createManual(%args) or return;
47 }
48  
49 sub _formatManual(@)
50 { my ($self, %args) = @_;
51 my $output = delete $args{output};
52  
53 my %permitted =
54 ( chapter => sub {$self->templateChapter(shift, \%args) },
55 diagnostics => sub {$self->templateDiagnostics(shift, \%args) },
56 append => sub {$self->templateAppend(shift, \%args) },
57 comment => sub { '' }
58 );
59  
60 my $template = Template::Magic->new({ -lookups => \%permitted });
61 my $layout = ${$self->{OFP_template}}; # Copy needed by template!
62 my $created = $template->output(\$layout);
63 $output->print($$created);
64 }
65  
66  
67 sub templateChapter($$)
68 { my ($self, $zone, $args) = @_;
69 my $contained = $zone->content;
70 defined $contained && length $contained
71 or warning __x"no meaning for container {tags} in chapter block", tags => $contained;
72  
73 my $attrs = $zone->attributes;
74 my $name = $attrs =~ s/^\s*(\w+)\s*\,?// ? $1 : undef;
75  
76 defined $name
77 or (error __x"chapter without name in template"), return '';
78  
79 my @attrs = $self->zoneGetParameters($attrs);
80  
81 open my $output, '>:encoding(UTF-8)', \(my $out);
82 $self->showOptionalChapter($name, %$args, output => $output, @attrs);
83 decode 'UTF-8', $out;
84 }
85  
86 sub templateDiagnostics($$)
87 { my ($self, $zone, $args) = @_;
88 open my $output, '>:encoding(UTF-8)', \(my $out);
89 $self->chapterDiagnostics(%$args, output => $output);
90 decode 'UTF-8', $out;
91 }
92  
93 sub templateAppend($$)
94 { my ($self, $zone, $args) = @_;
95 open my $output, '>:encoding(UTF-8)', \(my $out);
96 $self->showAppend(%$args, output => $output);
97 decode 'UTF-8', $out;
98 }
99  
100 1;
101  
102 __DATA__