blib/lib/Complete/Riap/Clientless.pm

filter: Statementstmt 33.7% 26 / 77 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 66.6% 6 / 9 Podpod 100% 1 / 1 totaltotal 24.8% 33 / 133 CC 23 SCAR 50.7
CC
23
Cov
22%
__ANON__
268.4
complete_riap_url
51.5
BEGIN
1.0
CRAP 159.0
↑ Summary
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
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
57 0 ▶ $word = "/$word" unless $word =~ m!\A/!;
Branch: 1 branch
BranchTrueFalseTotal
unless $word =~ m[\A/] 0 0 0
58 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
59  
60 0 my $starting_path;
61 0 my $result_prefix = '';
62 0 ▶ if ($word =~ s!\A/!!) {
Branch: 2 branches
BranchTrueFalseTotal
if ($word =~ s[\A/][]) { } 0 0 0
elsif ($word =~ s[\Apl:/][/]) { } 0 0 0
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
BranchTrueFalseTotal
if ref $inc 0 0 0
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
BranchTrueFalseTotal
if (opendir my $dh, $dir) 0 0 0
86 0 for my $e (readdir $dh) {
87 0 ▶ next if $e eq '.' || $e eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $e eq "." or $e eq ".." 0 0 0
Condition0%0/3
$e eq "." or $e eq ".."
l!l&&r!l&&!r
000
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 ".."
ABresult
1X1
011
000
88 0 ▶ next unless $e =~ /\A\w+(\.\w+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\A\w+(\.\w+)?\z/ 0 0 0
89 0 my $is_dir = (-d "$dir/$e");
90 0 ▶ if ($is_dir) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_dir) { } 0 0 0
elsif ($e =~ /(.+)\.pm\z/) { } 0 0 0
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
BranchTrueFalseTotal
unless -f $file 0 0 0
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
BranchTrueFalseTotal
eval { do { require $mod_pm; 1 } } or last 0 0 0
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
BranchTrueFalseTotal
if ($k =~ /\A[$@%]/) { } 0 0 0
elsif ($k =~ /\A\w+\z/) { } 0 0 0
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
BranchTrueFalseTotal
if $args{"type"} and $args{"type"} ne $type 0 0 0
Condition0%0/3
$args{"type"} and $args{"type"} ne $type
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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__
↑ Summary