blib/lib/PLS/Parser/Pod/Subroutine.pm

filter: Statementstmt 21.5% 25 / 116 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 72.7% 8 / 11 Podpod 0.0% 0 / 3 totaltotal 17.3% 33 / 190 CC 32 SCAR 61.0
CC
32
Cov
15%
find
702.0
find_pod_in_definitions
56.0
new
2.0
CRAP 444.1
« blib/lib/PLS/Parser/Document.pm ↑ Summary blib/lib/PLS/Server/Response/Resolve.pm »
1 package PLS::Parser::Pod::Subroutine;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 ▶use parent 'PLS::Parser::Pod';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 ▶use Pod::Simple::Search;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Pod::Markdown;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 15 ▶use PLS::Parser::PackageSymbols;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use PLS::Parser::Pod::Builtin;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use PLS::Server::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 PLS::Parser::Pod::Subroutine
18  
19 =head1 DESCRIPTION
20  
21 This is a subclass of L<PLS::Parser::Pod>, for finding POD for a subroutine.
22 This class also might find built-in Perl functions if found and C<include_builtins>
23 is set to true.
24  
25 =cut
26  
27 sub new
28 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my ($class, @args) = @_;
30  
31 0 my %args = @args;
32 0 my $self = $class->SUPER::new(%args);
33 0 $self->{subroutine} = $args{subroutine};
34 0 $self->{packages} = $args{packages};
35 0 $self->{include_builtins} = $args{include_builtins};
36 0 $self->{uri} = $args{uri};
37  
38 0 return $self;
39 } ## end sub new
40  
41 sub find
42 0 ▶{
Subroutine find: not called CC=26 SCAR=65.5
Pod undocumented
43 0 my ($self) = @_;
44  
45 0 my $definitions;
46  
47 # If there is no package name in the subroutine call, check to see if the
48 # function is imported.
49 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
50 {
51 0 require PLS::Parser::Document;
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 ▶ if (not $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 ▶ if (not $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 0 ▶{
Subroutine find_pod_in_definitions: not called CC=7 SCAR=40.3
Pod undocumented
147 0 my ($self, $definitions) = @_;
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 15 1;
« blib/lib/PLS/Parser/Document.pm ↑ Summary blib/lib/PLS/Server/Response/Resolve.pm »