| 1 | package PLS::Server::Request::TextDocument::PublishDiagnostics; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use parent 'PLS::Server::Request'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Fcntl (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use File::Path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use File::Temp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 13 | ▶ | use IO::Async::Function; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use IO::Async::Loop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | ▶ | use IO::Async::Process; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 13 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | ▶ | use PPI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 13 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | use Perl::Critic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | use Perl::Critic::PolicyParameter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 13 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 13 | ▶ | use PLS::Parser::Pod; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 13 | ▶ | use PLS::Server::State; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 13 | ▶ | use PLS::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | PLS::Server::Request::TextDocument::PublishDiagnostics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | This is a message from the server to the client requesting that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | diagnostics be published. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | These diagnostics currently include compilation errors and linting (using L<perlcritic>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 13 | my $perlcritic_function = IO::Async::Function->new(code => \&run_perlcritic); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 13 | my $podchecker_function = IO::Async::Function->new(code => \&run_podchecker); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | my $loop = IO::Async::Loop->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 13 | $loop->add($perlcritic_function); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 13 | $loop->add($podchecker_function); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | return if (ref $PLS::Server::State::CONFIG ne 'HASH'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my $uri = URI->new($args{uri}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | return if (ref $uri ne 'URI::file'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | method => 'textDocument/publishDiagnostics', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | params => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | uri => $uri->as_string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | diagnostics => [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | notification => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | my (undef, $dir, $suffix) = File::Basename::fileparse($uri->file, qr/\.[^\.]*$/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | my $source = $uri->file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | my $text = PLS::Parser::Document->text_from_uri($uri->as_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | $source = $text if (ref $text eq 'SCALAR'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my $version = PLS::Parser::Document::uri_version($uri->as_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | my $client_has_version_support = $PLS::Server::State::CLIENT_CAPABILITIES->{textDocument}{publishDiagnostics}{versionSupport}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | $self->{params}{version} = $version if (length $version and $client_has_version_support); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $version and $client_has_version_support
MC/DC0%0/2
length $version and $client_has_version_support
length $version
$client_has_version_support
Truth table33%1/3
A and B
A= length $versionB= $client_has_version_support
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # If closing, return empty list of diagnostics. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | ▶ | return Future->done($self) if $args{close}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | my @futures; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | ▶ | push @futures, get_compilation_errors($source, $dir, $uri->file, $suffix) if ($PLS::Server::State::CONFIG->{syntax}{enabled}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | push @futures, get_perlcritic_errors($source, $uri->file) if ($PLS::Server::State::CONFIG->{perlcritic}{enabled}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | push @futures, get_podchecker_errors($source) if ($PLS::Server::State::CONFIG->{podchecker}{enabled}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | return Future->wait_all(@futures)->then( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | my $current_version = PLS::Parser::Document::uri_version($uri->as_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # No version will be returned if the document has been closed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Since the only way we got here is if the document is open, we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # should return nothing, since any diagnostics we return will be from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # when the document was still open. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | ▶ | return Future->done(undef) unless (length $current_version); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # If the document has been updated since the diagnostics were created, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # send nothing back. The next update will re-trigger the diagnostics. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | return Future->done(undef) if (length $version and $current_version > $version); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $version and $current_version > $version
MC/DC0%0/2
length $version and $current_version > $version
length $version
$current_version > $version
Truth table33%1/3
A and B
A= length $versionB= $current_version > $version
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | @{$self->{params}{diagnostics}} = map { $_->result } @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | return Future->done($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } ## end sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | sub get_compilation_errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_compilation_errors: called CC=15 SCAR=32.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | my ($source, $dir, $orig_path, $suffix) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | my $future = $loop->new_future(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | my $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | my $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | my $temp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | if (ref $source eq 'SCALAR') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | $temp = eval { File::Temp->new(CLEANUP => 0, TEMPLATE => '.pls-tmp-XXXXXXXXXX', DIR => $dir) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $temp = eval { File::Temp->new(CLEANUP => 0) } if (ref $temp ne 'File::Temp'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | $path = $temp->filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | ▶ | $future->on_done(sub { unlink $temp }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | my $source_text = Encode::encode('UTF-8', ${$source}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | print {$temp} $source_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | close $temp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | ▶ | open $fh, '<', \$source_text or return []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } ## end if (ref $source eq 'SCALAR'...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $path = $source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | open $fh, '<', $path or return []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | my $line_lengths = get_line_lengths($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | my $perl = PLS::Parser::Pod->get_perl_exe(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | my $inc = PLS::Parser::Pod->get_clean_inc(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | my $args = PLS::Parser::Pod->get_perl_args(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | ▶ | my @inc = map { "-I$_" } @{$inc // []}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$inc // []
MC/DC0%0/1
$inc // []
$inc
Truth table50%1/2
A
A= $inc
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | my @loadfile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | ▶ | if (not length $suffix or $suffix eq '.pl' or $suffix eq '.t' or $suffix eq '.plx') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%3/9
not length $suffix or $suffix eq ".pl" or $suffix eq ".t" or $suffix eq ".plx"
not length $suffix or $suffix eq ".pl" or $suffix eq ".t"
not length $suffix or $suffix eq ".pl"
MC/DC0%0/4
not length $suffix or $suffix eq ".pl" or $suffix eq ".t" or $suffix eq ".plx"
not length $suffix
$suffix eq ".pl"
$suffix eq ".t"
$suffix eq ".plx"
Truth table20%1/5
not(A) or B or C or D
A= not length $suffixB= $suffix eq ".pl"C= $suffix eq ".t"D= $suffix eq ".plx"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | @loadfile = (-c => $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | elsif ($suffix eq '.pod') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $future->done(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | return $future; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | my ($relative, $module); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # Try to get the path as relative to @INC. If we're successful, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # then we can convert it to a package name and import it using that name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # instead of the full path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | foreach my $inc_path (@{$inc}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 16 | my $rel = path($orig_path)->relative($inc_path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 16 | ▶ | if ($rel !~ /\.\./) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | $module = $rel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | $relative = $rel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | $module =~ s/\.pm$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 2 | $module =~ s/\//::/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } ## end if ($rel !~ /\.\./) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } ## end foreach my $inc_path (@{$inc...}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | my $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | $path =~ s/'/\\'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 2 | ▶ | if (length $module and length $relative) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $module and length $relative
MC/DC0%0/2
length $module and length $relative
length $module
length $relative
Truth table33%1/3
A and B
A= length $moduleB= length $relative
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | $relative =~ s/'/\\'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # Load code using module name, but redirect Perl to the temp file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # when loading the file we are compiling. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | $code = <<~ "EOF"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | unshift \@INC, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | my (undef, \$filename) = \@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | if (\$filename eq '$relative') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | if (open my \$fh, '<', '$path') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | \$INC{\$filename} = '$orig_path'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | return \$fh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | require $module; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } ## end if (length $module and...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $code = "BEGIN { require '$path' }"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | @loadfile = (-e => $code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } ## end else[ if (not length $suffix...)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | my @diagnostics; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | my $proc = IO::Async::Process->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | command => [$perl, @inc, @loadfile, '--', @{$args}], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | setup => [chdir => path($orig_path)->parent], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | stderr => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | ▶ | on_read => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=13 SCAR=35.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | my ($stream, $buffref, $eof) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | ▶ | while (${$buffref} =~ s/^(.*)\n//) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 7 | my $line = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 7 | ▶ | next if $line =~ /syntax OK$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 7 | ▶ | if (my ($error, $file, $line_num, $area) = $line =~ /^(.+) at (.+?) line (\d+)(, .+)?/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 7 | $line_num = int $line_num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 7 | ▶ | $file = $orig_path if ($file eq $path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 7 | ▶ | if ($file ne $path and $file ne $orig_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$file ne $path and $file ne $orig_path
MC/DC0%0/2
$file ne $path and $file ne $orig_path
$file ne $path
$file ne $orig_path
Truth table33%1/3
A and B
A= $file ne $pathB= $file ne $orig_path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 7 | ▶ | $error .= " at $file line $line_num" if ($file ne '-e'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | $line_num = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 7 | ▶ | if (length $area) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | if ($area =~ /^, near "/ and $area !~ /"$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$area =~ /^, near "/ and not $area =~ /"$/
MC/DC0%0/2
$area =~ /^, near "/ and not $area =~ /"$/
$area =~ /^, near "/
not $area =~ /"$/
Truth table0%0/3
A and not(B)
A= $area =~ /^, near "/B= not $area =~ /"$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $area .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | while (${$buffref} =~ s/^(.*\n)//) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $area .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | last if ($1 =~ /"$/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } ## end if ($area =~ /^, near "/...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $error .= $area; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } ## end if (length $area) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 7 | push @diagnostics, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | range => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | start => {line => $line_num - 1, character => 0}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | end => {line => $line_num - 1, character => $line_lengths->[$line_num]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | message => $error, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | severity => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | source => 'perl', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } ## end if (my ($error, $file,...)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } ## end while (${$buffref} =~ s/^(.*)\n//...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | stdout => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | ▶ | on_read => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | my ($stream, $buffref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # Discard STDOUT, otherwise it might interfere with the server execution. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # This can happen if there is a BEGIN block that prints to STDOUT. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1 | ${$buffref} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | ▶ | on_finish => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | $future->done(@diagnostics); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | $loop->add($proc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | return $future; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } ## end sub get_compilation_errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | sub get_perlcritic_errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_perlcritic_errors: called CC=5 SCAR=17.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 2 | my ($source, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 2 | my ($profile) = PLS::Util::resolve_workspace_relative_path($PLS::Server::State::CONFIG->{perlcritic}{perlcriticrc}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | ▶ | if (not length $profile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | ($profile) = glob $PLS::Server::State::CONFIG->{perlcritic}{perlcriticrc}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | ▶ | if (not length $profile or not -f $profile or not -r $profile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
length $profile and -f $profile and -r $profile
length $profile and -f $profile
MC/DC0%0/3
length $profile and -f $profile and -r $profile
length $profile
-f $profile
-r $profile
Truth table25%1/4
A and B and C
A= length $profileB= -f $profileC= -r $profile
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | undef $profile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | my ($perltidyrc) = PLS::Util::resolve_workspace_relative_path($PLS::Server::State::CONFIG->{perltidy}{perltidyrc}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | return $perlcritic_function->call(args => [$profile, $source, $path, $perltidyrc]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } ## end sub get_perlcritic_errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | sub run_perlcritic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_perlcritic: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my ($profile, $source, $path, $perltidyrc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $critic = Perl::Critic->new(-profile => $profile); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | _set_perltidyrc_path_for_perltidy_policy($critic, $perltidyrc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my %args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | $args{filename} = $path if (ref $source eq 'SCALAR'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my $doc = PPI::Document->new($source, %args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my @violations = eval { $critic->critique($doc) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my @diagnostics; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Mapping from perlcritic severity to LSP severity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my %severity_map = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 5 => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 3 => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 => 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | foreach my $violation (@violations) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my $severity = $severity_map{$violation->severity}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $uri = URI->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $uri->scheme('https'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $uri->authority('metacpan.org'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $uri->path('pod/' . $violation->policy); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | push @diagnostics, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | range => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | start => {line => $violation->line_number - 1, character => $violation->column_number - 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | end => {line => $violation->line_number - 1, character => $violation->column_number + length($violation->source) - 1} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | message => $violation->description, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | code => $violation->policy, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | codeDescription => {href => $uri->as_string}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | severity => $severity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | source => 'perlcritic' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } ## end foreach my $violation (@violations...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | return @diagnostics; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } ## end sub run_perlcritic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | sub get_line_lengths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_line_lengths: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | my ($fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | my @line_lengths; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | ▶ | while (my $line = <$fh>) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 234 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 234 | $line_lengths[$.] = length $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | return \@line_lengths; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } ## end sub get_line_lengths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | sub get_podchecker_errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_podchecker_errors: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my ($source) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return $podchecker_function->call(args => [$source]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | sub run_podchecker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_podchecker: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my ($source) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | return unless (eval { require Pod::Checker; 1 }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my $errors = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | open my $ofh, '>', \$errors or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | open my $ifh, '<', $source or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $line_lengths = get_line_lengths($ifh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | seek $ifh, 0, Fcntl::SEEK_SET; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | Pod::Checker::podchecker($ifh, $ofh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my @diagnostics; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | while ($errors =~ s/^(.*)\n//) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my $line = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | if (my ($severity, $error, $line_num) = $line =~ /^\**\s*([A-Z]{3,}):\s*(.+) at line (\d+) in file/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | push @diagnostics, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | range => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | start => {line => $line_num - 1, character => 0}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | end => {line => $line_num - 1, character => $line_lengths->[$line_num]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | message => $error, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | severity => $severity eq 'ERROR' ? 1 : 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | source => 'podchecker', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } ## end if (my ($severity, $error...)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } ## end while ($errors =~ s/^(.*)\n//...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | return @diagnostics; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } ## end sub run_podchecker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | sub _set_perltidyrc_path_for_perltidy_policy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_perltidyrc_path_for_perltidy_policy: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my ($critic, $perltidyrc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if (not length $perltidyrc or not -f $perltidyrc) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $perltidyrc and -f $perltidyrc
MC/DC0%0/2
length $perltidyrc and -f $perltidyrc
length $perltidyrc
-f $perltidyrc
Truth table0%0/3
A and B
A= length $perltidyrcB= -f $perltidyrc
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | my $policy = first { $_->isa('Perl::Critic::Policy::CodeLayout::RequireTidyCode') } $critic->config->policies; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | if (not $policy) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | my ($parameter) = first { $_->get_name() eq 'perltidyrc' } map { Perl::Critic::PolicyParameter->new($_) } $policy->supported_parameters; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if (not $parameter) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $parameter->parse_and_validate_config_value($policy, {perltidyrc => $perltidyrc}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } ## end sub _set_perltidyrc_path_for_perltidy_policy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||