PLS/Parser/Pod/Subroutine.pm

filter: Statementstmt 25.4% 28 / 110 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 3 totaltotal 20.0% 37 / 185 CC 32 SCAR 60.7
CC
32
Cov
17%
find
702.0
find_pod_in_definitions
56.0
new
2.0
CRAP 433.8
« PLS/Parser/Document.pm ↑ Summary PLS/Server/Response/Resolve.pm »
1 package PLS::Parser::Pod::Subroutine;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use parent 'PLS::Parser::Pod';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use Pod::Simple::Search;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Pod::Markdown;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 ▶use PLS::Parser::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use PLS::Parser::PackageSymbols;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use PLS::Parser::Pod::Builtin;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use PLS::Server::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 NAME
17  
18 PLS::Parser::Pod::Subroutine
19  
20 =head1 DESCRIPTION
21  
22 This is a subclass of L<PLS::Parser::Pod>, for finding POD for a subroutine.
23 This class also might find built-in Perl functions if found and C<include_builtins>
24 is set to true.
25  
26 =cut
27  
28 sub new
29 {
30 0 ▶ my ($class, @args) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
31  
32 0 my %args = @args;
33 0 my $self = $class->SUPER::new(%args);
34 0 $self->{subroutine} = $args{subroutine};
35 0 $self->{packages} = $args{packages};
36 0 $self->{include_builtins} = $args{include_builtins};
37 0 $self->{uri} = $args{uri};
38  
39 0 return $self;
40 } ## end sub new
41  
42 sub find
43 {
44 0 ▶ my ($self) = @_;
Subroutine find: not called CC=26 SCAR=65.5
Pod undocumented
45  
46 0 my $definitions;
47  
48 # If there is no package name in the subroutine call, check to see if the
49 # function is imported.
50 0 ▶ if (length $self->{uri} and (ref $self->{packages} ne 'ARRAY' or not scalar @{$self->{packages}}))
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"uri"} and ref $self->{"packages"} ne "ARRAY" || !scalar(@{$self->{"packages"};})) 0 0 0
Condition0%0/6
length $self->{"uri"} and ref $self->{"packages"} ne "ARRAY" || !scalar(@{$self->{"packages"};})
!ll&&!rl&&r
000
ref $self->{"packages"} ne "ARRAY" or not scalar @{$self->{"packages"};}
l!l&&r!l&&!r
000
MC/DC0%0/3
length $self->{"uri"} and ref $self->{"packages"} ne "ARRAY" || !scalar(@{$self->{"packages"};})
length $self->{"uri"} ref $self->{"packages"} ne "ARRAY" not scalar @{$self->{"packages"};}
Truth table0%0/4
A and B or not(C)
A= length $self->{"uri"}B= ref $self->{"packages"} ne "ARRAY"C= not scalar @{$self->{"packages"};}
ABCresult
0XX0
1000
11X1
1011
51 {
52 0 my $full_text = PLS::Parser::Document->text_from_uri($self->{uri});
53 0 my $imports = PLS::Parser::Document->get_imports($full_text);
54 0 my $imported_functions = PLS::Parser::PackageSymbols::get_imported_package_symbols($PLS::Server::State::CONFIG, @{$imports})->get();
55  
56 0 PACKAGE: foreach my $package (keys %{$imported_functions})
57 {
58 0 foreach my $subroutine (@{$imported_functions->{$package}})
59 {
60 0 ▶ if ($self->{subroutine} eq $subroutine)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"subroutine"} eq $subroutine) 0 0 0
61 {
62 0 $self->{packages} = [$package];
63 0 last PACKAGE;
64 }
65 } ## end foreach my $subroutine (@{$imported_functions...})
66 } ## end foreach my $package (keys %...)
67 } ## end if (length $self->{uri...})
68  
69 0 my @markdown;
70 my @definitions;
71  
72 0 ▶ if (ref $self->{packages} eq 'ARRAY' and scalar @{$self->{packages}})
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{'packages'} eq 'ARRAY' and scalar @{$self->{'packages'};}) { } 0 0 0
elsif (ref $self->{'index'} eq 'PLS::Parser::Index') { } 0 0 0
Condition0%0/2
ref $self->{"packages"} eq "ARRAY" and scalar @{$self->{"packages"};}
!ll
00
MC/DC0%0/1
ref $self->{"packages"} eq "ARRAY" and scalar @{$self->{"packages"};}
ref $self->{"packages"} eq "ARRAY"
Truth table0%0/2
A
A= ref $self->{"packages"} eq "ARRAY"
Aresult
00
11
73 {
74 0 my $include = $self->get_clean_inc();
75 0 foreach my $package (@{$self->{packages}})
76 {
77 0 my $search = Pod::Simple::Search->new();
78 0 $search->inc(0);
79 0 my $path = $search->find($package, @{$include});
80 0 my $ok;
81  
82 0 ▶ if (length $path)
Branch: 1 branch
BranchTrueFalseTotal
if (length $path) 0 0 0
83 {
84 0 my $markdown;
85 0 ($ok, $markdown) = $self->find_pod_in_file($path, $self->{subroutine});
86 0 ▶ push @markdown, $$markdown if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
87 } ## end if (length $path)
88  
89 0 ▶ unless ($ok)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
90 {
91 0 ▶ push @definitions, @{$self->{index}->find_package_subroutine($package, $self->{subroutine})} if (ref $self->{index} eq 'PLS::Parser::Index');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"index"} eq "PLS::Parser::Index" 0 0 0
92 }
93 } ## end foreach my $package (@{$self...})
94 } ## end if (ref $self->{packages...})
95 elsif (ref $self->{index} eq 'PLS::Parser::Index')
96 {
97 0 push @definitions, @{$self->{index}->find_subroutine($self->{subroutine})};
98 }
99  
100 0 ▶ if (scalar @definitions)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @definitions) 0 0 0
101 {
102 0 my ($ok, $markdown) = $self->find_pod_in_definitions(\@definitions);
103 0 ▶ push @markdown, $$markdown if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
104 }
105  
106 0 ▶ if ($self->{include_builtins})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"include_builtins"}) 0 0 0
107 {
108 0 my $builtin = PLS::Parser::Pod::Builtin->new(function => $self->{subroutine});
109 0 my $ok = $builtin->find();
110 0 ▶ unshift @markdown, ${$builtin->{markdown}} if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
111 } ## end if ($self->{include_builtins...})
112  
113 0 ▶ if (scalar @markdown)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @markdown) 0 0 0
114 {
115 0 $self->{markdown} = \($self->combine_markdown(@markdown));
116 0 return 1;
117 }
118  
119 # if all else fails, show documentation for the entire package
120 0 ▶ if (ref $self->{packages} and scalar @{$self->{packages}})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"packages"} and scalar @{$self->{"packages"};}) 0 0 0
Condition0%0/2
ref $self->{"packages"} and scalar @{$self->{"packages"};}
!ll
00
MC/DC0%0/1
ref $self->{"packages"} and scalar @{$self->{"packages"};}
ref $self->{"packages"}
Truth table0%0/2
A
A= ref $self->{"packages"}
Aresult
00
11
121 {
122 0 foreach my $package (@{$self->{packages}})
123 {
124 0 my ($ok, $markdown) = $self->get_markdown_for_package($package);
125  
126 0 ▶ unless ($ok)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
127 {
128 0 $package = join '::', $package, $self->{subroutine};
129 0 ($ok, $markdown) = $self->get_markdown_for_package($package);
130 }
131  
132 0 ▶ push @markdown, $$markdown if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
133 } ## end foreach my $package (@{$self...})
134 } ## end if (ref $self->{packages...})
135  
136 0 ▶ if (scalar @markdown)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @markdown) 0 0 0
137 {
138 0 $self->{markdown} = \($self->combine_markdown(@markdown));
139 0 return 1;
140 }
141  
142 0 return 0;
143 } ## end sub find
144  
145 sub find_pod_in_definitions
146 {
147 0 ▶ my ($self, $definitions) = @_;
Subroutine find_pod_in_definitions: not called CC=7 SCAR=40.3
Pod undocumented
148  
149 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
150  
151 0 my $ok;
152 my @markdown_parts;
153  
154 0 foreach my $definition (@{$definitions})
155 {
156 0 my $path = URI->new($definition->{uri})->file;
157 0 my ($found, $markdown_part) = $self->find_pod_in_file($path, $self->{subroutine});
158 0 ▶ next unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 0 0
159  
160 0 ▶ if (length $$markdown_part)
Branch: 1 branch
BranchTrueFalseTotal
if (length $$markdown_part) 0 0 0
161 {
162 0 $$markdown_part = "*(From $path)*\n" . $$markdown_part;
163 0 push @markdown_parts, $$markdown_part;
164 }
165  
166 0 $ok = 1;
167 } ## end foreach my $definition (@{$definitions...})
168  
169 0 ▶ return 0 unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
170 0 my $markdown = $self->combine_markdown(@markdown_parts);
171 0 return 1, \$markdown;
172 } ## end sub find_pod_in_definitions
173  
174 11 1;
« PLS/Parser/Document.pm ↑ Summary PLS/Server/Response/Resolve.pm »