ParseLink.pm

filter: Statementstmt 100% 46 / 46 Branchbran 96.1% 25 / 26 Conditioncond 79.1% 19 / 24 MC/DCmcdc 66.6% 10 / 15 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 89.8% 106 / 118 CC 22 SCAR 20.0
CC
22
Cov
94%
parselink
9.0
_parse_section
8.0
_infer_text
7.3
CRAP 7.4
« Text/Termcap.pm ↑ Summary Text/Color.pm »
1 # Parse an L<> formatting code in POD text.
2 #
3 # This module implements parsing of the text of an L<> formatting code as
4 # defined in perlpodspec. It should be suitable for any POD formatter. It
5 # exports only one function, parselink(), which returns the five-item parse
6 # defined in perlpodspec.
7 #
8 # SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
9  
10 ##############################################################################
11 # Modules and declarations
12 ##############################################################################
13  
14 package Pod::ParseLink v6.1.1;
15  
16 1 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 our @EXPORT = qw(parselink);
22  
23 ##############################################################################
24 # Implementation
25 ##############################################################################
26  
27 # Parse the name and section portion of a link into a name and section.
28 23 ▶sub _parse_section {
Subroutine _parse_section: called CC=8 SCAR=20.8
29 23 my ($link) = @_;
30 23 $link =~ s/^\s+//;
31 23 $link =~ s/\s+$//;
32  
33 # If the whole link is enclosed in quotes, interpret it all as a section
34 # even if it contains a slash.
35 23 ▶ return (undef, $1) if ($link =~ /^"\s*(.*?)\s*"$/);
Branch: 1 branch
BranchTrueFalseTotal
if $link =~ /^"\s*(.*?)\s*"$/u 2 21 23
36  
37 # Split into page and section on slash, and then clean up quoting in the
38 # section. If there is no section and the name contains spaces, also
39 # guess that it's an old section link.
40 21 my ($page, $section) = split (/\s*\/\s*/, $link, 2);
41 21 ▶ $section =~ s/^"\s*(.*?)\s*"$/$1/ if $section;
Branch: 1 branch
BranchTrueFalseTotal
if $section 13 8 21
42 21 ▶ if ($page && $page =~ / / && !defined ($section)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page and $page =~ / /u and not defined $section) { } 1 20 21
Condition100%6/6
$page and $page =~ / /u and not defined $section
!ll&&!rl&&r
1731
$page and $page =~ / /u
!ll&&!rl&&r
3144
MC/DC100%3/3
$page and $page =~ / /u and not defined $section
$page $page =~ / /u not defined $section
Truth table100%4/4
A and B and not(C)
A= $pageB= $page =~ / /uC= not defined $section
ABCresult
0XX0
10X0
1100
1111
43 1 $section = $page;
44 1 $page = undef;
45 } else {
46 20 ▶ $page = undef unless $page;
Branch: 1 branch
BranchTrueFalseTotal
unless $page 3 17 20
47 20 ▶ $section = undef unless $section;
Branch: 1 branch
BranchTrueFalseTotal
unless $section 7 13 20
48 }
49 21 return ($page, $section);
50 }
51  
52 # Infer link text from the page and section.
53 17 ▶sub _infer_text {
Subroutine _infer_text: called CC=7 SCAR=19.9
54 17 my ($page, $section) = @_;
55 17 my $inferred;
56 17 ▶ if ($page && !$section) {
Branch: 3 branches
BranchTrueFalseTotal
if ($page and not $section) { } 3 14 17
elsif (not $page and $section) { } 6 8 14
elsif ($page and $section) { } 8 0 8
Condition100%3/3
$page and not $section
!ll&&!rl&&r
683
MC/DC100%2/2
$page and not $section
$page not $section
Truth table100%3/3
A and not(B)
A= $pageB= not $section
ABresult
0X0
100
111
57 3 $inferred = $page;
58 ▶ } elsif (!$page && $section) {
Condition66%2/3
not $page and $section
!ll&&!rl&&r
806
MC/DC50%1/2
not $page and $section
not $page $section
Truth table66%2/3
not(A) and B
A= not $pageB= $section
ABresult
0X0
100
111
59 6 $inferred = '"' . $section . '"';
60 ▶ } elsif ($page && $section) {
Condition33%1/3
$page and $section
!ll&&!rl&&r
008
MC/DC0%0/2
$page and $section
$page $section
Truth table33%1/3
A and B
A= $pageB= $section
ABresult
0X0
100
111
61 8 $inferred = '"' . $section . '" in ' . $page;
62 }
63 17 return $inferred;
64 }
65  
66 # Given the contents of an L<> formatting code, parse it into the link text,
67 # the possibly inferred link text, the name or URL, the section, and the type
68 # of link (pod, man, or url).
69 27 ▶sub parselink {
Subroutine parselink: called CC=9 SCAR=22.0
Pod undocumented
70 27 my ($link) = @_;
71 27 $link =~ s/\s+/ /g;
72 27 my $text;
73 27 ▶ if ($link =~ /\|/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link =~ /\|/u) 8 19 27
74 8 ($text, $link) = split (/\|/, $link, 2);
75 }
76 27 ▶ if ($link =~ /\A\w+:[^:\s]\S*\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link =~ /\A\w+:[^:\s]\S*\Z/u) { } 4 23 27
77 4 my $inferred;
78 4 ▶ if (defined ($text) && length ($text) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text and length $text > 0) { } 2 2 4
Condition66%2/3
defined $text and length $text > 0
!ll&&!rl&&r
202
MC/DC50%1/2
defined $text and length $text > 0
defined $text length $text > 0
Truth table66%2/3
A and B
A= defined $textB= length $text > 0
ABresult
0X0
100
111
79 2 return ($text, $text, $link, undef, 'url');
80 } else {
81 2 return ($text, $link, $link, undef, 'url');
82 }
83 } else {
84 23 my ($name, $section) = _parse_section ($link);
85 23 my $inferred;
86 23 ▶ if (defined ($text) && length ($text) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text and length $text > 0) { } 6 17 23
Condition66%2/3
defined $text and length $text > 0
!ll&&!rl&&r
1706
MC/DC50%1/2
defined $text and length $text > 0
defined $text length $text > 0
Truth table66%2/3
A and B
A= defined $textB= length $text > 0
ABresult
0X0
100
111
87 6 $inferred = $text;
88 } else {
89 17 $inferred = _infer_text ($name, $section);
90 }
91 23 ▶ my $type = ($name && $name =~ /\(\S*\)/) ? 'man' : 'pod';
Branch: 1 branch
BranchTrueFalseTotal
$name && $name =~ /\(\S*\)/u ? : 3 20 23
Condition100%3/3
$name and $name =~ /\(\S*\)/u
!ll&&!rl&&r
6143
MC/DC100%2/2
$name and $name =~ /\(\S*\)/u
$name $name =~ /\(\S*\)/u
Truth table100%3/3
A and B
A= $nameB= $name =~ /\(\S*\)/u
ABresult
0X0
100
111
92 23 return ($text, $inferred, $name, $section, $type);
93 }
94 }
95  
96 ##############################################################################
97 # Module return value and documentation
98 ##############################################################################
99  
100 # Ensure we evaluate to true.
101 1 1;
102 __END__
« Text/Termcap.pm ↑ Summary Text/Color.pm »