Boxer/World/Reclass.pm

filter: Statementstmt 86.7% 164 / 189 Branchbran 69.5% 32 / 46 Conditioncond 58.0% 18 / 31 MC/DCmcdc 31.2% 5 / 16 Subroutinesub 76.7% 33 / 43 Podpod 0.0% 0 / 3 totaltotal 76.8% 252 / 328 CC 41 SCAR 27.3
CC
41
Cov
80%
map
46.0
_build_parts
9.1
get_part
4.0
CRAP 15.4
« Boxer/Task/Bootstrap.pm ↑ Summary Boxer/CLI/Command/About.pm »
1 package Boxer::World::Reclass;
2  
3 =encoding UTF-8
4  
5 =head1 NAME
6  
7 Boxer::World::Reclass - software as serialized by reclass
8  
9 =cut
10  
11 6 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Role::Commons -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use namespace::autoclean 0.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 ▶use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use List::MoreUtils qw(uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶use Hash::Merge qw(merge);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶use MooX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 extends qw(Boxer::World);
26  
27 6 ▶use Types::Standard qw( ArrayRef InstanceOf Maybe );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 ▶use Boxer::Types qw( ClassDir NodeDir Suite );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 6 ▶use Boxer::Part::Reclass;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 ▶use Boxer::World::Flat;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 6 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 ▶no warnings "experimental::signatures";
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 =head1 VERSION
37  
38 Version v1.4.3
39  
40 =cut
41  
42 6 our $VERSION = "v1.4.3";
43  
44 =head1 DESCRIPTION
45  
46 Outside the box is a world of software.
47  
48 B<Boxer::World::Reclass> is a class describing a collection of software
49 available for installation into (or as) an operating system.
50  
51 =head1 SEE ALSO
52  
53 L<Boxer>.
54  
55 =cut
56  
57 6 has suite => (
58 is => 'ro',
59 isa => Suite,
60 required => 1,
61 );
62  
63 6 has classdir => (
64 is => 'lazy',
65 isa => ClassDir,
66 coerce => 1,
67 required => 1,
68 );
69  
70 1 ▶sub _build_classdir ($self)
Subroutine _build_classdir: called CC=2 SCAR=8.1
71 {
72 1 ▶ if ( $self->data ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->data) 1 0 1
73 1 return $self->data->child('classes');
74 }
75 0 return;
76 }
77  
78 6 has nodedir => (
79 is => 'lazy',
80 isa => NodeDir,
81 coerce => 1,
82 required => 1,
83 );
84  
85 1 ▶sub _build_nodedir ($self)
Subroutine _build_nodedir: called CC=2 SCAR=8.1
86 {
87 1 ▶ if ( $self->data ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->data) 1 0 1
88 1 return $self->data->child('nodes');
89 }
90 0 return;
91 }
92  
93 6 has parts => (
94 is => 'lazy',
95 isa => ArrayRef [ InstanceOf ['Boxer::Part::Reclass'] ],
96 init_arg => undef,
97 );
98  
99 # process only matching types, and skip duplicates is arrays
100 my $merge_spec = {
101 'SCALAR' => {
102 0 ▶ 'SCALAR' => sub { $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
103 0 ▶ 'ARRAY' => sub { die 'bad input data' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 0 ▶ 'HASH' => sub { die 'bad input data' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
105 },
106 'ARRAY' => {
107 0 ▶ 'SCALAR' => sub { die 'bad input data' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 915 ▶ 'ARRAY' => sub { [ uniq @{ $_[0] }, @{ $_[1] } ] },
Subroutine __ANON__: called CC=1 SCAR=0.0
109 0 ▶ 'HASH' => sub { die 'bad input data' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 },
111 'HASH' => {
112 0 ▶ 'SCALAR' => sub { die 'bad input data' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
113 0 ▶ 'ARRAY' => sub { die 'bad input data' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
114 1865 ▶ 'HASH' => sub { Hash::Merge::_merge_hashes( $_[0], $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
115 },
116 6 };
117 6 Hash::Merge::add_behavior_spec($merge_spec);
118  
119 6 ▶sub _build_parts ($self)
Subroutine _build_parts: called CC=9 SCAR=22.1
120 {
121 my $classdata = $self->classdir->visit(
122 1400 ▶ sub ( $path, $state ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
123 1400 ▶ return if $path->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
if $path->is_dir 480 920 1400
124 920 ▶ return unless ( $path->basename =~ /\.yml$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $path->basename =~ /\.yml$/u 0 920 920
125 920 my $yaml = Load( $path->slurp_utf8 );
126 920 my $class = $path->relative( $self->classdir ) =~ tr/\//./r
127 =~ s/\.yml$//r =~ s/\.init$//r;
128 920 $state->{$class} = $yaml;
129 },
130 6 { recurse => 1 },
131 );
132 my $nodedata = $self->nodedir->visit(
133 15 ▶ sub ( $path, $state ) {
Subroutine __ANON__: called CC=3 SCAR=11.3
134 15 ▶ return if $path->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
if $path->is_dir 0 15 15
135 15 ▶ return unless ( $path->basename =~ /\.yml$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $path->basename =~ /\.yml$/u 0 15 15
136 15 my $yaml = Load( $path->slurp_utf8 );
137 15 my $node = $path->basename(qr/\.yml$/);
138 15 $state->{$node} = $yaml;
139 },
140 6 );
141 6 my @parts;
142 6 for ( sort keys %{$nodedata} ) {
143 15 my %params = ();
144 my @classes
145 = $nodedata->{$_}{classes}
146 15 ▶ ? @{ $nodedata->{$_}{classes} }
Branch: 1 branch
BranchTrueFalseTotal
$nodedata->{$_}{'classes'} ? : 10 5 15
147 : ();
148 15 ▶ while ( my $next = shift @classes ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = shift @classes) 1270 15 1285
149 1270 ▶ unless ( $classdata->{$next} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($classdata->{$next}) 0 1270 1270
150 0 $self->_logger->debug(
151 "Ignoring missing class $next for node $_.");
152 0 next;
153 }
154 1270 ▶ if ( $classdata->{$next}{classes} and !$params{_seen}{$next} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($classdata->{$next}{"classes"} and not $params{"_seen"}{$next}) 450 820 1270
Condition100%3/3
$classdata->{$next}{"classes"} and not $params{"_seen"}{$next}
!ll&&!rl&&r
265555450
MC/DC100%2/2
$classdata->{$next}{"classes"} and not $params{"_seen"}{$next}
$classdata->{$next}{"classes"} not $params{"_seen"}{$next}
Truth table100%3/3
A and not(B)
A= $classdata->{$next}{"classes"}B= not $params{"_seen"}{$next}
ABresult
0X0
100
111
155 450 $params{_seen}{$next} = 1;
156 450 unshift @classes, @{ $classdata->{$next}{classes} }, $next;
157 450 next;
158 }
159 725 %params = %{ merge( \%params, $classdata->{$next}{parameters} ) }
160 820 ▶ if $classdata->{$next}{parameters};
Branch: 1 branch
BranchTrueFalseTotal
if $classdata->{$next}{"parameters"} 725 95 820
161 }
162 15 delete $params{_seen};
163 5 %params = %{ merge( \%params, $nodedata->{$_}{parameters} ) }
164 15 ▶ if $nodedata->{$_}{parameters};
Branch: 1 branch
BranchTrueFalseTotal
if $nodedata->{$_}{"parameters"} 5 10 15
165 15 push @parts,
166 Boxer::Part::Reclass->new(
167 id => $_,
168 epoch => $self->suite,
169 %params,
170 );
171 }
172 6 return [@parts];
173 }
174  
175 1 ▶sub list_parts ($self)
Subroutine list_parts: called CC=1 SCAR=0.0
Pod undocumented
176 {
177 1 return map { $_->id } @{ $self->parts };
178 }
179  
180 11 ▶sub get_part ( $self, $id )
Subroutine get_part: called CC=4 SCAR=13.9
Pod undocumented
181 {
182 11 ▶ unless ( @{ $self->parts } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->parts;}) 1 10 11
183 1 $self->_logger->error("No parts exist.");
184 1 return;
185 }
186 10 foreach ( @{ $self->parts } ) {
187 15 ▶ if ( $_->id eq $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->id eq $id) 9 6 15
188 9 return $_;
189 }
190 }
191 1 $self->_logger->error("Part \"$id\" does not exist.");
192 1 return;
193 }
194  
195 6 my $pos = 1;
196 6 my @section_order = qw(
197 Administration
198 Service
199 Console
200 Desktop
201 Language
202 Framework
203 Task
204 Hardware
205 );
206 6 my %section_order = map { $_ => $pos++ } @section_order;
207  
208 6 ▶sub map ( $self, $node_id, $nonfree )
Subroutine map: called CC=24 SCAR=38.3
Pod undocumented
209 {
210 6 my $node = $self->get_part($node_id);
211 6 my %desc;
212  
213 my @section_keys = sort {
214 122 ▶ ( $section_order{$a} // 1000 ) <=> ( $section_order{$b} // 1000 )
Condition42%3/7
($section_order{$a} // 1000) <=> ($section_order{$b} // 1000) || $a cmp $b
l!l&&r!l&&!r
01220
$section_order{$a} // 1000
l!l
0122
$section_order{$b} // 1000
l!l
0122
MC/DC0%0/2
($section_order{$a} // 1000) <=> ($section_order{$b} // 1000) || $a cmp $b
$section_order{$a} $a cmp $b
MC/DC0%0/1
$section_order{$b} // 1000
$section_order{$b}
Truth table33%1/3
A || B
A= $section_order{$a}B= $a cmp $b
ABresult
1X1
011
000
Truth table50%1/2
A
A= $section_order{$b}
Aresult
11
00
215 || $a cmp $b
216 6 } keys %{ $node->{doc} };
217  
218 6 foreach my $key (@section_keys) {
219 55 ▶ my $headline = $node->{doc}{$key}{headline}[0] || $key;
Condition66%2/3
$node->{'doc'}{$key}{'headline'}[0] || $key
l!l&&r!l&&!r
5320
MC/DC0%0/2
$node->{'doc'}{$key}{'headline'}[0] || $key
$node->{'doc'}{$key}{'headline'}[0] $key
Truth table66%2/3
A || B
A= $node->{'doc'}{$key}{'headline'}[0]B= $key
ABresult
1X1
011
000
220 55 ▶ if (( $node->{pkg} and $node->{doc}{$key}{pkg} )
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"pkg"} and $node->{"doc"}{$key}{"pkg"} or $nonfree and $node->{"pkg-nonfree"} and $node->{"doc"}{$key}{"pkg-nonfree"}) 54 1 55
Condition50%6/12
$node->{"pkg"} and $node->{"doc"}{$key}{"pkg"} or $nonfree and $node->{"pkg-nonfree"} and $node->{"doc"}{$key}{"pkg-nonfree"}
l!l&&r!l&&!r
5401
$node->{"pkg"} and $node->{"doc"}{$key}{"pkg"}
!ll&&!rl&&r
0154
$nonfree and $node->{"pkg-nonfree"} and $node->{"doc"}{$key}{"pkg-nonfree"}
!ll&&!rl&&r
100
$nonfree and $node->{"pkg-nonfree"}
!ll&&!rl&&r
100
MC/DC20%1/5
$node->{"pkg"} and $node->{"doc"}{$key}{"pkg"} or $nonfree and $node->{"pkg-nonfree"} and $node->{"doc"}{$key}{"pkg-nonfree"}
$node->{"pkg"} $node->{"doc"}{$key}{"pkg"} $nonfree $node->{"pkg-nonfree"} $node->{"doc"}{$key}{"pkg-nonfree"}
Truth table22%2/9
A and B or C and D and E
A= $node->{"pkg"}B= $node->{"doc"}{$key}{"pkg"}C= $nonfreeD= $node->{"pkg-nonfree"}E= $node->{"doc"}{$key}{"pkg-nonfree"}
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
221 or ( $nonfree
222 and $node->{'pkg-nonfree'}
223 and $node->{doc}{$key}{'pkg-nonfree'} )
224 )
225 {
226 54 push @{ $desc{pkg} }, "# $headline";
227 54 ▶ if ( $node->{pkg} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"pkg"}) 54 0 54
228 54 foreach ( @{ $node->{doc}{$key}{pkg} } ) {
229 187 push @{ $desc{pkg} }, "# * $_";
230 }
231 }
232 54 ▶ if ( $nonfree and $node->{'pkg-nonfree'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nonfree and $node->{"pkg-nonfree"}) 0 54 54
Condition33%1/3
$nonfree and $node->{"pkg-nonfree"}
!ll&&!rl&&r
5400
MC/DC0%0/2
$nonfree and $node->{"pkg-nonfree"}
$nonfree $node->{"pkg-nonfree"}
Truth table33%1/3
A and B
A= $nonfreeB= $node->{"pkg-nonfree"}
ABresult
0X0
100
111
233 0 foreach ( @{ $node->{doc}{$key}{'pkg-nonfree'} } ) {
234 0 push @{ $desc{pkg} }, "# * [non-free] $_";
235 }
236 }
237 }
238 55 ▶ if ( $node->{tweak} and $node->{doc}{$key}{tweak} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"tweak"} and $node->{"doc"}{$key}{"tweak"}) 2 53 55
Condition100%3/3
$node->{"tweak"} and $node->{"doc"}{$key}{"tweak"}
!ll&&!rl&&r
4582
MC/DC100%2/2
$node->{"tweak"} and $node->{"doc"}{$key}{"tweak"}
$node->{"tweak"} $node->{"doc"}{$key}{"tweak"}
Truth table100%3/3
A and B
A= $node->{"tweak"}B= $node->{"doc"}{$key}{"tweak"}
ABresult
0X0
100
111
239 2 push @{ $desc{tweak} }, "# $headline";
240 2 foreach ( @{ $node->{doc}{$key}{tweak} } ) {
241 4 push @{ $desc{tweak} }, "# * $_";
242 }
243 }
244 }
245 my $pkgdesc
246 = defined( $desc{pkg} )
247 6 ▶ ? join( "\n", @{ $desc{pkg} } )
Branch: 1 branch
BranchTrueFalseTotal
defined $desc{'pkg'} ? : 6 0 6
248 : '';
249 my $tweakdesc
250 = defined( $desc{tweak} )
251 6 ▶ ? join( "\n", @{ $desc{tweak} } )
Branch: 1 branch
BranchTrueFalseTotal
defined $desc{'tweak'} ? : 1 5 6
252 : '';
253 6 ▶ my @pkg = try { @{ $node->{pkg} } }
Subroutine __ANON__: called CC=1 SCAR=0.0
254 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
255 0 $self->_logger->warning('No packages resolved');
256 0 return ();
257 6 };
258 6 ▶ my @pkgauto = try { @{ $node->{'pkg-auto'} } }
Subroutine __ANON__: called CC=1 SCAR=0.0
259 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
260 0 $self->_logger->warning('No package auto-markings resolved');
261 0 return ();
262 6 };
263 6 ▶ my @pkgavoid = try { @{ $node->{'pkg-avoid'} } }
Subroutine __ANON__: called CC=1 SCAR=0.0
264 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
265 0 $self->_logger->warning('No package avoidance resolved');
266 0 return ();
267 6 };
268 6 ▶ my @tweak = try { @{ $node->{tweak} } }
Subroutine __ANON__: called CC=1 SCAR=0.0
269 5 ▶ catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
270 5 $self->_logger->warning('No tweaks resolved');
271 5 return ();
272 6 };
273 6 ▶ if ($nonfree) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nonfree) 0 6 6
274 0 ▶ push @pkg, @{ $node->{'pkg-nonfree'} } if ( $node->{'pkg-nonfree'} );
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"pkg-nonfree"} 0 0 0
275 0 push @pkgauto, @{ $node->{'pkg-nonfree-auto'} }
276 0 ▶ if ( $node->{'pkg-nonfree-auto'} );
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"pkg-nonfree-auto"} 0 0 0
277 }
278 6 chomp(@tweak);
279  
280 6 return Boxer::World::Flat->new(
281 node => $node_id,
282 epoch => $node->epoch,
283 pkgs => \@pkg,
284 pkgs_auto => \@pkgauto,
285 pkgs_avoid => \@pkgavoid,
286 tweaks => \@tweak,
287 pkgdesc => $pkgdesc,
288 tweakdesc => $tweakdesc,
289 nonfree => $nonfree, # TODO: unset if none resolved
290 );
291 }
292  
293 =head1 AUTHOR
294  
295 Jonas Smedegaard C<< <dr@jones.dk> >>.
296  
297 =cut
298  
299 6 our $AUTHORITY = 'cpan:JONASS';
300  
301 =head1 COPYRIGHT AND LICENCE
302  
303 Copyright © 2013-2016 Jonas Smedegaard
304  
305 This is free software; you can redistribute it and/or modify it under
306 the same terms as the Perl 5 programming language system itself.
307  
308 =head1 DISCLAIMER OF WARRANTIES
309  
310 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
311 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
312 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
313  
314 =cut
315  
316 6 1;
« Boxer/Task/Bootstrap.pm ↑ Summary Boxer/CLI/Command/About.pm »