blib/lib/App/hashdata.pm

filter: Statementstmt 46.8% 22 / 47 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 62.5% 5 / 8 Podpod 100% 1 / 1 totaltotal 41.7% 28 / 67 CC 8 SCAR 33.1
CC
8
Cov
39%
hashdata
56.0
_list_installed
6.0
__ANON__
2.0
CRAP 27.4
↑ Summary
1 package App::hashdata;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use List::Util qw(shuffle);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11 1 our $DATE = '2024-01-15'; # DATE
12 1 our $DIST = 'App-hashdata'; # DIST
13 1 our $VERSION = '0.001'; # VERSION
14  
15 1 our %SPEC;
16  
17 1 our %argspecopt_module = (
18 module => {
19 schema => 'perl::hashdata::modname_with_optional_args*',
20 cmdline_aliases => {m=>{}},
21 pos => 0,
22 },
23 );
24  
25 #our %argspecopt_modules = (
26 # modules => {
27 # schema => 'perl::hashdata::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 "HashData::",
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/\AHashData:://;
44  
45 push @res, {
46 name => $mod,
47 path => $mods->{$mod0}{module_path},
48 0 };
49 }
50 0 \@res;
51 }
52  
53 $SPEC{hashdata} = {
54 v => 1.1,
55 summary => 'Show content of HashData 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 #'get_value',
65 #'stat',
66 ]],
67 default => 'dump',
68 cmdline_aliases => {
69 L => {
70 summary=>'List installed HashData::*',
71 is_flag => 1,
72 0 ▶ code => sub { my $args=shift; $args->{action} = 'list_installed' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 },
74 #C => {
75 # summary=>'List HashData::* on CPAN',
76 # is_flag => 1,
77 # code => sub { my $args=shift; $args->{action} = 'list_cpan' },
78 #},
79 #R => {
80 # summary=>'Pick random keys from a HashData module',
81 # is_flag => 1,
82 # code => sub { my $args=shift; $args->{action} = 'pick' },
83 #},
84 #S => {
85 # summary=>'Show statistics contained in the HashData module',
86 # is_flag => 1,
87 # code => sub { my $args=shift; $args->{action} = 'stat' },
88 #},
89 },
90 },
91 1 detail => {
92 schema => 'bool*',
93 cmdline_aliases => {l=>{}},
94 },
95 num => {
96 summary => 'Number of keys to pick (for -R)',
97 schema => 'posint*',
98 default => 1,
99 cmdline_aliases => {n=>{}},
100 },
101 key => {
102 summary => 'Key',
103 schema => 'str*',
104 },
105 #lcpan => {
106 # schema => 'bool',
107 # summary => 'Use local CPAN mirror first when available (for -C)',
108 #},
109 },
110 examples => [
111 ],
112 };
113 0 ▶sub hashdata {
Subroutine hashdata: not called CC=7 SCAR=40.3
Pod documented
114 0 my %args = @_;
115 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
116  
117 0 ▶ if ($action eq 'list_installed') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "list_installed") 0 0 0
118 0 my @rows;
119 0 for my $row (@{ _list_installed() }) {
120 0 ▶ push @rows, $args{detail} ? $row : $row->{name};
Branch: 1 branch
BranchTrueFalseTotal
$args{'detail'} ? : 0 0 0
121 }
122 0 return [200, "OK", \@rows];
123 }
124  
125 0 ▶ return [400, "Please specify module"] unless defined $args{module};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"module"} 0 0 0
126  
127 0 require Module::Load::Util;
128 my $obj = Module::Load::Util::instantiate_class_with_optional_args(
129 0 {ns_prefix=>"HashData"}, $args{module});
130  
131 #if ($action eq 'pick') {
132 # return [200, "OK", [$obj->pick_items(n=>$args{num})]];
133 #}
134  
135 # dump
136 0 my %hash;
137 0 ▶ while ($obj->has_next_item) { my $item = $obj->get_next_item; $hash{ $item->[0] } = $item->[1] }
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->has_next_item) 0 0 0
138 0 [200, "OK", \%hash];
139 }
140  
141 1 1;
142 # ABSTRACT: Show content of HashData modules (plus a few other things)
143  
144 __END__
↑ Summary