blib/lib/Complete/Riap.pm

filter: Statementstmt 40.0% 20 / 50 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 57.1% 4 / 7 Podpod 100% 1 / 1 totaltotal 27.1% 25 / 92 CC 14 SCAR 38.8
CC
14
Cov
26%
__ANON__
72.0
complete_riap_url
56.0
BEGIN
1.0
CRAP 48.6
↑ Summary
1 package Complete::Riap;
2  
3 1 our $DATE = '2015-11-29'; # DATE
4 1 our $VERSION = '0.07'; # VERSION
5  
6 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 Complete::Common qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our %SPEC;
13 1 require Exporter;
14 1 our @ISA = qw(Exporter);
15 1 our @EXPORT_OK = qw(complete_riap_url);
16  
17 1 $SPEC{':package'} = {
18 v => 1.1,
19 summary => 'Riap-related completion routines',
20 };
21  
22 $SPEC{complete_riap_url} = {
23 1 v => 1.1,
24 summary => 'Complete Riap URL',
25 description => <<'_',
26  
27 Currently only support local Perl schemes (e.g. `/Pkg/Subpkg/function` or
28 `pl:/Pkg/Subpkg/`).
29  
30 _
31 args => {
32 %arg_word,
33 type => {
34 schema => ['str*', in=>['function','package']], # XXX other types?
35 summary => 'Filter by entity type',
36 },
37 riap_client => {
38 schema => 'obj*',
39 },
40 },
41 result_naked => 1,
42 };
43 0 ▶sub complete_riap_url {
Subroutine complete_riap_url: not called CC=7 SCAR=40.3
Pod documented
44 0 require Complete::Path;
45  
46 0 my %args = @_;
47  
48 0 ▶ my $word = $args{word} // ''; $word = '/' if !length($word);
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 0 0 0
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
49 0 ▶ $word = "/$word" unless $word =~ m!\A/!;
Branch: 1 branch
BranchTrueFalseTotal
unless $word =~ m[\A/] 0 0 0
50 0 ▶ my $type = $args{type} // '';
Condition0%0/2
$args{"type"} // ""
l!l
00
MC/DC0%0/1
$args{"type"} // ""
$args{"type"}
Truth table0%0/2
A
A= $args{"type"}
Aresult
11
00
51  
52 0 my $starting_path;
53 0 my $result_prefix = '';
54 0 ▶ if ($word =~ s!\A/!!) {
Branch: 2 branches
BranchTrueFalseTotal
if ($word =~ s[\A/][]) { } 0 0 0
elsif ($word =~ s[\Apl:/][/]) { } 0 0 0
55 0 $starting_path = '/';
56 0 $result_prefix = '/';
57 } elsif ($word =~ s!\Apl:/!/!) {
58 0 $starting_path = 'pl:';
59 0 $result_prefix = 'pl:';
60 } else {
61 0 return [];
62 }
63  
64 my $res = Complete::Path::complete_path(
65 word => $word,
66 0 ▶ list_func => sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
67 0 my ($path, $intdir, $isint) = @_;
68  
69 0 state $default_pa = do {
70 0 require Perinci::Access;
71 0 Perinci::Access->new;
72 };
73 0 ▶ my $pa = $args{riap_client} // $default_pa;
Condition0%0/3
$args{"riap_client"} // $default_pa
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"riap_client"} // $default_pa
$args{"riap_client"} $default_pa
Truth table0%0/3
A // B
A= $args{"riap_client"}B= $default_pa
ABresult
1X1
011
000
74  
75 0 ▶ $path = "/$path" unless $path =~ m!\A/!;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ m[\A/] 0 0 0
76 0 my $riap_res = $pa->request(list => $path, {detail=>1});
77 0 ▶ return [] unless $riap_res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $riap_res->[0] == 200 0 0 0
78 0 my @res;
79 0 for my $ent (@{ $riap_res->[2] }) {
80 next unless $ent->{type} eq 'package' ||
81 0 ▶ (!$type || $type eq $ent->{type});
Branch: 1 branch
BranchTrueFalseTotal
unless $ent->{"type"} eq "package" or (not $type or $type eq $ent->{"type"}) 0 0 0
Condition0%0/6
$ent->{"type"} eq "package" or (not $type or $type eq $ent->{"type"})
l!l&&r!l&&!r
000
not $type or $type eq $ent->{"type"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$ent->{"type"} eq "package" or (not $type or $type eq $ent->{"type"})
$ent->{"type"} eq "package" not $type $type eq $ent->{"type"}
Truth table0%0/4
A or not(B) or C
A= $ent->{"type"} eq "package"B= not $typeC= $type eq $ent->{"type"}
ABCresult
1XX1
01X1
0011
0000
82 0 push @res, $ent->{uri};
83 }
84 0 \@res;
85 },
86 starting_path => $starting_path,
87 result_prefix => $result_prefix,
88 0 ▶ is_dir_func => sub { }, # not needed, we already suffixed "dir" with /
Subroutine __ANON__: not called CC=1 SCAR=0.0
89 0 );
90  
91 0 {words=>$res, path_sep=>'/'};
92 }
93  
94 1 1;
95 # ABSTRACT: Riap-related completion routines
96  
97 __END__
↑ Summary