| 1 | package PLS::Server::Response::Completion; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use parent q(PLS::Server::Response); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use feature 'state'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use Pod::Functions; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use List::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use Module::CoreList; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use Module::Metadata; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use ExtUtils::Installed; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use PLS::Parser::Document; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use PLS::Parser::PackageSymbols; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use PLS::Parser::Pod; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | ▶ | use PLS::Server::State; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | PLS::Server::Response::Completion | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | This is a message from the server to the client with a list | ||||||||||||||||||||||||||||||||||||||||||
| 27 | of completion items for the current location. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my ($class, $request) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $self = bless {id => $request->{id}, result => undef}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $document = PLS::Parser::Document->new(uri => $request->{params}{textDocument}{uri}, line => $request->{params}{position}{line}); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return $self if (ref $document ne 'PLS::Parser::Document'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($range, $arrow, $package, $filter) = $document->find_word_under_cursor(@{$request->{params}{position}}{qw(line character)}); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return $self if (ref $range ne 'HASH'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $range->{start}{line} = $request->{params}{position}{line}; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $range->{end}{line} = $request->{params}{position}{line}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $range->{end}{character} = $request->{params}{position}{character}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $package =~ s/::$// if (length $package); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my @results; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $full_text = $document->get_full_text(); | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my @futures; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ($filter =~ /^[\$\@\%]/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | push @results, @{get_variables($document, $filter, $full_text)}; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | else | ||||||||||||||||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my @packages = @{get_packages($document, $full_text)}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | unless ($arrow) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | push @results, @packages; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | push @results, @{get_keywords()}; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($package) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | push @futures, get_package_functions($package, $filter, $arrow); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($filter) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | push @results, @{get_constants($document, $filter, $full_text)}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | push @futures, get_imported_package_functions($document, $full_text); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | push @results, @{get_subroutines($document, $arrow, $full_text, $packages[0]{label})}; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } ## end if ($filter) | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } ## end else [ if ($filter =~ /^[\$\@\%]/...)] | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | push @results, @{Future->wait_all(@futures)->then( | |||||||||||||||||||||||||||||||||||||||||
| 83 | sub { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | [map { @{$_->result} } grep { $_->is_ready } @_] | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | )->get() | |||||||||||||||||||||||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my %unique_by_detail; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | foreach my $result (@results) | |||||||||||||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $new_text = $result->{label}; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | $new_text = $result->{insertText} if (length $result->{insertText}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | delete $result->{insertText}; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | next if (exists $result->{detail} and length $result->{detail} and $unique_by_detail{$result->{detail}}++); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
exists $result->{"detail"} and length $result->{"detail"} and $unique_by_detail{$result->{"detail"}}++
exists $result->{"detail"} and length $result->{"detail"}
MC/DC0%0/3
exists $result->{"detail"} and length $result->{"detail"} and $unique_by_detail{$result->{"detail"}}++
exists $result->{"detail"}
length $result->{"detail"}
$unique_by_detail{$result->{"detail"}}++
Truth table0%0/4
A and B and C
A= exists $result->{"detail"}B= length $result->{"detail"}C= $unique_by_detail{$result->{"detail"}}++
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | push @{$self->{result}}, {%$result, textEdit => {newText => $new_text, range => $range}}; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } ## end foreach my $result (@results...) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (not $arrow and not $package and $filter !~ /^\%\@/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$arrow or $package or $filter =~ /^\%\@/
$arrow or $package
MC/DC0%0/3
$arrow or $package or $filter =~ /^\%\@/
$arrow
$package
$filter =~ /^\%\@/
Truth table0%0/4
A or B or C
A= $arrowB= $packageC= $filter =~ /^\%\@/
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | push @{$self->{result}}, get_snippets(); | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } ## end sub new | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | sub get_keywords | ||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | state @keywords; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_keywords: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return \@keywords if (scalar @keywords); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my %seen_keywords; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | foreach my $family (keys %Pod::Functions::Kinds) | |||||||||||||||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | foreach my $sub (@{$Pod::Functions::Kinds{$family}}) | |||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | next if $sub =~ /\s+/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | next if $seen_keywords{$sub}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | push @keywords, {label => $sub, kind => 14}; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } ## end foreach my $sub (@{$Pod::Functions::Kinds...}) | ||||||||||||||||||||||||||||||||||||||||||
| 125 | } ## end foreach my $family (keys %Pod::Functions::Kinds...) | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | foreach my $keyword ( | |||||||||||||||||||||||||||||||||||||||||
| 128 | qw(cmp continue default do else elsif eq for foreach ge given gt if le lock lt ne not or package sub unless until when while x xor -r -w -x -o -R -W -X -O -e -z -s -f -d -l -p -S -b -c -t -u -g -k -T -B -M -A -C) | ||||||||||||||||||||||||||||||||||||||||||
| 129 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | next if $seen_keywords{$keyword}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | push @keywords, {label => $keyword, kind => 14}; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } ## end foreach my $keyword (...) | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | return \@keywords; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } ## end sub get_keywords | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | sub get_ext_modules | ||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # Can use state here, external modules unlikely to change. | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | state @ext_modules; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_ext_modules: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return \@ext_modules if (scalar @ext_modules); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $include = PLS::Parser::Pod->get_clean_inc(); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $installed = ExtUtils::Installed->new(inc_override => $include); | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | foreach my $module ($installed->modules) | |||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my @files = $installed->files($module, 'prog'); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $module =~ s/::/\//g; | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # Find all the packages that are part of this module | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | foreach my $file (@files) | |||||||||||||||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my ($path) = $file =~ /(\Q$module\E(?:\/.+)?)\.pm$/; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | next unless (length $path); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $mod_package = $path =~ s/\//::/gr; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | push @ext_modules, $mod_package; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } ## end foreach my $file (@files) | ||||||||||||||||||||||||||||||||||||||||||
| 161 | } ## end foreach my $module ($installed...) | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | return \@ext_modules; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } ## end sub get_ext_modules | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | sub get_package_functions | ||||||||||||||||||||||||||||||||||||||||||
| 167 | { | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | my ($package, $filter, $arrow) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_package_functions: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | return Future->done([]) unless (length $package); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | return PLS::Parser::PackageSymbols::get_package_symbols($PLS::Server::State::CONFIG, $package)->then( | ||||||||||||||||||||||||||||||||||||||||||
| 173 | sub { | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | my ($functions) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | return Future->done([]) if (ref $functions ne 'HASH'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $separator = $arrow ? '->' : '::'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my @functions; | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | foreach my $package_name (keys %{$functions}) | |||||||||||||||||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | foreach my $name (@{$functions->{$package_name}}) | |||||||||||||||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $fully_qualified = join $separator, $package_name, $name; | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $result = { | |||||||||||||||||||||||||||||||||||||||||
| 188 | label => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 189 | sortText => $fully_qualified, | ||||||||||||||||||||||||||||||||||||||||||
| 190 | kind => 3 | ||||||||||||||||||||||||||||||||||||||||||
| 191 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ($arrow) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $result->{insertText} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | else | ||||||||||||||||||||||||||||||||||||||||||
| 198 | { | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $result->{insertText} = $fully_qualified; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ($arrow) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if (length $filter) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $result->{filterText} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | else | ||||||||||||||||||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $result->{filterText} = $fully_qualified; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | } ## end if ($arrow) | ||||||||||||||||||||||||||||||||||||||||||
| 213 | else | ||||||||||||||||||||||||||||||||||||||||||
| 214 | { | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $result->{filterText} = $fully_qualified; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | push @functions, $result; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } ## end foreach my $name (@{$functions...}) | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } ## end foreach my $package_name (keys...) | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | return Future->done(\@functions); | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 225 | } ## end sub get_package_functions | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | sub get_imported_package_functions | ||||||||||||||||||||||||||||||||||||||||||
| 228 | { | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | my ($document, $full_text) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_imported_package_functions: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $imports = $document->get_imports($full_text); | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | return Future->done([]) if (ref $imports ne 'ARRAY' or not scalar @{$imports}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $imports ne "ARRAY" or not scalar @{$imports;}
MC/DC0%0/2
ref $imports ne "ARRAY" or not scalar @{$imports;}
ref $imports ne "ARRAY"
not scalar @{$imports;}
Truth table0%0/3
A or not(B)
A= ref $imports ne "ARRAY"B= not scalar @{$imports;}
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return PLS::Parser::PackageSymbols::get_imported_package_symbols($PLS::Server::State::CONFIG, @{$imports})->then( | |||||||||||||||||||||||||||||||||||||||||
| 235 | sub { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | my ($imported_functions) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my @results; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | foreach my $package_name (keys %{$imported_functions}) | |||||||||||||||||||||||||||||||||||||||||
| 240 | { | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | foreach my $subroutine (@{$imported_functions->{$package_name}}) | |||||||||||||||||||||||||||||||||||||||||
| 242 | { | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my $result = { | |||||||||||||||||||||||||||||||||||||||||
| 244 | kind => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 245 | label => $subroutine, | ||||||||||||||||||||||||||||||||||||||||||
| 246 | data => [$package_name], | ||||||||||||||||||||||||||||||||||||||||||
| 247 | detail => "${package_name}::${subroutine}", | ||||||||||||||||||||||||||||||||||||||||||
| 248 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | $result->{labelDetails} = {description => "${package_name}::${subroutine}"} | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if $PLS::Server::State::CLIENT_CAPABILITIES->{textDocument}{completion}{completionItem}{labelDetailsSupport}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | push @results, $result; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } ## end foreach my $subroutine (@{$imported_functions...}) | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } ## end foreach my $package_name (keys...) | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | return Future->done(\@results); | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 258 | } ## end sub get_imported_package_functions | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | sub get_subroutines | ||||||||||||||||||||||||||||||||||||||||||
| 261 | { | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | my ($document, $arrow, $full_text, $this_document_package) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_subroutines: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my %subroutines; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | foreach my $sub (@{$document->get_subroutines_fast($full_text)}) | |||||||||||||||||||||||||||||||||||||||||
| 267 | { | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | next if ($sub =~ /\n/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | $subroutines{$sub} = {label => $sub, kind => 3}; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | $subroutines{$sub}{data} = ["${this_document_package}::${sub}"] if (length $this_document_package); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | } ## end foreach my $sub (@{$document...}) | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | # Add subroutines to the list, uniquifying and keeping track of the packages in which | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # it is defined so that resolve can find the documentation. | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | foreach my $sub (keys %{$document->{index}->subs}) | |||||||||||||||||||||||||||||||||||||||||
| 276 | { | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | foreach my $data (@{$document->{index}->subs->{$sub}}) | |||||||||||||||||||||||||||||||||||||||||
| 278 | { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | my $result = $subroutines{$sub} // {label => $sub, kind => $data->{kind}, data => []}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$subroutines{$sub} // {"label", $sub, "kind", $data->{"kind"}, "data", []}
MC/DC0%0/1
$subroutines{$sub} // {"label", $sub, "kind", $data->{"kind"}, "data", []}
$subroutines{$sub}
Truth table0%0/2
A
A= $subroutines{$sub}
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if (length $data->{package}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | push @{$result->{data}}, $data->{package}; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | $subroutines{$sub} = $result; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } ## end foreach my $data (@{$document...}) | ||||||||||||||||||||||||||||||||||||||||||
| 288 | } ## end foreach my $sub (keys %{$document...}) | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | # If the subroutine is only defined in one place, include the package name as the detail. | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | foreach my $sub (keys %subroutines) | |||||||||||||||||||||||||||||||||||||||||
| 292 | { | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if (exists $subroutines{$sub}{data} and ref $subroutines{$sub}{data} eq 'ARRAY' and scalar @{$subroutines{$sub}{data}} == 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
exists $subroutines{$sub}{"data"} and ref $subroutines{$sub}{"data"} eq "ARRAY" and scalar @{$subroutines{$sub}{"data"};} == 1
exists $subroutines{$sub}{"data"} and ref $subroutines{$sub}{"data"} eq "ARRAY"
MC/DC0%0/3
exists $subroutines{$sub}{"data"} and ref $subroutines{$sub}{"data"} eq "ARRAY" and scalar @{$subroutines{$sub}{"data"};} == 1
exists $subroutines{$sub}{"data"}
ref $subroutines{$sub}{"data"} eq "ARRAY"
scalar @{$subroutines{$sub}{"data"};} == 1
Truth table0%0/4
A and B and C
A= exists $subroutines{$sub}{"data"}B= ref $subroutines{$sub}{"data"} eq "ARRAY"C= scalar @{$subroutines{$sub}{"data"};} == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | { | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $subroutines{$sub}{detail} = $subroutines{$sub}{data}[0] . "::${sub}"; | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | } ## end foreach my $sub (keys %subroutines...) | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return [values %subroutines]; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } ## end sub get_subroutines | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | sub get_packages | ||||||||||||||||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | my ($document, $full_text) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_packages: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my @packages; | |||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | # Can use state here, core modules unlikely to change. | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | state $core_modules = [Module::CoreList->find_modules(qr//, $])]; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $ext_modules = get_ext_modules(); | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | push @packages, @{$document->get_packages_fast($full_text)}; | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | foreach my $pack (@{$core_modules}, @{$ext_modules}) | |||||||||||||||||||||||||||||||||||||||||
| 315 | { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | next if ($pack =~ /\n/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | push @packages, $pack; | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | if (ref $document->{index} eq 'PLS::Parser::Index') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | { | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | push @packages, @{$document->{index}->get_all_packages()}; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return [map { {label => $_, kind => 7} } List::Util::uniq sort @packages]; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } ## end sub get_packages | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | sub get_constants | ||||||||||||||||||||||||||||||||||||||||||
| 329 | { | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | my ($document, $filter, $full_text) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_constants: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | my %seen_constants; | |||||||||||||||||||||||||||||||||||||||||
| 333 | my @constants; | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | foreach my $constant (@{$document->get_constants_fast($full_text)}) | |||||||||||||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | next if $seen_constants{$constant}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | next if ($constant =~ /\n/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | push @constants, {label => $constant, kind => 21}; | |||||||||||||||||||||||||||||||||||||||||
| 340 | } ## end foreach my $constant (@{$document...}) | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | return \@constants; | |||||||||||||||||||||||||||||||||||||||||
| 343 | } ## end sub get_constants | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | sub get_variables | ||||||||||||||||||||||||||||||||||||||||||
| 346 | { | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | my ($document, $full_text) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_variables: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my @variables; | |||||||||||||||||||||||||||||||||||||||||
| 350 | my %seen_variables; | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | state @builtin_variables; | |||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | unless (scalar @builtin_variables) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | { | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $perldoc = PLS::Parser::Pod->get_perldoc_location(); | |||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if (open my $fh, '-|', $perldoc, '-Tu', 'perlvar') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | while (my $line = <$fh>) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | { | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if ($line =~ /=item\s*(C<)?([\$\@\%]\S+)\s*/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | { | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # If variable started with pod sequence "C<" remove ">" from the end | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my $variable = $2; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | $variable = substr $variable, 0, -1 if (length $1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | # Remove variables indicated by pod sequences | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | next if ($variable =~ /^\$</ and $variable ne '$<'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$variable =~ /^\$</ and $variable ne "\$<"
MC/DC0%0/2
$variable =~ /^\$</ and $variable ne "\$<"
$variable =~ /^\$</
$variable ne "\$<"
Truth table0%0/3
A and B
A= $variable =~ /^\$</B= $variable ne "\$<"
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | push @builtin_variables, $variable; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } ## end if ($line =~ /=item\s*(C<)?([\$\@\%]\S+)\s*/...) | ||||||||||||||||||||||||||||||||||||||||||
| 372 | } ## end while (my $line = <$fh>) | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 375 | } ## end if (open my $fh, '-|',...) | ||||||||||||||||||||||||||||||||||||||||||
| 376 | } ## end unless (scalar @builtin_variables...) | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | foreach my $variable (@builtin_variables, @{$document->get_variables_fast($full_text)}) | |||||||||||||||||||||||||||||||||||||||||
| 379 | { | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | next if $seen_variables{$variable}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | next if ($variable =~ /\n/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | push @variables, | |||||||||||||||||||||||||||||||||||||||||
| 383 | { | ||||||||||||||||||||||||||||||||||||||||||
| 384 | label => $variable, | ||||||||||||||||||||||||||||||||||||||||||
| 385 | kind => 6 | ||||||||||||||||||||||||||||||||||||||||||
| 386 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | # add other variable forms to the list for arrays and hashes | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if ($variable =~ /^[\@\%]/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | { | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my $name = $variable =~ s/^[\@\%]/\$/r; | |||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | my $append = $variable =~ /^\@/ ? '[' : '{'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | push @variables, | |||||||||||||||||||||||||||||||||||||||||
| 394 | { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | label => $variable, | ||||||||||||||||||||||||||||||||||||||||||
| 396 | insertText => $name . $append, | ||||||||||||||||||||||||||||||||||||||||||
| 397 | filterText => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 398 | kind => 6 | ||||||||||||||||||||||||||||||||||||||||||
| 399 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 400 | } ## end if ($variable =~ /^[\@\%]/...) | ||||||||||||||||||||||||||||||||||||||||||
| 401 | } ## end foreach my $variable (@builtin_variables...) | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | return \@variables; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } ## end sub get_variables | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | sub get_snippets | ||||||||||||||||||||||||||||||||||||||||||
| 407 | { | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | state @snippets; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_snippets: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | return @snippets if (scalar @snippets); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | @snippets = ( | |||||||||||||||||||||||||||||||||||||||||
| 413 | { | ||||||||||||||||||||||||||||||||||||||||||
| 414 | label => 'sub', | ||||||||||||||||||||||||||||||||||||||||||
| 415 | detail => 'Insert subroutine', | ||||||||||||||||||||||||||||||||||||||||||
| 416 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 417 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 418 | insertText => "sub \$1\n{\n\t\$0\n}", | ||||||||||||||||||||||||||||||||||||||||||
| 419 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 420 | { | ||||||||||||||||||||||||||||||||||||||||||
| 421 | label => 'foreach', | ||||||||||||||||||||||||||||||||||||||||||
| 422 | detail => 'Insert foreach loop', | ||||||||||||||||||||||||||||||||||||||||||
| 423 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 424 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 425 | insertText => "foreach my \$1 (\$2)\n{\n\t\$0\n}", | ||||||||||||||||||||||||||||||||||||||||||
| 426 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 427 | { | ||||||||||||||||||||||||||||||||||||||||||
| 428 | label => 'for', | ||||||||||||||||||||||||||||||||||||||||||
| 429 | detail => 'Insert C-style for loop', | ||||||||||||||||||||||||||||||||||||||||||
| 430 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 431 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 432 | insertText => "for (\$1 ; \$2 ; \$3)\n{\n\t\$0\n}", | ||||||||||||||||||||||||||||||||||||||||||
| 433 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 434 | { | ||||||||||||||||||||||||||||||||||||||||||
| 435 | label => 'while', | ||||||||||||||||||||||||||||||||||||||||||
| 436 | detail => 'Insert while statement', | ||||||||||||||||||||||||||||||||||||||||||
| 437 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 438 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 439 | insertText => "while (\$1)\n{\n\t\$0\n}", | ||||||||||||||||||||||||||||||||||||||||||
| 440 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 441 | { | ||||||||||||||||||||||||||||||||||||||||||
| 442 | label => 'if', | ||||||||||||||||||||||||||||||||||||||||||
| 443 | detail => 'Insert if statement', | ||||||||||||||||||||||||||||||||||||||||||
| 444 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 445 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 446 | insertText => "if (\$1)\n{\n\t\$0\n}", | ||||||||||||||||||||||||||||||||||||||||||
| 447 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 448 | { | ||||||||||||||||||||||||||||||||||||||||||
| 449 | label => 'elsif', | ||||||||||||||||||||||||||||||||||||||||||
| 450 | detail => 'Insert elsif statement', | ||||||||||||||||||||||||||||||||||||||||||
| 451 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 452 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 453 | insertText => "elsif (\$1)\n{\n\t\$0\n}", | ||||||||||||||||||||||||||||||||||||||||||
| 454 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 455 | { | ||||||||||||||||||||||||||||||||||||||||||
| 456 | label => 'else', | ||||||||||||||||||||||||||||||||||||||||||
| 457 | detail => 'Insert else statement', | ||||||||||||||||||||||||||||||||||||||||||
| 458 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 459 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 460 | insertText => "else\n{\n\t\$0\n}", | ||||||||||||||||||||||||||||||||||||||||||
| 461 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 462 | { | ||||||||||||||||||||||||||||||||||||||||||
| 463 | label => 'package', | ||||||||||||||||||||||||||||||||||||||||||
| 464 | detail => 'Create a new package', | ||||||||||||||||||||||||||||||||||||||||||
| 465 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 466 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 467 | insertText => "package \$1;\n\nuse strict;\nuse warnings;\n\n\$0\n\n1;", | ||||||||||||||||||||||||||||||||||||||||||
| 468 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 469 | { | ||||||||||||||||||||||||||||||||||||||||||
| 470 | label => 'open my $fh, ...', | ||||||||||||||||||||||||||||||||||||||||||
| 471 | filterText => 'open', | ||||||||||||||||||||||||||||||||||||||||||
| 472 | sortText => 'open', | ||||||||||||||||||||||||||||||||||||||||||
| 473 | detail => 'Insert an open statement', | ||||||||||||||||||||||||||||||||||||||||||
| 474 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 475 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 476 | insertText => q[open $1, '${2|<,>,>>,+<,+>,\|-,-\|,>&,<&=,>>&=|}', $3], | ||||||||||||||||||||||||||||||||||||||||||
| 477 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 478 | { | ||||||||||||||||||||||||||||||||||||||||||
| 479 | label => 'do { local $/; <$fh> }', | ||||||||||||||||||||||||||||||||||||||||||
| 480 | filterText => 'do', | ||||||||||||||||||||||||||||||||||||||||||
| 481 | sortText => 'do1', | ||||||||||||||||||||||||||||||||||||||||||
| 482 | detail => 'Slurp an entire filehandle', | ||||||||||||||||||||||||||||||||||||||||||
| 483 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 484 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 485 | insertText => 'do { local $/; <$1> }' | ||||||||||||||||||||||||||||||||||||||||||
| 486 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 487 | { | ||||||||||||||||||||||||||||||||||||||||||
| 488 | label => 'while (my $line = <$fh>) { ... }', | ||||||||||||||||||||||||||||||||||||||||||
| 489 | filterText => 'while', | ||||||||||||||||||||||||||||||||||||||||||
| 490 | sortText => 'while1', | ||||||||||||||||||||||||||||||||||||||||||
| 491 | detail => 'Iterate through a filehandle line-by-line', | ||||||||||||||||||||||||||||||||||||||||||
| 492 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 493 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 494 | insertText => "while (my \$1 = <\$2>)\n{\n\t\$0\n}" | ||||||||||||||||||||||||||||||||||||||||||
| 495 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||||||||||||||||
| 497 | label => 'my ($param1, $param2, ...) = @_;', | ||||||||||||||||||||||||||||||||||||||||||
| 498 | filterText => 'my', | ||||||||||||||||||||||||||||||||||||||||||
| 499 | sortText => 'my1', | ||||||||||||||||||||||||||||||||||||||||||
| 500 | detail => 'Get subroutine parameters', | ||||||||||||||||||||||||||||||||||||||||||
| 501 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 502 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 503 | insertText => "my (\$1) = \@_;\n\n" | ||||||||||||||||||||||||||||||||||||||||||
| 504 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 505 | { | ||||||||||||||||||||||||||||||||||||||||||
| 506 | label => '$? >> 8', | ||||||||||||||||||||||||||||||||||||||||||
| 507 | filterText => '$?', | ||||||||||||||||||||||||||||||||||||||||||
| 508 | sortText => '$?', | ||||||||||||||||||||||||||||||||||||||||||
| 509 | detail => 'Get exit code', | ||||||||||||||||||||||||||||||||||||||||||
| 510 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 511 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 512 | insertText => '? >> 8' | ||||||||||||||||||||||||||||||||||||||||||
| 513 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 514 | { | ||||||||||||||||||||||||||||||||||||||||||
| 515 | label => 'sort { $a <=> $b } ...', | ||||||||||||||||||||||||||||||||||||||||||
| 516 | filterText => 'sort', | ||||||||||||||||||||||||||||||||||||||||||
| 517 | sortText => 'sort1', | ||||||||||||||||||||||||||||||||||||||||||
| 518 | detail => 'Sort numerically ascending', | ||||||||||||||||||||||||||||||||||||||||||
| 519 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 520 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 521 | insertText => 'sort { \$a <=> \$b } $1' | ||||||||||||||||||||||||||||||||||||||||||
| 522 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 523 | { | ||||||||||||||||||||||||||||||||||||||||||
| 524 | label => 'reverse sort { $a <=> $b } ...', | ||||||||||||||||||||||||||||||||||||||||||
| 525 | filterText => 'sort', | ||||||||||||||||||||||||||||||||||||||||||
| 526 | sortText => 'sort2', | ||||||||||||||||||||||||||||||||||||||||||
| 527 | detail => 'Sort numerically descending', | ||||||||||||||||||||||||||||||||||||||||||
| 528 | kind => 15, | ||||||||||||||||||||||||||||||||||||||||||
| 529 | insertTextFormat => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 530 | insertText => 'reverse sort { \$a <=> \$b } $1' | ||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||
| 532 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | return @snippets; | |||||||||||||||||||||||||||||||||||||||||
| 535 | } ## end sub get_snippets | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||