blib/lib/App/arraydata.pm

filter: Statementstmt 44.0% 22 / 50 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 55.5% 5 / 9 Podpod 100% 1 / 1 totaltotal 38.3% 28 / 73 CC 9 SCAR 35.6
CC
9
Cov
35%
arraydata
72.0
_list_installed
6.0
__ANON__
2.0
CRAP 35.1
↑ Summary
1 package App::arraydata;
2  
3 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 1 our $DATE = '2021-06-11'; # DATE
5 1 our $DIST = 'App-arraydata'; # DIST
6 1 our $VERSION = '0.003'; # VERSION
7  
8 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use List::Util qw(shuffle);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 our %SPEC;
16  
17 1 our %argspecopt_module = (
18 module => {
19 schema => 'perl::arraydata::modname_with_optional_args*',
20 cmdline_aliases => {m=>{}},
21 pos => 0,
22 },
23 );
24  
25 #our %argspecopt_modules = (
26 # modules => {
27 # schema => 'perl::arraydata::modnames_with_optional_args*',
28 # },
29 #);
30  
31 0 ▶sub _list_installed {
Subroutine _list_installed: not called CC=2 SCAR=17.9
32 0 require Module::List::More;
33 0 my $mods = Module::List::More::list_modules(
34 "ArrayData::",
35 {
36 list_modules => 1,
37 list_pod => 0,
38 recurse => 1,
39 return_path => 1,
40 });
41 0 my @res;
42 0 for my $mod0 (sort keys %$mods) {
43 0 (my $mod = $mod0) =~ s/\AArrayData:://;
44  
45 push @res, {
46 name => $mod,
47 path => $mods->{$mod0}{module_path},
48 0 };
49 }
50 0 \@res;
51 }
52  
53 $SPEC{arraydata} = {
54 v => 1.1,
55 summary => 'Show content of ArrayData modules (plus a few other things)',
56 args => {
57 %argspecopt_module,
58 action => {
59 schema => ['str*', in=>[
60 'list_installed',
61 #'list_cpan',
62 'dump',
63 'pick',
64 #'stat',
65 ]],
66 default => 'dump',
67 cmdline_aliases => {
68 L => {
69 summary=>'List installed ArrayData::*',
70 is_flag => 1,
71 0 ▶ code => sub { my $args=shift; $args->{action} = 'list_installed' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 },
73 #C => {
74 # summary=>'List ArrayData::* on CPAN',
75 # is_flag => 1,
76 # code => sub { my $args=shift; $args->{action} = 'list_cpan' },
77 #},
78 R => {
79 summary=>'Pick random elements from an ArrayData module',
80 is_flag => 1,
81 0 ▶ code => sub { my $args=shift; $args->{action} = 'pick' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 },
83 #S => {
84 # summary=>'Show statistics contained in the ArrayData module',
85 # is_flag => 1,
86 # code => sub { my $args=shift; $args->{action} = 'stat' },
87 #},
88 },
89 },
90 1 detail => {
91 schema => 'bool*',
92 cmdline_aliases => {l=>{}},
93 },
94 num => {
95 summary => 'Number of elements to pick (for -R)',
96 schema => 'posint*',
97 default => 1,
98 cmdline_aliases => {n=>{}},
99 },
100 #lcpan => {
101 # schema => 'bool',
102 # summary => 'Use local CPAN mirror first when available (for -C)',
103 #},
104 },
105 examples => [
106 ],
107 };
108 0 ▶sub arraydata {
Subroutine arraydata: not called CC=8 SCAR=42.8
Pod documented
109 0 my %args = @_;
110 0 ▶ my $action = $args{action} // 'dump';
Condition0%0/2
$args{"action"} // "dump"
l!l
00
MC/DC0%0/1
$args{"action"} // "dump"
$args{"action"}
Truth table0%0/2
A
A= $args{"action"}
Aresult
11
00
111  
112 0 ▶ if ($action eq 'list_installed') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "list_installed") 0 0 0
113 0 my @rows;
114 0 for my $row (@{ _list_installed() }) {
115 0 ▶ push @rows, $args{detail} ? $row : $row->{name};
Branch: 1 branch
BranchTrueFalseTotal
$args{'detail'} ? : 0 0 0
116 }
117 0 return [200, "OK", \@rows];
118 }
119  
120 0 ▶ return [400, "Please specify module"] unless defined $args{module};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"module"} 0 0 0
121  
122 0 require Module::Load::Util;
123 my $obj = Module::Load::Util::instantiate_class_with_optional_args(
124 0 {ns_prefix=>"ArrayData"}, $args{module});
125  
126 0 ▶ if ($action eq 'pick') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "pick") 0 0 0
127 0 return [200, "OK", [$obj->pick_items(n=>$args{num})]];
128 }
129  
130 # dump
131 0 my @items;
132 0 ▶ while ($obj->has_next_item) { push @items, $obj->get_next_item }
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->has_next_item) 0 0 0
133 0 [200, "OK", \@items];
134 }
135  
136 1 1;
137 # ABSTRACT: Show content of ArrayData modules (plus a few other things)
138  
139 __END__
↑ Summary