| 1 | package Complete::Riap::Clientless; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | our $DATE = '2017-01-01'; # DATE | |||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.002'; # 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 | 1 | ▶ | use List::MoreUtils qw(uniq); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | our %SPEC; | |||||||||||||||||||||||||||
| 14 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 15 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 16 | 1 | our @EXPORT_OK = qw(complete_riap_url); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | $SPEC{':package'} = { | |||||||||||||||||||||||||||
| 19 | v => 1.1, | ||||||||||||||||||||||||||||
| 20 | summary => 'Riap-related completion routines (clientless version)', | ||||||||||||||||||||||||||||
| 21 | description => <<'_', | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | This is an alternative to <pm:Complete::Riap>. It does not utilize a <pm:Riap> | ||||||||||||||||||||||||||||
| 24 | client but instead inspect `%SPEC` package variables directly. Thus, it can only | ||||||||||||||||||||||||||||
| 25 | be used to complete local Riap URL's. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | _ | ||||||||||||||||||||||||||||
| 28 | }; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | $SPEC{complete_riap_url} = { | ||||||||||||||||||||||||||||
| 31 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 32 | summary => 'Complete Riap URL', | ||||||||||||||||||||||||||||
| 33 | description => <<'_', | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Only supports local Perl schemes (e.g. `/Pkg/Subpkg/function` or | ||||||||||||||||||||||||||||
| 36 | `pl:/Pkg/Subpkg/`). | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | _ | ||||||||||||||||||||||||||||
| 39 | args => { | ||||||||||||||||||||||||||||
| 40 | %arg_word, | ||||||||||||||||||||||||||||
| 41 | type => { | ||||||||||||||||||||||||||||
| 42 | schema => ['str*', in=>['function','package']], # XXX other types? | ||||||||||||||||||||||||||||
| 43 | summary => 'Filter by entity type', | ||||||||||||||||||||||||||||
| 44 | }, | ||||||||||||||||||||||||||||
| 45 | riap_client => { | ||||||||||||||||||||||||||||
| 46 | schema => 'obj*', | ||||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||||||||||
| 49 | result_naked => 1, | ||||||||||||||||||||||||||||
| 50 | }; | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub complete_riap_url { | ||||||||||||||||||||||||||
|
Subroutine
complete_riap_url: not called CC=7 SCAR=39.4
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 0 | require Complete::Path; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 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"}
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $word = "/$word" unless $word =~ m!\A/!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 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"}
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | my $starting_path; | |||||||||||||||||||||||||||
| 61 | 0 | my $result_prefix = ''; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($word =~ s!\A/!!) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 63 | 0 | $starting_path = '/'; | |||||||||||||||||||||||||||
| 64 | 0 | $result_prefix = '/'; | |||||||||||||||||||||||||||
| 65 | } elsif ($word =~ s!\Apl:/!/!) { | ||||||||||||||||||||||||||||
| 66 | 0 | $starting_path = 'pl:'; | |||||||||||||||||||||||||||
| 67 | 0 | $result_prefix = 'pl:'; | |||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||
| 69 | 0 | return []; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | my $res = Complete::Path::complete_path( | ||||||||||||||||||||||||||||
| 73 | word => $word, | ||||||||||||||||||||||||||||
| 74 | path_sep => '/', | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | list_func => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=17 SCAR=55.9
| |||||||||||||||||||||||||||||
| 76 | 0 | my ($path, $intdir, $isint) = @_; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | my @res; | |||||||||||||||||||||||||||
| 79 | 0 | for my $inc (@INC) { | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | next if ref($inc); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # list .pm files and directories | ||||||||||||||||||||||||||||
| 83 | 0 | my $dir = $inc . $path; | |||||||||||||||||||||||||||
| 84 | #say "D:try opendir $dir ..."; | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (opendir my($dh), $dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | for my $e (readdir $dh) { | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | next if $e eq '.' || $e eq '..'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$e eq "." or $e eq ".."
MC/DC0%0/2
$e eq "." or $e eq ".."
$e eq "."
$e eq ".."
Truth table0%0/3
A or B
A= $e eq "."B= $e eq ".."
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | next unless $e =~ /\A\w+(\.\w+)?\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | my $is_dir = (-d "$dir/$e"); | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ($is_dir) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 91 | 0 | push @res, "$e/"; | |||||||||||||||||||||||||||
| 92 | } elsif ($e =~ /(.+)\.pm\z/) { | ||||||||||||||||||||||||||||
| 93 | 0 | push @res, "$1/"; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # list regexp patterns inside a .pm file | ||||||||||||||||||||||||||||
| 99 | 0 | (my $file = $dir) =~ s!/\z!!; $file .= ".pm"; | |||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | last unless -f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | #say "D:$file is a .pm ..."; | ||||||||||||||||||||||||||||
| 104 | 0 | (my $mod_pm = $path) =~ s!\A/!!; $mod_pm =~ s!/\z!!; | |||||||||||||||||||||||||||
| 105 | 0 | (my $mod = $mod_pm) =~ s!/!::!g; | |||||||||||||||||||||||||||
| 106 | 0 | $mod_pm .= ".pm"; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | eval { require $mod_pm; 1 } or last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | my $spec = \%{"$mod\::SPEC"}; | |||||||||||||||||||||||||||
| 110 | 0 | for my $k (keys %$spec) { | |||||||||||||||||||||||||||
| 111 | 0 | my $type; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ($k =~ /\A[$@%]/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 113 | 0 | $type = 'var'; | |||||||||||||||||||||||||||
| 114 | } elsif ($k =~ /\A\w+\z/) { | ||||||||||||||||||||||||||||
| 115 | 0 | $type = 'function'; | |||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||
| 117 | 0 | next; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | next if $args{type} && $args{type} ne $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"type"} and $args{"type"} ne $type
MC/DC0%0/2
$args{"type"} and $args{"type"} ne $type
$args{"type"}
$args{"type"} ne $type
Truth table0%0/3
A and B
A= $args{"type"}B= $args{"type"} ne $type
| |||||||||||||||||||||||||||||
| 120 | 0 | push @res, $k; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 0 | [sort(uniq(@res))]; | |||||||||||||||||||||||||||
| 126 | }, | ||||||||||||||||||||||||||||
| 127 | starting_path => $starting_path, | ||||||||||||||||||||||||||||
| 128 | result_prefix => $result_prefix, | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | is_dir_func => sub { }, # not needed, we already suffixed "dir" with / | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | 0 | ); | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | {words=>$res, path_sep=>'/'}; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 1 | 1; | |||||||||||||||||||||||||||
| 136 | # ABSTRACT: Riap-related completion routines (clientless version) | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||||||||||