blib/lib/Pod/POM/View/Restructured.pm

filter: Statementstmt 64.6% 161 / 249 Branchbran 40.9% 36 / 88 Conditioncond 15.3% 6 / 39 MC/DCmcdc 4.1% 1 / 24 Subroutinesub 81.8% 27 / 33 Podpod 85.7% 18 / 21 totaltotal 54.8% 249 / 454 CC 61 SCAR 37.3
CC
61
Cov
54%
convert_files
182.0
_get_file_handle
56.0
view_seq_link
52.1
CRAP 41.6
↑ Summary
1 # AUTHOR: Don Owens <don@regexguy.com>
2 # AUTHOR: Jeff Fearn <Jeff.Fearn@gmail.com>
3 # AUTHOR: Alex Muntada <alexm@alexm.org>
4 # OWNER: 2010 Don Owens <don@regexguy.com>
5 # OWNER: 2016 Jeff Fearn <Jeff.Fearn@gmail.com>
6 # OWNER: 2016-2026 Alex Muntada <alexm@alexm.org>
7 # LICENSE: Perl_5
8  
9  
10 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use Pod::POM;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 package Pod::POM::View::Restructured;
17  
18 3 our $VERSION = '1.000004'; # VERSION
19  
20 3 ▶use base 'Pod::POM::View::Text';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 4 ▶sub new {
Subroutine new: called CC=5 SCAR=17.1
Pod documented
24 4 my ($class, $params) = @_;
25 4 ▶ $params = { } unless $params and UNIVERSAL::isa($params, 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $params and UNIVERSAL::isa($params, "HASH") 0 4 4
Condition33%1/3
$params and UNIVERSAL::isa($params, "HASH")
!ll&&!rl&&r
004
MC/DC0%0/2
$params and UNIVERSAL::isa($params, "HASH")
$params UNIVERSAL::isa($params, "HASH")
Truth table33%1/3
A and B
A= $paramsB= UNIVERSAL::isa($params, "HASH")
ABresult
0X0
100
111
26  
27 4 ▶ my $self = bless { seen_something => 0, title_set => 0, params => { } }, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
28  
29 4 my $callbacks = $params->{callbacks};
30 4 ▶ $callbacks = { } unless $callbacks;
Branch: 1 branch
BranchTrueFalseTotal
unless $callbacks 2 2 4
31 4 $self->{callbacks} = $callbacks;
32 4 $self->{namespace} = delete($params->{namespace});
33  
34 4 return $self;
35 }
36  
37 2 ▶sub convert_file {
Subroutine convert_file: called CC=9 SCAR=30.6
Pod documented
38 2 my ($self, $source_file, $title, $dest_file, $callbacks) = @_;
39  
40 2 my $cb;
41 2 ▶ if ($callbacks) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks) { } 0 2 2
42 0 $cb = { %{ $self->{callbacks} }, %$callbacks };
43 }
44 else {
45 2 $cb = $self->{callbacks};
46 }
47  
48 2 my $view = Pod::POM::View::Restructured->new({ callbacks => $cb, namespace => $self->{namespace} });
49 2 my $parser = Pod::POM->new;
50  
51 2 ▶ unless (-r $source_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $source_file) 0 2 2
52 0 warn "can't read source file $source_file";
53 0 return;
54 }
55  
56 2 my $pom = $parser->parse_file($source_file);
57  
58 2 ▶ $view->{title_set} = 1 if defined($title);
Branch: 1 branch
BranchTrueFalseTotal
if defined $title 0 2 2
59 2 my $out = $pom->present($view);
60  
61 2 ▶ if (defined($title)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $title) { } 0 2 2
62 0 $out = $self->_build_header($title, '#', 1) . "\n" . $out;
63 }
64 else {
65 2 $title = $view->{title};
66 }
67  
68 2 ▶ if (defined($dest_file) and $dest_file ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dest_file and $dest_file ne "") 0 2 2
Condition33%1/3
defined $dest_file and $dest_file ne ""
!ll&&!rl&&r
200
MC/DC0%0/2
defined $dest_file and $dest_file ne ""
defined $dest_file $dest_file ne ""
Truth table33%1/3
A and B
A= defined $dest_fileB= $dest_file ne ""
ABresult
0X0
100
111
69 0 my $out_fh;
70 0 ▶ if (UNIVERSAL::isa($dest_file, 'GLOB')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($dest_file, 'GLOB')) { } 0 0 0
71 0 $out_fh = $dest_file;
72 }
73 else {
74 0 ▶ unless (open($out_fh, '>', $dest_file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $out_fh, ">", $dest_file) 0 0 0
75 0 warn "couldn't open output file $dest_file";
76 0 return;
77 }
78 }
79  
80 0 print $out_fh $out;
81 0 close $out_fh;
82 }
83  
84 2 my $rv = { content => $out, title => $title };
85  
86 2 return $rv;
87 }
88  
89 0 ▶sub convert_files {
Subroutine convert_files: not called CC=13 SCAR=52.0
Pod documented
90 0 my ($self, $file_spec, $index_file, $index_title, $out_dir) = @_;
91  
92 0 my $index_fh = $self->_get_file_handle($index_file, '>');
93  
94 0 ▶ if ($index_fh and defined($index_title) and $index_title ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($index_fh and defined $index_title and $index_title ne "") 0 0 0
Condition0%0/6
$index_fh and defined $index_title and $index_title ne ""
!ll&&!rl&&r
000
$index_fh and defined $index_title
!ll&&!rl&&r
000
MC/DC0%0/3
$index_fh and defined $index_title and $index_title ne ""
$index_fh defined $index_title $index_title ne ""
Truth table0%0/4
A and B and C
A= $index_fhB= defined $index_titleC= $index_title ne ""
ABCresult
0XX0
10X0
1100
1111
95 0 my $header = $self->_build_header($index_title, '#', 1);
96 # my $line = '#' x length($index_title);
97 # my $header = $line . "\n" . $index_title . "\n" . $line . "\n\n";
98  
99 0 print $index_fh $header;
100  
101 0 print $index_fh "\nContents:\n\n";
102 0 print $index_fh ".. toctree::\n";
103 0 print $index_fh " :maxdepth: 1\n\n";
104 }
105  
106 0 my $count = 0;
107 0 my $toc = '';
108 0 foreach my $spec (@$file_spec) {
109 0 $count++;
110 my $data = $self->convert_file($spec->{source_file}, $spec->{title},
111 0 $spec->{dest_file}, $spec->{callbacks});
112  
113 0 my $this_title = $data->{title};
114 # print STDERR Data::Dumper->Dump([ $this_title ], [ 'this_title' ]) . "\n\n";
115  
116 0 ▶ unless (defined($this_title) and $this_title !~ /\A\s*\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $this_title and not $this_title =~ /\A\s*\Z/) 0 0 0
Condition0%0/3
defined $this_title and not $this_title =~ /\A\s*\Z/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this_title and not $this_title =~ /\A\s*\Z/
defined $this_title not $this_title =~ /\A\s*\Z/
Truth table0%0/3
A and not(B)
A= defined $this_titleB= not $this_title =~ /\A\s*\Z/
ABresult
0X0
100
111
117 0 $this_title = 'section_' . $count;
118 }
119  
120 0 my $name = $spec->{dest_file};
121 0 ▶ if (defined($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 0 0 0
122 0 $name =~ s/\.rst\Z//;
123 }
124 else {
125 0 ($name = $this_title) =~ s/\W/_/g;
126 0 my $dest_file = $out_dir . '/' . $name . '.rst';
127 0 my $out_fh;
128  
129 0 ▶ unless (open($out_fh, '>', $dest_file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $out_fh, ">", $dest_file) 0 0 0
130 0 warn "couldn't open output file $dest_file";
131 0 return;
132 }
133  
134 0 print $out_fh $data->{content};
135 0 close $out_fh;
136 }
137  
138 0 ▶ unless ($spec->{no_toc}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($spec->{"no_toc"}) 0 0 0
139 0 $toc .= ' ' . $name . "\n";
140 }
141  
142 0 ▶ if ($index_fh and not $spec->{no_toc}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index_fh and not $spec->{"no_toc"}) 0 0 0
Condition0%0/3
$index_fh and not $spec->{"no_toc"}
!ll&&!rl&&r
000
MC/DC0%0/2
$index_fh and not $spec->{"no_toc"}
$index_fh not $spec->{"no_toc"}
Truth table0%0/3
A and not(B)
A= $index_fhB= not $spec->{"no_toc"}
ABresult
0X0
100
111
143 0 print $index_fh " " . $name . "\n";
144 }
145 }
146  
147 0 ▶ if ($index_fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index_fh) 0 0 0
148 0 print $index_fh "\n";
149 }
150  
151 0 return { toc => $toc };
152 }
153  
154 0 ▶sub _get_file_handle {
Subroutine _get_file_handle: not called CC=7 SCAR=40.3
155 0 my ($self, $file, $mode) = @_;
156  
157 0 ▶ return unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 0 0
158  
159 0 ▶ if (ref($file) and UNIVERSAL::isa($file, 'GLOB')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file and UNIVERSAL::isa($file, "GLOB")) 0 0 0
Condition0%0/3
ref $file and UNIVERSAL::isa($file, "GLOB")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $file and UNIVERSAL::isa($file, "GLOB")
ref $file UNIVERSAL::isa($file, "GLOB")
Truth table0%0/3
A and B
A= ref $fileB= UNIVERSAL::isa($file, "GLOB")
ABresult
0X0
100
111
160 0 return $file;
161 }
162  
163 0 ▶ $mode = '<' unless $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $mode 0 0 0
164  
165 0 my $fh;
166 0 ▶ if ($file ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file ne "") 0 0 0
167 0 ▶ unless (open($fh, $mode, $file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fh, $mode, $file) 0 0 0
168 0 warn "couldn't open input file $file: $!";
169 0 return;
170 }
171 }
172  
173 0 return $fh;
174 }
175  
176 2 ▶sub view_pod {
Subroutine view_pod: called CC=1 SCAR=0.0
Pod documented
177 2 my ($self, $node) = @_;
178  
179 2 return $node->content()->present($self);
180 }
181  
182 4 ▶sub _generic_head {
Subroutine _generic_head: called CC=1 SCAR=0.0
183 4 my ($self, $node, $marker, $do_overline) = @_;
184  
185 4 return scalar($self->_generic_head_multi($node, $marker, $do_overline));
186 }
187  
188 16 ▶sub _generic_head_multi {
Subroutine _generic_head_multi: called CC=3 SCAR=11.0
189 16 my ($self, $node, $marker, $do_overline) = @_;
190  
191 16 my $title = $node->title()->present($self);
192 16 my $content = $node->content()->present($self);
193  
194 16 ▶ $title = ' ' if $title eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $title eq "" 0 16 16
195 # my $section_line = $marker x length($title);
196  
197 16 my $section = $self->_build_header($title, $marker, $do_overline) . "\n" . $content;
198  
199 # my $section = $title . "\n" . $section_line . "\n\n" . $content;
200 # if ($do_overline) {
201 # $section = $section_line . "\n" . $section;
202 # }
203  
204 16 $section .= "\n";
205  
206 16 ▶ return wantarray ? ($section, $content, $title) : $section;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 4 16
207 }
208  
209 17 ▶sub _build_header {
Subroutine _build_header: called CC=4 SCAR=13.9
210 17 my ($self, $text, $marker, $do_overline) = @_;
211  
212 17 my $line = $marker x length($text);
213 17 my $header = $text . "\n" . $line . "\n";
214  
215 17 ▶ if ($do_overline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_overline) 13 4 17
216 13 $header = $line . "\n" . $header;
217 }
218  
219 17 my $namespace = $self->{namespace};
220 17 ▶ if($namespace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($namespace) 17 0 17
221 17 my $a = $text;
222 # prepend the namesspace to guarantee document wide unique names
223 17 ▶ $a = "$namespace\:\:$a" unless($text =~ /^$namespace/);
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /^$namespace/ 16 1 17
224 17 $a =~ s/(?:\s)/-/g;
225  
226 17 $header = qq{.. _$a:\n\n} . $header;
227 }
228  
229 17 return "\n" . $header;
230 }
231  
232 19 ▶sub _do_indent {
Subroutine _do_indent: called CC=2 SCAR=6.9
233 19 my ($self, $text, $indent_amount, $dbg) = @_;
234  
235 19 my $indent = ' ' x $indent_amount;
236  
237 # $indent = "'$dbg" . $indent . "'";
238  
239 19 my @lines = split /\n/, $text, -1;
240 19 foreach my $line (@lines) {
241 68 $line = $indent . $line;
242 }
243  
244 19 return join("\n", @lines);
245 }
246  
247 12 ▶sub view_head1 {
Subroutine view_head1: called CC=5 SCAR=16.2
Pod documented
248 12 my ($self, $node) = @_;
249  
250 12 my ($section, $content, $title) = $self->_generic_head_multi($node, '*', 1);
251  
252 12 ▶ unless ($self->{seen_something} or $self->{title_set}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"seen_something"} or $self->{"title_set"}) 1 11 12
Condition66%2/3
$self->{"seen_something"} or $self->{"title_set"}
l!l&&r!l&&!r
1101
MC/DC50%1/2
$self->{"seen_something"} or $self->{"title_set"}
$self->{"seen_something"} $self->{"title_set"}
Truth table66%2/3
A or B
A= $self->{"seen_something"}B= $self->{"title_set"}
ABresult
1X1
011
000
253 1 ▶ if ($title eq 'NAME') {
Branch: 1 branch
BranchTrueFalseTotal
if ($title eq "NAME") 1 0 1
254 1 $self->{seen_something} = 1;
255  
256 1 ▶ if ($content =~ /\A\s*(\w+(?:::\w+)+)\s+-\s+/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\A\s*(\w+(?:::\w+)+)\s+-\s+/s) 1 0 1
257 1 my $mod_name = $1;
258 1 $self->{module_name} = $mod_name;
259 1 $self->{title} = $mod_name;
260 1 $self->{title_set} = 1;
261  
262 1 $section = $self->_build_header($mod_name, '#', 1) . $section;
263  
264 # my $line = '#' x length($mod_name);
265 # $section = $line . "\n" . $mod_name . "\n" . $line . "\n\n" . $section;
266 }
267  
268 1 return $section;
269 }
270 }
271  
272 11 $self->{seen_something} = 1;
273 11 return $section;
274 }
275  
276 4 ▶sub view_head2 {
Subroutine view_head2: called CC=1 SCAR=0.0
Pod documented
277 4 my ($self, $node) = @_;
278  
279 4 $self->{seen_something} = 1;
280 4 return $self->_generic_head($node, '=');
281 }
282  
283 0 ▶sub view_head3 {
Subroutine view_head3: not called CC=1 SCAR=6.9
Pod documented
284 0 my ($self, $node) = @_;
285  
286 0 $self->{seen_something} = 1;
287 0 return $self->_generic_head($node, '-');
288 }
289  
290 0 ▶sub view_head4 {
Subroutine view_head4: not called CC=1 SCAR=6.9
Pod documented
291 0 my ($self, $node) = @_;
292  
293 0 $self->{seen_something} = 1;
294 0 return $self->_generic_head($node, '^');
295 }
296  
297 16 ▶sub view_item {
Subroutine view_item: called CC=2 SCAR=6.9
Pod documented
298 16 my ($self, $node) = @_;
299  
300 16 $self->{seen_something} = 1;
301  
302 16 my $title = $node->title()->present($self);
303 16 my $content = $node->content()->present($self);
304  
305 16 $title =~ s/\A\s+//;
306 16 $title =~ s/\n/ /;
307 16 ▶ $title = "- $title"
Branch: 1 branch
BranchTrueFalseTotal
unless $title =~ / # the line starts with \A # single unordered bullet, (?:(?:[-+] | \\[*]) # or ordered bullet followed by dot, | [1AaIi] \. # or ordered bullet within parens (first optional), | \(? [1AaIi] \) # then finally followed by whitespace. )\s /msx 13 3 16
308 unless $title =~ /
309 # the line starts with
310 \A
311 # single unordered bullet,
312 (?:(?:[-+] | \\[*])
313 # or ordered bullet followed by dot,
314 | [1AaIi] \.
315 # or ordered bullet within parens (first optional),
316 | \(? [1AaIi] \)
317 # then finally followed by whitespace.
318 )\s
319 /xms;
320 # Make asterisk an actual bullet
321 16 $title =~ s/ \A \\ [*]/*/xms;
322 # $content =~ s/\n/\n /g;
323 # $content = ' ' . $content;
324  
325 16 $self->{view_item_count}++;
326 16 $content = $self->_do_indent($content, 1, "[[view_item_$self->{view_item_count}]]");
327  
328 16 return "\n" . $title . "\n" . $content . "\n\n";
329 }
330  
331 6 ▶sub view_over {
Subroutine view_over: called CC=1 SCAR=0.0
Pod documented
332 6 my ($self, $node) = @_;
333  
334 6 my $content = $node->content()->present($self);
335 # my $indent = $node->indent();
336  
337 6 return "\n" . $content;
338 }
339  
340 0 ▶sub view_text {
Subroutine view_text: not called CC=2 SCAR=17.9
Pod undocumented
341 0 my ($self, $node) = @_;
342  
343 0 my @lines = split /\n/, $node;
344 0 foreach my $line (@lines) {
345 0 $line =~ s/\A\s+//;
346 }
347  
348 0 return join("\n", @lines);
349 }
350  
351 37 ▶sub view_textblock {
Subroutine view_textblock: called CC=1 SCAR=0.0
Pod documented
352 37 my ($self, $text) = @_;
353  
354 37 return "\n" . $text . "\n";
355 }
356  
357  
358 3 ▶sub view_verbatim {
Subroutine view_verbatim: called CC=3 SCAR=11.1
Pod documented
359 3 my ($self, $node) = @_;
360  
361 # (my $node_part = ' ' . $node) =~ s/\n/\n /g;
362 3 my $node_part = $self->_do_indent($node . '', 1, '[[view_verbatim]]');
363  
364 3 my $block_part = ".. code-block:: perl\n\n";
365 3 ▶ if (defined($self->{next_code_block})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"next_code_block"}) 1 2 3
366 1 my $lang = $self->{next_code_block};
367 1 delete $self->{next_code_block};
368  
369 1 ▶ if ($lang eq 'none') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lang eq 'none') { } 0 1 1
370 # FIXME: need to output a preformatted paragraph here, but no highlighting
371 0 $block_part = '';
372 }
373 else {
374 1 $block_part = ".. code-block:: $lang\n\n";
375 }
376 }
377  
378 3 my $content = $block_part . $node_part;
379  
380 3 return "\n\n" . $content . "\n\n";
381 }
382  
383 1 ▶sub view_for {
Subroutine view_for: called CC=3 SCAR=11.7
Pod documented
384 1 my ($self, $node) = @_;
385  
386 1 my $fmt = $node->format();
387  
388 # print STDERR "got for: fmt='$fmt', text='" . $node->text() . "'\n";
389  
390 1 ▶ if ($fmt eq 'pod2rst') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt eq "pod2rst") 1 0 1
391 1 my $text = $node->text();
392 1 ▶ if ($text =~ /\A\s*next-code-block\s*:\s*(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /\A\s*next-code-block\s*:\s*(\S+)/) 1 0 1
393 1 my $lang = $1;
394 1 $self->{next_code_block} = $lang;
395 1 return '';
396 }
397  
398 0 return "\n". $node->text() . "\n\n";
399 }
400  
401 0 return $self->SUPER::view_for($node);
402 }
403  
404 29 ▶sub view_seq_code {
Subroutine view_seq_code: called CC=1 SCAR=0.0
Pod documented
405 29 my ($self, $text) = @_;
406  
407 29 return '\ ``' . $text . '``\ ';
408 }
409  
410 2 ▶sub view_seq_bold {
Subroutine view_seq_bold: called CC=1 SCAR=0.0
Pod documented
411 2 my ($self, $text) = @_;
412  
413 2 $text =~ s/\*/\\*/g;
414 2 $text =~ s/\`/\\`/g;
415  
416 2 return '\ **' . $text . '**\ ';
417 }
418  
419 3 ▶sub view_seq_italic {
Subroutine view_seq_italic: called CC=1 SCAR=0.0
Pod documented
420 3 my ($self, $text) = @_;
421  
422 3 $text =~ s/\*/\\*/g;
423 3 $text =~ s/\`/\\`/g;
424  
425 3 return '\ *' . $text . '*\ ';
426 }
427  
428 0 ▶sub view_seq_file {
Subroutine view_seq_file: not called CC=1 SCAR=6.9
Pod documented
429 0 my ($self, $text) = @_;
430  
431 0 $text =~ s/\*/\\*/g;
432 0 $text =~ s/\`/\\`/g;
433  
434 0 return '\ *' . $text . '*\ ';
435 }
436  
437 134 ▶sub view_seq_text {
Subroutine view_seq_text: called CC=1 SCAR=0.0
Pod undocumented
438 134 my ($self, $node) = @_;
439  
440 134 my $text = $node . '';
441  
442 134 $text =~ s/\*/\\*/g;
443 134 $text =~ s/\`/\\`/g;
444  
445 134 return $text;
446 }
447  
448 1 ▶sub view_seq_zero {
Subroutine view_seq_zero: called CC=1 SCAR=0.0
Pod undocumented
449 1 return '';
450 }
451  
452 10 ▶sub view_seq_link {
Subroutine view_seq_link: called CC=15 SCAR=39.5
Pod documented
453 10 my ($self, $text) = @_;
454  
455 # FIXME: determine if has label, if manpage, etc., and pass that info along to the callback,
456 # instead of just the text, e.g.,
457 # $link_cb->($label, $name, $sec, $url);
458 10 my $link_cb = $self->{callbacks}{link};
459 10 ▶ if ($link_cb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link_cb) 0 10 10
460 0 my ($url, $label) = $link_cb->($text);
461  
462 0 ▶ if (defined($url)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url) 0 0 0
463 0 ▶ if ($url eq '' and defined($label) and $label ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if ($url eq '' and defined $label and $label ne '') { } 0 0 0
elsif (defined $label and $label ne '') { } 0 0 0
Condition0%0/6
$url eq "" and defined $label and $label ne ""
!ll&&!rl&&r
000
$url eq "" and defined $label
!ll&&!rl&&r
000
MC/DC0%0/3
$url eq "" and defined $label and $label ne ""
$url eq "" defined $label $label ne ""
Truth table0%0/4
A and B and C
A= $url eq ""B= defined $labelC= $label ne ""
ABCresult
0XX0
10X0
1100
1111
464 0 $text = $label;
465 }
466 ▶ elsif (defined($label) and $label ne '') {
Condition0%0/3
defined $label and $label ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $label and $label ne ""
defined $label $label ne ""
Truth table0%0/3
A and B
A= defined $labelB= $label ne ""
ABresult
0X0
100
111
467 0 $text = qq{`$label <$url>`_};
468 }
469 else {
470 0 $text = qq{`$url <$url>`_};
471 }
472  
473 0 return $text;
474 }
475 }
476  
477 10 my $url = '';
478 10 my $label = '';
479 10 my $module = $text;
480 10 my $namespace = $self->{namespace};
481  
482 10 ▶ if ($text =~ m{\A/(.+)}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($text =~ m[\A/(.+)]) { } 2 8 10
elsif ($text =~ m[\Ahttps?://]) { } 4 4 8
elsif ($text =~ /::/) { } 3 1 4
483 2 (my $section = $1) =~ s/\A"(.+)"/$1/;
484 2 $text = qq{`$section`_};
485 }
486 elsif ($text =~ m{\Ahttps?://}) {
487 4 $text = qq{`$text <$text>`_};
488 }
489 elsif ($text =~ /::/) {
490 3 $label = $text;
491 3 ▶ if ($text =~ /\A(.+?)\|(.+::.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /\A(.+?)\|(.+::.+)/) 0 3 3
492 0 $label = $1;
493 0 $module = $2;
494 }
495  
496 # Links in this namespace are cross references
497 3 ▶ if (($namespace) and ($text =~ /^$namespace/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($namespace and $text =~ /^$namespace/) { } 0 3 3
Condition33%1/3
$namespace and $text =~ /^$namespace/
!ll&&!rl&&r
030
MC/DC0%0/2
$namespace and $text =~ /^$namespace/
$namespace $text =~ /^$namespace/
Truth table33%1/3
A and B
A= $namespaceB= $text =~ /^$namespace/
ABresult
0X0
100
111
498 0 ▶ $module = qq{$namespace\:\:$module} unless($module =~ /^$namespace/);
Branch: 1 branch
BranchTrueFalseTotal
unless $module =~ /^$namespace/ 0 0 0
499 0 $module =~ s/(?:\s)/-/g;
500 0 $text = qq{:ref:`$label <$module>`};
501 }
502 else {
503 3 $module = $self->_url_encode($module);
504 3 my $url = "https://metacpan.org/search?q=$module";
505 3 $text = qq{`$label <$url>`_};
506 }
507 }
508  
509 10 return $text;
510 }
511  
512 3 ▶sub _url_encode {
Subroutine _url_encode: called CC=1 SCAR=0.0
513 3 my ($self, $str) = @_;
514  
515 3 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
516 3 $str =~ s{([^A-Za-z0-9_])}{sprintf("%%%02x", ord($1))}eg;
517 3 return $str;
518 }
519  
520  
521  
522 3 1;
523  
524 __END__
↑ Summary