| 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
Condition0%0/2
$args{"word"} // ""
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $word = "/$word" unless $word =~ m!\A/!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $type = $args{type} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"type"} // ""
MC/DC0%0/1
$args{"type"} // ""
$args{"type"}
Truth table0%0/2
A
A= $args{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $starting_path; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $result_prefix = ''; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($word =~ s!\A/!!) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $path = "/$path" unless $path =~ m!\A/!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $riap_res = $pa->request(list => $path, {detail=>1}); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return [] unless $riap_res->[0] == 200; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$ent->{"type"} eq "package" or (not $type or $type eq $ent->{"type"})
not $type or $type eq $ent->{"type"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||