lib/Neovim/RPC/Plugin/FileToPackageName.pm

filter: Statementstmt 48.8% 21 / 43 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 6 / 14 Podpod 0.0% 0 / 3 totaltotal 36.9% 27 / 73 CC 6 SCAR 18.2
CC
6
Cov
39%
collect_props
15.8
__ANON__
12.0
file_to_package_name
2.0
CRAP 6.2
« lib/Neovim/RPC/API/AutoDiscover.pm ↑ Summary lib/Neovim/RPC/API/Command.pm »
1 package Neovim::RPC::Plugin::FileToPackageName;
2 1 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: turns a path into a package name
4 1 $Neovim::RPC::Plugin::FileToPackageName::VERSION = '1.0.1';
5 1 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Neovim::RPC::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub file_to_package_name {
Subroutine file_to_package_name: not called CC=1 SCAR=6.9
Pod undocumented
15 shift
16 0 =~ s#^(.*/)?lib/##r
17 =~ s#^/##r
18 =~ s#/#::#rg
19 =~ s#\.p[ml]$##r;
20 }
21  
22 0 ▶sub shall_get_filename ($self) {
Subroutine shall_get_filename: not called CC=1 SCAR=6.9
Pod undocumented
23 0 $self->api->vim_call_function( fname => 'expand', args => [ '%:p' ] );
24 }
25  
26 subscribe file_to_package_name => rpcrequest
27 0 ▶ sub($self,@) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 collect_props(
29 filename => $self->shall_get_filename,
30 line => $self->api->vim_get_current_line,
31 )
32 },
33 0 ▶ sub ($self,$props) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 $self->api->vim_set_current_line(
35 0 $props->{line} =~ s/__PACKAGE__/file_to_package_name($props->{filename})/er
36 )
37 1 };
38  
39  
40 0 ▶sub collect_props {
Subroutine collect_props: not called CC=4 SCAR=27.6
Pod undocumented
41  
42 1 ▶ use Promises qw/ deferred /;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 0 my %promises = @_;
44  
45 0 my $all_done = deferred();
46  
47 0 my $results = {};
48 0 my $remaining = scalar keys %promises;
49  
50 0 ▶ my $are_we_there_yet = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
51 0 ▶ return if --$remaining;
Branch: 1 branch
BranchTrueFalseTotal
if --$remaining 0 0 0
52  
53 0 ▶ return if $all_done->is_rejected;
Branch: 1 branch
BranchTrueFalseTotal
if $all_done->is_rejected 0 0 0
54  
55 0 $all_done->resolve($results);
56 0 };
57  
58 0 ▶ while( my( $key, $promise ) = each %promises ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %promises) 0 0 0
59 0 ▶ unless( ref $promise eq 'Promises::Promise' or ref $promise eq 'Promises::Deferred' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $promise eq "Promises::Promise" or ref $promise eq "Promises::Deferred") 0 0 0
Condition0%0/3
ref $promise eq "Promises::Promise" or ref $promise eq "Promises::Deferred"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $promise eq "Promises::Promise" or ref $promise eq "Promises::Deferred"
ref $promise eq "Promises::Promise" ref $promise eq "Promises::Deferred"
Truth table0%0/3
A or B
A= ref $promise eq "Promises::Promise"B= ref $promise eq "Promises::Deferred"
ABresult
1X1
011
000
60 0 my $p = deferred();
61 0 $p->resolve($promise);
62 0 $promise = $p;
63 }
64  
65 0 ▶ $promise->then(sub{ $results->{$key} = shift })
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 0 ▶ ->then( $are_we_there_yet, sub { $all_done->reject(@_) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 }
68  
69 0 return $all_done->promise;
70 }
71 1 1;
72  
73 __END__
« lib/Neovim/RPC/API/AutoDiscover.pm ↑ Summary lib/Neovim/RPC/API/Command.pm »