PLS/Parser/Pod/Subroutine.pm

filter: Statementstmt 21.1% 22 / 104 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 58.3% 7 / 12 Podpod 20.0% 1 / 5 totaltotal 15.6% 30 / 192 CC 32 SCAR 48.0
CC
32
Cov
13%
find
210.0
find_pod_in_file
156.0
find_pod_in_definitions
56.0
CRAP 121.5
« PLS/Parser/DocumentSymbols.pm ↑ Summary PLS/Parser/Element.pm »
1 package PLS::Parser::Pod::Subroutine;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use parent 'PLS::Parser::Pod';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Pod::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Pod::Markdown;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use PLS::Parser::Pod::Builtin;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use PLS::Server::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 PLS::Parser::Pod::Subroutine
17  
18 =head1 DESCRIPTION
19  
20 This is a subclass of L<PLS::Parser::Pod>, for finding POD for a subroutine.
21 This class also might find built-in Perl functions if found and C<include_builtins>
22 is set to true.
23  
24 =cut
25  
26 sub new
27 {
28 0 ▶ my ($class, @args) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
29  
30 0 my %args = @args;
31 0 my $self = $class->SUPER::new(%args);
32 0 $self->{subroutine} = $args{subroutine};
33 0 $self->{package} = $args{package};
34 0 $self->{include_builtins} = $args{include_builtins};
35  
36 0 return $self;
37 } ## end sub new
38  
39 sub name
40 {
41 0 ▶ my ($self) = @_;
Subroutine name: not called CC=2 SCAR=17.9
Pod documented
42  
43 0 my $name = '';
44 0 ▶ $name = $self->{package} . '::' if (length $self->{package});
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"package"} 0 0 0
45 0 return $name . $self->{subroutine};
46 } ## end sub name
47  
48 sub find
49 {
50 0 ▶ my ($self) = @_;
Subroutine find: not called CC=14 SCAR=53.5
Pod undocumented
51  
52 0 my $definitions;
53  
54 0 ▶ if (length $self->{package})
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"package"}) 0 0 0
55 {
56 0 my $include = $self->get_clean_inc();
57 0 my $path = Pod::Find::pod_where({-dirs => $include}, $self->{package});
58  
59 0 ▶ if (length $path)
Branch: 1 branch
BranchTrueFalseTotal
if (length $path) 0 0 0
60 {
61 0 my ($ok, $markdown) = $self->find_pod_in_file($path);
62 0 ▶ if ($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 0 0 0
63 {
64 0 $self->{markdown} = $markdown;
65 0 return 1;
66 }
67 } ## end if (length $path)
68  
69 0 $definitions = $self->{index}->find_package_subroutine($self->{package}, $self->{subroutine});
70 } ## end if (length $self->{package...})
71  
72 0 ▶ unless (ref $definitions eq 'ARRAY' and scalar @$definitions)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $definitions eq "ARRAY" and scalar @$definitions) 0 0 0
Condition0%0/2
ref $definitions eq "ARRAY" and scalar @$definitions
!ll
00
MC/DC0%0/1
ref $definitions eq "ARRAY" and scalar @$definitions
ref $definitions eq "ARRAY"
Truth table0%0/2
A
A= ref $definitions eq "ARRAY"
Aresult
00
11
73 {
74 0 $definitions = $self->{index}->find_subroutine($self->{subroutine});
75 }
76  
77 0 my @markdown;
78  
79 0 my ($ok, $markdown) = $self->find_pod_in_definitions($definitions);
80 0 ▶ push @markdown, $$markdown if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
81  
82 0 ▶ if ($self->{include_builtins})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"include_builtins"}) 0 0 0
83 {
84 0 my $builtin = PLS::Parser::Pod::Builtin->new(function => $self->{subroutine});
85 0 $ok = $builtin->find();
86 0 ▶ unshift @markdown, ${$builtin->{markdown}} if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
87 }
88  
89 0 ▶ if (scalar @markdown)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @markdown) 0 0 0
90 {
91 0 $self->{markdown} = \($self->combine_markdown(@markdown));
92 0 return 1;
93 }
94  
95 # if all else fails, show documentation for the entire package
96 0 ▶ if (length $self->{package})
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"package"}) 0 0 0
97 {
98 0 ▶ ($ok, $markdown) = $self->get_markdown_for_package($self->{package}) if (length $self->{package});
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"package"} 0 0 0
99  
100 0 ▶ unless ($ok)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
101 {
102 0 my $package = join '::', $self->{package}, $self->{subroutine};
103 0 ($ok, $markdown) = $self->get_markdown_for_package($package);
104 }
105 } ## end if (length $self->{package...})
106  
107 0 ▶ $self->{markdown} = $markdown if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
108 0 return $ok;
109 } ## end sub find
110  
111 sub find_pod_in_definitions
112 {
113 0 ▶ my ($self, $definitions) = @_;
Subroutine find_pod_in_definitions: not called CC=7 SCAR=40.3
Pod undocumented
114  
115 0 ▶ return 0 unless (ref $definitions eq 'ARRAY' and scalar @$definitions);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $definitions eq "ARRAY" and scalar @$definitions 0 0 0
Condition0%0/2
ref $definitions eq "ARRAY" and scalar @$definitions
!ll
00
MC/DC0%0/1
ref $definitions eq "ARRAY" and scalar @$definitions
ref $definitions eq "ARRAY"
Truth table0%0/2
A
A= ref $definitions eq "ARRAY"
Aresult
00
11
116  
117 0 my $ok;
118 my @markdown_parts;
119  
120 0 foreach my $definition (@$definitions)
121 {
122 0 my $path = URI->new($definition->{uri})->file;
123 0 my ($found, $markdown_part) = $self->find_pod_in_file($path);
124 0 ▶ next unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 0 0
125  
126 0 ▶ if (length $$markdown_part)
Branch: 1 branch
BranchTrueFalseTotal
if (length $$markdown_part) 0 0 0
127 {
128 0 $$markdown_part = "*(From $path)*\n" . $$markdown_part;
129 0 push @markdown_parts, $$markdown_part;
130 }
131  
132 0 $ok = 1;
133 } ## end foreach my $definition (@$definitions...)
134  
135 0 ▶ return 0 unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
136 0 my $markdown = $self->combine_markdown(@markdown_parts);
137 0 return 1, \$markdown;
138 } ## end sub find_pod_in_definitions
139  
140 sub find_pod_in_file
141 {
142 0 ▶ my ($self, $path) = @_;
Subroutine find_pod_in_file: not called CC=12 SCAR=50.5
Pod undocumented
143  
144 0 ▶ open my $fh, '<', $path or return 0;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $path or return 0 0 0 0
145  
146 0 my @lines;
147 0 my $start = '';
148  
149 0 ▶ while (my $line = <$fh>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
150 {
151 0 ▶ if ($line =~ /^=(head\d|item).*\b$self->{subroutine}\b.*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^=(head\d|item).*\b$self->{"subroutine"}\b.*$/) 0 0 0
152 {
153 0 $start = $1;
154 0 push @lines, $line;
155 0 next;
156 } ## end if ($line =~ /^=(head\d|item).*\b$self->{subroutine}\b.*$/...)
157  
158 0 ▶ if (length $start)
Branch: 1 branch
BranchTrueFalseTotal
if (length $start) 0 0 0
159 {
160 0 push @lines, $line;
161  
162 0 ▶ if ( $start eq 'item' and $line =~ /^=item/
Branch: 1 branch
BranchTrueFalseTotal
if ($start eq "item" and $line =~ /^=item/ or $start =~ /head/ and $line =~ /^=$start/ or $line =~ /^=cut/) 0 0 0
Condition0%0/12
$start eq "item" and $line =~ /^=item/ or $start =~ /head/ and $line =~ /^=$start/ or $line =~ /^=cut/
l!l&&r!l&&!r
000
$start eq "item" and $line =~ /^=item/ or $start =~ /head/ and $line =~ /^=$start/
l!l&&r!l&&!r
000
$start eq "item" and $line =~ /^=item/
!ll&&!rl&&r
000
$start =~ /head/ and $line =~ /^=$start/
!ll&&!rl&&r
000
MC/DC0%0/5
$start eq "item" and $line =~ /^=item/ or $start =~ /head/ and $line =~ /^=$start/ or $line =~ /^=cut/
$start eq "item" $line =~ /^=item/ $start =~ /head/ $line =~ /^=$start/ $line =~ /^=cut/
Truth table0%0/11
A and B or C and D or E
A= $start eq "item"B= $line =~ /^=item/C= $start =~ /head/D= $line =~ /^=$start/E= $line =~ /^=cut/
ABCDEresult
11XXX1
0X11X1
1011X1
0X0X11
0X1011
100X11
101011
0X0X00
0X1000
100X00
101000
163 or $start =~ /head/ and $line =~ /^=$start/
164 or $line =~ /^=cut/)
165 {
166 0 last;
167 } ## end if ($start eq 'item' and...)
168 } ## end if (length $start)
169 } ## end while (my $line = <$fh>)
170  
171 0 close $fh;
172  
173 # we don't want the last line - it's a start of a new section.
174 0 pop @lines;
175  
176 0 my $markdown = '';
177  
178 0 ▶ if (scalar @lines)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @lines) 0 0 0
179 {
180 0 my $parser = Pod::Markdown->new();
181  
182 0 $parser->output_string(\$markdown);
183 0 $parser->no_whining(1);
184 0 $parser->parse_lines(@lines, undef);
185  
186 # remove first extra space to avoid markdown from being displayed inappropriately as code
187 0 $markdown =~ s/\n\n/\n/;
188 0 my $ok = $parser->content_seen;
189 0 ▶ return 0 unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
190 0 return $ok, \$markdown;
191 } ## end if (scalar @lines)
192  
193 0 return 0;
194 } ## end sub find_pod_in_file
195  
196 1 1;
« PLS/Parser/DocumentSymbols.pm ↑ Summary PLS/Parser/Element.pm »