blib/lib/Acme/CPANModulesUtil/FeatureMatrix.pm

filter: Statementstmt 21.5% 19 / 88 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 15.2% 24 / 157 CC 31 SCAR 67.8
CC
31
Cov
13%
draw_feature_matrix
992.0
BEGIN
1.0
BEGIN
1.0
CRAP 878.7
↑ Summary
1 package Acme::CPANModulesUtil::FeatureMatrix;
2  
3 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 1 our $DATE = '2021-07-29'; # DATE
5 1 our $DIST = 'Acme-CPANModulesUtil-FeatureMatrix'; # DIST
6 1 our $VERSION = '0.005'; # VERSION
7  
8 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use strict 'subs', 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our %SPEC;
13  
14 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 our @EXPORT_OK = qw(draw_feature_matrix);
16  
17 $SPEC{draw_feature_matrix} = {
18 1 v => 1.1,
19 summary => 'Draw features matrix of modules in an Acme::CPANModules::* list',
20 args => {
21 cpanmodule => {
22 summary => 'Name of Acme::CPANModules::* module, without the prefix',
23 schema => 'perl::modname*',
24 req => 1,
25 pos => 0,
26 'x.completion' => ['perl_modname' => {ns_prefix=>'Acme::CPANModules'}],
27 },
28 },
29 };
30 0 ▶sub draw_feature_matrix {
Subroutine draw_feature_matrix: not called CC=31 SCAR=69.0
Pod documented
31 0 require Data::Sah::Resolve;
32 0 require Data::Sah::Util::Type;
33 0 require Markdown::To::POD;
34 0 require Text::Table::Any;
35  
36 0 my %args = @_;
37  
38 0 my $list;
39 my $mod;
40  
41 0 ▶ if ($args{_list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'_list'}) { } 0 0 0
42 0 $list = $args{_list};
43 } else {
44 0 ▶ $mod = $args{cpanmodule} or return [400, "Please specify cpanmodule"];
Branch: 1 branch
BranchTrueFalseTotal
$mod = $args{"cpanmodule"} or return [400, "Please specify cpanmodule"] 0 0 0
45 0 ▶ $mod = "Acme::CPANModules::$mod" unless $mod =~ /\AAcme::CPANModules::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mod =~ /\AAcme::CPANModules::/ 0 0 0
46 0 (my $mod_pm = "$mod.pm") =~ s!::!/!g;
47 0 require $mod_pm;
48  
49 0 $list = ${"$mod\::LIST"};
50 }
51  
52 # collect all features mentioned
53 0 my @features;
54 0 for my $e (@{ $list->{entries} }) {
55 0 ▶ next unless $e->{features};
Branch: 1 branch
BranchTrueFalseTotal
unless $e->{"features"} 0 0 0
56 0 for my $fname (sort keys %{$e->{features}}) {
57 0 ▶ push @features, $fname unless grep {$_ eq $fname} @features;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $fname;} @features 0 0 0
58 }
59 }
60  
61 0 ▶ return [412, "No features mentioned in " . ($mod // "list")]
Branch: 1 branch
BranchTrueFalseTotal
unless @features 0 0 0
Condition0%0/2
$mod // "list"
l!l
00
MC/DC0%0/1
$mod // "list"
$mod
Truth table0%0/2
A
A= $mod
Aresult
11
00
62 unless @features;
63  
64 # generate table and collect notes
65 0 my @notes;
66 my %note_nums; # text => num
67 0 my $note_num = 0;
68 0 my @rows;
69  
70 HEADER_ROW:
71 {
72 0 my @header_row = ("module");
73 0 for my $fname (@features) {
74 0 my $has_note;
75 0 ▶ if ($list->{entry_features} && $list->{entry_features}{$fname} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($list->{"entry_features"} and $list->{"entry_features"}{$fname} and $list->{"entry_features"}{$fname}{"summary"}) 0 0 0
Condition0%0/6
$list->{"entry_features"} and $list->{"entry_features"}{$fname} and $list->{"entry_features"}{$fname}{"summary"}
!ll&&!rl&&r
000
$list->{"entry_features"} and $list->{"entry_features"}{$fname}
!ll&&!rl&&r
000
MC/DC0%0/3
$list->{"entry_features"} and $list->{"entry_features"}{$fname} and $list->{"entry_features"}{$fname}{"summary"}
$list->{"entry_features"} $list->{"entry_features"}{$fname} $list->{"entry_features"}{$fname}{"summary"}
Truth table0%0/4
A and B and C
A= $list->{"entry_features"}B= $list->{"entry_features"}{$fname}C= $list->{"entry_features"}{$fname}{"summary"}
ABCresult
0XX0
10X0
1100
1111
76 $list->{entry_features}{$fname}{summary}) {
77 0 $has_note++;
78 0 $note_num++;
79 0 my $note = "=item $note_num. $fname: " . $list->{entry_features}{$fname}{summary} . "\n\n";
80 0 ▶ if ($list->{entry_features}{$fname}{description}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list->{"entry_features"}{$fname}{"description"}) 0 0 0
81 0 $note .= Markdown::To::POD::markdown_to_pod($list->{entry_features}{$fname}{description}) . "\n\n";
82 }
83 0 push @notes, $note;
84 }
85 0 ▶ push @header_row, "$fname" . ($has_note ? " *$note_num)" : "");
Branch: 1 branch
BranchTrueFalseTotal
$has_note ? : 0 0 0
86 }
87 0 push @rows, \@header_row;
88 }
89  
90 DATA_ROW:
91 {
92 0 for my $e (@{ $list->{entries} }) {
93 0 my @row = ($e->{module});
94 0 for my $fname (@features) {
95 my $rres = Data::Sah::Resolve::resolve_schema(
96 0 ▶ $list->{entry_features}{$fname}{schema} // 'bool'
Condition0%0/2
$list->{"entry_features"}{$fname}{"schema"} // "bool"
l!l
00
MC/DC0%0/1
$list->{"entry_features"}{$fname}{"schema"} // "bool"
$list->{"entry_features"}{$fname}{"schema"}
Truth table0%0/2
A
A= $list->{"entry_features"}{$fname}{"schema"}
Aresult
11
00
97 );
98 0 my $ftype = $rres->{type};
99  
100 0 my $fvalue0;
101 my $fvalue;
102 0 ▶ if (!$e->{features} || !defined($e->{features}{$fname})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $e->{'features'} && defined $e->{'features'}{$fname}) { } 0 0 0
Condition0%0/3
$e->{'features'} && defined $e->{'features'}{$fname}
!ll&&!rl&&r
000
MC/DC0%0/2
$e->{'features'} && defined $e->{'features'}{$fname}
$e->{'features'} defined $e->{'features'}{$fname}
Truth table0%0/3
A && B
A= $e->{'features'}B= defined $e->{'features'}{$fname}
ABresult
0X0
100
111
103 0 $fvalue = "N/A";
104 } else {
105 0 $fvalue0 = $e->{features}{$fname};
106 0 ▶ $fvalue = ref $fvalue0 eq 'HASH' ? $fvalue0->{value} : $fvalue0;
Branch: 1 branch
BranchTrueFalseTotal
ref $fvalue0 eq 'HASH' ? : 0 0 0
107 0 ▶ $fvalue = !defined($fvalue) ? "N/A" :
Branch: 3 branches
BranchTrueFalseTotal
!defined($fvalue) ? : 0 0 0
$ftype eq 'bool' ? : 0 0 0
$fvalue ? : 0 0 0
108 $ftype eq 'bool' ? ($fvalue ? "yes" : "no") : $fvalue;
109 }
110  
111 0 my $has_note;
112 my $this_note_num;
113 0 ▶ if (ref $fvalue0 eq 'HASH' && $fvalue0->{summary}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fvalue0 eq "HASH" and $fvalue0->{"summary"}) 0 0 0
Condition0%0/3
ref $fvalue0 eq "HASH" and $fvalue0->{"summary"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $fvalue0 eq "HASH" and $fvalue0->{"summary"}
ref $fvalue0 eq "HASH" $fvalue0->{"summary"}
Truth table0%0/3
A and B
A= ref $fvalue0 eq "HASH"B= $fvalue0->{"summary"}
ABresult
0X0
100
111
114 0 $has_note++;
115  
116 0 my $note_text = $fvalue0->{summary};
117 0 ▶ if ($fvalue0->{description}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fvalue0->{"description"}) 0 0 0
118 0 $note_text .= Markdown::To::POD::markdown_to_pod($fvalue0->{description}) . "\n\n";
119 }
120  
121 0 ▶ if ($this_note_num = $note_nums{$note_text}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this_note_num = $note_nums{$note_text}) { } 0 0 0
122 # reuse the same text from another note
123 } else {
124 0 $note_num++;
125 0 push @notes, "=item $note_num. $note_text\n\n";
126 0 $note_nums{$note_text} = $this_note_num = $note_num;
127 }
128 }
129 0 ▶ push @row, $fvalue . ($has_note ? " *$this_note_num)" : "");
Branch: 1 branch
BranchTrueFalseTotal
$has_note ? : 0 0 0
130 }
131 0 push @rows, \@row;
132 }
133 }
134  
135 0 my $res = Text::Table::Any::table(
136 rows => \@rows,
137 header_row => 1,
138 0 ); $res =~ s/^/ /gm;
139  
140 0 ▶ if (@notes) {
Branch: 1 branch
BranchTrueFalseTotal
if (@notes) 0 0 0
141 0 $res .= join(
142 "",
143 "\n\nNotes:\n\n=over\n\n", @notes, "=back\n\n",
144 );
145 }
146  
147 0 [200, "OK", $res];
148 }
149  
150 1 1;
151 # ABSTRACT: Draw features matrix of modules in an Acme::CPANModules::* list
152  
153 __END__
↑ Summary