PLS/Server/Response/RangeFormatting.pm

filter: Statementstmt 62.5% 25 / 40 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 1 totaltotal 58.1% 32 / 55 CC 3 SCAR 10.1
CC
3
Cov
57%
new
6.0
__ANON__
6.0
__ANON__
2.0
CRAP 2.8
« PLS/Parser/Pod/Builtin.pm ↑ Summary PLS/Server/Request/Exit.pm »
1 package PLS::Server::Response::RangeFormatting;
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  
8 9 ▶use IO::Async::Function;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use IO::Async::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 ▶use PLS::Parser::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use PLS::Server::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 PLS::Server::Response::RangeFormatting
17  
18 =head1 DESCRIPTION
19  
20 This is a message from the server to the client with a document range
21 after having been formatted.
22  
23 =cut
24  
25 # Set up formatting as a function because it can be slow
26 9 my $loop = IO::Async::Loop->new();
27 my $function = IO::Async::Function->new(
28 code => sub {
29 0 ▶ my ($self, $request, $text, $perltidyrc) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
30  
31 0 my ($ok, $formatted) = PLS::Parser::Document->format_range(text => $text, range => $request->{params}{range}, formatting_options => $request->{params}{options}, perltidyrc => $perltidyrc);
32 0 return $ok, $formatted;
33 }
34 9 );
35 9 $loop->add($function);
36  
37 sub new
38 {
39 0 ▶ my ($class, $request) = @_;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
40  
41 0 ▶ if (ref $request->{params}{options} eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $request->{"params"}{"options"} eq "HASH") 0 0 0
42 {
43 # these options aren't really valid for range formatting
44 0 delete $request->{params}{options}{trimFinalNewlines};
45 0 delete $request->{params}{options}{insertFinalNewline};
46 } ## end if (ref $request->{params...})
47  
48 0 my $self = bless {id => $request->{id}}, $class;
49 0 my $text = PLS::Parser::Document->text_from_uri($request->{params}{textDocument}{uri});
50  
51 return $function->call(args => [$self, $request, $text, $PLS::Server::State::CONFIG->{perltidy}{perltidyrc}])->then(
52 sub {
53 0 ▶ my ($ok, $formatted) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
54  
55 0 ▶ if ($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 0 0 0
56 {
57 0 $self->{result} = $formatted;
58 }
59 else
60 {
61 0 $self->{error} = $formatted;
62 }
63  
64 0 return $self;
65 }
66 0 );
67 } ## end sub new
68  
69 9 1;
« PLS/Parser/Pod/Builtin.pm ↑ Summary PLS/Server/Request/Exit.pm »