lib/OODoc/Export.pm

filter: Statementstmt 22.6% 22 / 97 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 21.4% 6 / 28 Podpod 93.3% 14 / 15 totaltotal 20.2% 42 / 207 CC 28 SCAR 35.7
CC
28
Cov
15%
tree
132.0
new
30.0
processingManual
30.0
CRAP 35.7
« lib/OODoc/Format/Pod.pm ↑ Summary lib/OODoc/Text.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::Export;{
13 1 our $VERSION = '3.05';
14 }
15  
16 1 ▶use parent 'OODoc::Object';
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  
21 1 ▶use Log::Report 'oodoc';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use HTML::Entities qw/encode_entities/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use POSIX qw/strftime/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 our %exporters = (
27 json => 'OODoc::Export::JSON',
28 );
29  
30 #--------------------
31  
32 sub new(%)
33 0 ▶{ my ($class, %args) = @_;
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
34  
35 0 ▶ $class eq __PACKAGE__
Branch: 1 branch
BranchTrueFalseTotal
$class eq __PACKAGE__ or return $class->SUPER::new(%args) 0 0 0
36 or return $class->SUPER::new(%args);
37  
38 0 ▶ my $serial = $args{serializer} or panic;
Branch: 1 branch
BranchTrueFalseTotal
my $serial = $args{"serializer"} or &panic() 0 0 0
39  
40 0 ▶ my $pkg = $exporters{$serial}
Branch: 1 branch
BranchTrueFalseTotal
my $pkg = $OODoc::Export::exporters{$serial} or &error(&__x("exporter serializer '{name}' is unknown.")) 0 0 0
41 or error __x"exporter serializer '{name}' is unknown.";
42  
43 0 eval "require $pkg";
44 0 ▶ $@ and error __x"exporter {name} has compilation errors: {err}", name => $serial, err => $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and &error(&__x("exporter {name} has compilation errors: {err}", "name", $serial, "err", $@)) 0 0 0
45  
46 0 $pkg->new(%args);
47 }
48  
49 sub init($)
50 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=4 SCAR=30.0
Pod undocumented
51 0 $self->SUPER::init($args);
52 0 ▶ $self->{OE_serial} = delete $args->{serializer} or panic;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"OE_serial"} = delete $args->{"serializer"} or &panic() 0 0 0
53 0 ▶ $self->{OE_markup} = my $markup = delete $args->{markup} or panic;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"OE_markup"} = my $markup = delete $args->{"markup"} or &panic() 0 0 0
54  
55 0 ▶ $markup eq 'html' # avoid producing errors in every method
Branch: 1 branch
BranchTrueFalseTotal
$markup eq "html" or &error(&__x("only HTML markup is currently supported, found {style UNKNOWN}.", "style", $markup)) 0 0 0
56 or error __x"only HTML markup is currently supported, found {style UNKNOWN}.", style => $markup;
57  
58 0 $self;
59 }
60  
61 #--------------------
62  
63 0 ▶sub serializer() { $_[0]->{OE_serial} }
Subroutine serializer: not called CC=1 SCAR=6.9
Pod documented
64 0 ▶sub markupStyle() { $_[0]->{OE_markup} }
Subroutine markupStyle: not called CC=1 SCAR=6.9
Pod documented
65 0 ▶sub parser() { $_[0]->{OE_parser} }
Subroutine parser: not called CC=1 SCAR=6.9
Pod documented
66 0 ▶sub format() { $_[0]->{OE_format} }
Subroutine format: not called CC=1 SCAR=6.9
Pod documented
67  
68 #--------------------
69  
70 sub tree($%)
71 0 ▶{ my ($self, $doc, %args) = @_;
Subroutine tree: not called CC=11 SCAR=48.8
Pod documented
72 0 $args{exporter} = $self;
73  
74 0 my $pubindex = +{};
75 0 $self->_publicationIndex($pubindex);
76  
77 0 my $selected_manuals = $args{manuals};
78 0 ▶ my %need_manual = map +($_ => 1), @{$selected_manuals || []};
Condition0%0/2
$selected_manuals || []
l!l
00
MC/DC0%0/1
$selected_manuals || []
$selected_manuals
Truth table0%0/2
A
A= $selected_manuals
Aresult
11
00
79 0 my @podtail_chapters = $self->podChapters($args{podtail});
80  
81 0 my %man;
82 0 my $manindex = $doc->index;
83  
84 0 foreach my $package (sort $manindex->packageNames)
85 {
86 0 foreach my $manual ($manindex->manualsForPackage($package))
87 0 ▶ { !$selected_manuals || $need_manual{$manual} or next;
Branch: 1 branch
BranchTrueFalseTotal
not $selected_manuals or $need_manual{$manual} or next 0 0 0
Condition0%0/3
not $selected_manuals or $need_manual{$manual}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $selected_manuals or $need_manual{$manual}
not $selected_manuals $need_manual{$manual}
Truth table0%0/3
not(A) or B
A= not $selected_manualsB= $need_manual{$manual}
ABresult
1X1
011
000
88 0 ▶ my $man = $manual->publish(\%args) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $man = $manual->publish(\%args) or next 0 0 0
89  
90 0 push @{$man->{chapters}}, @podtail_chapters;
91 0 $man{$manual->name} = $man->{id};
92 }
93 }
94  
95 0 ▶ my $meta = $args{meta} || {};
Condition0%0/2
$args{'meta'} || {}
l!l
00
MC/DC0%0/1
$args{'meta'} || {}
$args{'meta'}
Truth table0%0/2
A
A= $args{'meta'}
Aresult
11
00
96 0 my %meta = map +($_ => $self->markup($meta->{$_}) ), keys %$meta;
97  
98 +{
99 project => $self->markup($doc->project),
100 distribution => $doc->distribution,
101 version => $doc->version,
102 manuals => \%man,
103 meta => \%meta,
104 distributions => $args{distributions} || {},
105 0 ▶ index => $pubindex,
Condition0%0/6
$args{'distributions'} || {}
l!l
00
$main::VERSION // undef
l!l
00
$OODoc::VERSION // "devel"
l!l
00
MC/DC0%0/1
$args{'distributions'} || {}
$args{'distributions'}
MC/DC0%0/1
$main::VERSION // undef
$main::VERSION
MC/DC0%0/1
$OODoc::VERSION // "devel"
$OODoc::VERSION
Truth table0%0/2
A
A= $args{'distributions'}
Aresult
11
00
Truth table0%0/2
A
A= $main::VERSION
Aresult
11
00
Truth table0%0/2
A
A= $OODoc::VERSION
Aresult
11
00
106  
107 generated_by => +{
108 program => $0,
109 program_version => $main::VERSION // undef,
110 oodoc_version => $OODoc::VERSION // 'devel',
111 created => (strftime "%F %T", localtime),
112 },
113 };
114 }
115  
116 0 ▶sub publish { panic }
Subroutine publish: not called CC=1 SCAR=6.9
Pod documented
117  
118  
119 sub _formatterHtml($$)
120 0 ▶{ my ($self, $manual, $parser) = @_;
Subroutine _formatterHtml: not called CC=1 SCAR=6.9
121  
122 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
123 # called with $html, %settings
124 0 ▶ $parser->cleanupHtml($manual, @_, create_link => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
125 # called with ($manual, ...);
126 0 my (undef, $object, $html, $settings) = @_;
127 0 ▶ $html //= encode_entities $object->name;
Condition0%0/3
$html //= encode_entities($object->name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$html //= encode_entities($object->name)
$html encode_entities($object->name)
Truth table0%0/3
A //= B
A= $htmlB= encode_entities($object->name)
ABresult
1X1
011
000
128 0 my $unique = $object->unique;
129 0 qq{<a class="jump" href="$unique">$html</a>};
130 0 });
131 0 };
132 }
133  
134 sub _formatterPod($$)
135 0 ▶{ my ($self, $manual, $parser) = @_;
Subroutine _formatterPod: not called CC=1 SCAR=6.9
136  
137 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
138 # called with $text, %settings
139 0 ▶ $parser->cleanupPod($manual, @_, create_link => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
140 # called with ($manual, ...);
141 0 my (undef, $object, $text, $settings) = @_;
142 0 OODoc::Format::Pod->link($manual, $object, $text, $settings);
143 0 });
144 0 };
145 }
146  
147 sub processingManual($)
148 0 ▶{ my ($self, $manual) = @_;
Subroutine processingManual: not called CC=5 SCAR=34.0
Pod documented
149 0 ▶ my $parser = $self->{OE_parser} = defined $manual ? $manual->parser : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $manual ? : 0 0 0
150  
151 0 ▶ if(!defined $manual)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $manual) 0 0 0
152 0 { delete $self->{OE_parser};
153 0 ▶ $self->{OE_format} = sub { panic };
Subroutine __ANON__: not called CC=1 SCAR=6.9
154 0 return;
155 }
156  
157 0 my $style = $self->markupStyle;
158 $self->{OE_format}
159 0 ▶ = $style eq 'html' ? $self->_formatterHtml($manual, $parser)
Branch: 2 branches
BranchTrueFalseTotal
$style eq 'html' ? : 0 0 0
$style eq 'pod' ? : 0 0 0
160 : $style eq 'pod' ? $self->_formatterPod($manual, $parser)
161 : panic $style;
162  
163 0 $self;
164 }
165  
166  
167 sub markup($)
168 0 ▶{ my ($self, $string) = @_;
Subroutine markup: not called CC=3 SCAR=24.8
Pod documented
169 0 ▶ defined $string && $self->markupStyle eq 'html' ? encode_entities $string : $string;
Branch: 1 branch
BranchTrueFalseTotal
defined $string && $self->markupStyle eq 'html' ? : 0 0 0
Condition0%0/3
defined $string and $self->markupStyle eq "html"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $string and $self->markupStyle eq "html"
defined $string $self->markupStyle eq "html"
Truth table0%0/3
A and B
A= defined $stringB= $self->markupStyle eq "html"
ABresult
0X0
100
111
170 }
171  
172  
173 0 ▶sub boolean($) { !! $_[1] }
Subroutine boolean: not called CC=1 SCAR=6.9
Pod documented
174  
175  
176 sub markupBlock($%)
177 0 ▶{ my ($self, $text, %args) = @_;
Subroutine markupBlock: not called CC=1 SCAR=6.9
Pod documented
178 0 $self->format->($text, %args);
179 }
180  
181  
182 sub markupString($%)
183 0 ▶{ my ($self, $string, %args) = @_;
Subroutine markupString: not called CC=2 SCAR=17.9
Pod documented
184 0 my $up = $self->format->($string, %args);
185 0 ▶ $self->markupStyle eq 'html' or return $up;
Branch: 1 branch
BranchTrueFalseTotal
$self->markupStyle eq "html" or return $up 0 0 0
186  
187 0 $up =~ s!</p>\s*<p>!<br>!grs # keep line-breaks
188 =~ s!<p\b.*?>!!gr # remove paragraphing
189 =~ s!\</p\>!!gr;
190 }
191  
192  
193 sub podChapters($)
194 0 ▶{ my ($self, $pod) = @_;
Subroutine podChapters: not called CC=3 SCAR=24.8
Pod documented
195 0 ▶ defined $pod && length $pod or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $pod and length $pod or return () 0 0 0
Condition0%0/3
defined $pod and length $pod
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pod and length $pod
defined $pod length $pod
Truth table0%0/3
A and B
A= defined $podB= length $pod
ABresult
0X0
100
111
196  
197 0 my $parser = OODoc::Parser::Markov->new; # supports plain POD
198 ...
199 0 }
200  
201  
202 sub referTo($$)
203 0 ▶{ my ($self, $manual, $object) = @_;
Subroutine referTo: not called CC=1 SCAR=6.9
Pod documented
204 0 $self->parser->formatReferTo($manual, $object);
205 }
206  
207 #--------------------
208  
209 1 1;
« lib/OODoc/Format/Pod.pm ↑ Summary lib/OODoc/Text.pm »