blib/lib/Complete/Acme/MetaSyntactic.pm

filter: Statementstmt 41.1% 28 / 68 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 100% 3 / 3 totaltotal 39.7% 37 / 93 CC 8 SCAR 24.4
CC
8
Cov
35%
complete_meta_theme_and_category
30.0
complete_meta_category
8.0
complete_meta_theme
6.0
CRAP 11.4
↑ Summary
1 package Complete::Acme::MetaSyntactic;
2  
3 1 our $DATE = '2019-07-05'; # 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::Util 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(
17 complete_meta_category
18 complete_meta_theme
19 complete_meta_theme_and_category
20 );
21  
22 #TODO: complete_meta_name
23  
24 1 $SPEC{':package'} = {
25 v => 1.1,
26 summary => 'Completion routines for Acme::MetaSyntactic',
27 };
28  
29 $SPEC{complete_meta_theme} = {
30 1 v => 1.1,
31 summary => 'Complete from list of available themes',
32 args => {
33 %arg_word,
34 },
35 result_naked => 1,
36 };
37 0 ▶sub complete_meta_theme {
Subroutine complete_meta_theme: not called CC=2 SCAR=17.9
Pod documented
38 0 require Complete::Util;
39 0 require PERLANCAR::Module::List;
40  
41 0 my %args = @_;
42  
43 0 my $res = PERLANCAR::Module::List::list_modules(
44 "Acme::MetaSyntactic::", {list_modules=>1});
45 0 my @ary = sort keys %$res;
46 0 for (@ary) {
47 0 s/\AAcme::MetaSyntactic:://;
48 }
49 0 @ary = grep { !/^[A-Z]/ } @ary;
50 Complete::Util::complete_array_elem(
51 word => $args{word},
52 0 array => \@ary,
53 );
54 }
55  
56 $SPEC{complete_meta_category} = {
57 v => 1.1,
58 summary => 'Complete from list of categories for a particular theme',
59 args => {
60 %arg_word,
61 theme => {
62 schema => ['str*', match => qr/\A\w+\z/],
63 req => 1,
64 0 ▶ completion => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 0 complete_meta_theme(@_);
66 },
67 },
68 },
69 1 result_naked => 1,
70 };
71 0 ▶sub complete_meta_category {
Subroutine complete_meta_category: not called CC=3 SCAR=20.8
Pod documented
72 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
73 0 require Complete::Util;
74  
75 0 my %args = @_;
76  
77 0 ▶ my $theme = $args{theme} or return [];
Branch: 1 branch
BranchTrueFalseTotal
my $theme = $args{"theme"} or return [] 0 0 0
78 0 my $pkg = "Acme::MetaSyntactic::$theme";
79 0 (my $pkg_pm = "$pkg.pm") =~ s!::!/!g;
80 0 ▶ eval { require $pkg_pm; 1 } or return [];
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $pkg_pm; 1 } } or return [] 0 0 0
81 0 my $meta = $pkg->new;
82 Complete::Util::complete_array_elem(
83 word => $args{word},
84 0 array => [$pkg->categories],
85 );
86 }
87  
88 $SPEC{complete_meta_theme_and_category} = {
89 1 v => 1.1,
90 summary => 'Complete from list of available themes (or "theme/category")',
91 description => <<'_',
92  
93 This routine can complete from a list of themes, like `complete_meta_theme()`.
94 Additionally, if the word is in the form of "word/" or "word/rest" then the
95 "rest" will be completed from list of categories of theme "word".
96  
97 _
98 args => {
99 %arg_word,
100 },
101 result_naked => 1,
102 };
103 0 ▶sub complete_meta_theme_and_category {
Subroutine complete_meta_theme_and_category: not called CC=5 SCAR=34.0
Pod documented
104 0 require Complete::Util;
105 0 require PERLANCAR::Module::List;
106  
107 0 my %args = @_;
108 0 my $word = $args{word};
109  
110 0 ▶ if ($word =~ /\A(\w*)\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($word =~ /\A(\w*)\z/) { } 0 0 0
elsif ($word =~ m[\A(\w+)/((?:/\w+)*\w*)\z]) { } 0 0 0
111 0 return complete_meta_theme(word => $word);
112 } elsif ($word =~ m!\A(\w+)/((?:/\w+)*\w*)\z!) {
113 0 my ($theme, $cat) = ($1, $2);
114 0 my $themes = complete_meta_theme(word => $theme);
115 0 ▶ return [] unless @$themes == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$themes == 1 0 0 0
116 0 my $pkg = "Acme::MetaSyntactic::$themes->[0]";
117 0 (my $pkg_pm = "$pkg.pm") =~ s!::!/!g;
118 0 ▶ return [] unless eval { require $pkg_pm; 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require $pkg_pm; 1 } } 0 0 0
119 0 my $meta = $pkg->new;
120 0 my $cats = Complete::Util::complete_array_elem(
121 word => $cat,
122 array => [$meta->categories],
123 );
124 0 return [map {"$themes->[0]/$_"} @$cats];
125 } else {
126 0 return [];
127 }
128 }
129  
130 1 1;
131 # ABSTRACT: Completion routines for Acme::MetaSyntactic
132  
133 __END__
↑ Summary