Boxer/World/Reclass.pm

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