lib/Gentoo/Overlay/Group.pm

filter: Statementstmt 88.1% 112 / 127 Branchbran 87.5% 14 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 87.1% 27 / 31 Podpod 100% 2 / 2 totaltotal 87.2% 158 / 181 CC 11 SCAR 6.3
CC
11
Cov
88%
add_overlay
4.0
_type_print
3.6
_add_overlay_object
3.0
CRAP 1.9
« blib/lib/Gentoo/Overlay/Group.pm ↑ Summary
1 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Gentoo::Overlay::Group;
6  
7 3 our $VERSION = '1.000000';
8  
9 # ABSTRACT: A collection of Gentoo::Overlay objects.
10  
11 3 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 3 ▶use Moo qw( has );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use MooX::HandlesVia;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use MooseX::Has::Sugar qw( ro lazy );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Types::Standard qw( HashRef Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Types::Path::Tiny qw( Dir );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 ▶use Gentoo::Overlay 2.001001;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Gentoo::Overlay::Types qw( Gentoo__Overlay_Overlay );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Gentoo::Overlay::Exceptions qw( exception );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53 has '_overlays' => (
54 ro, lazy,
55 isa => HashRef [Gentoo__Overlay_Overlay],
56 8 ▶ default => sub { return {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
57 3 handles_via => 'Hash',
58 handles => {
59 _has_overlay => exists =>,
60 overlay_names => keys =>,
61 overlays => elements =>,
62 get_overlay => get =>,
63 _set_overlay => set =>,
64 },
65 );
66  
67 3 my $_str = Str();
68  
69  
70  
71  
72  
73  
74  
75  
76  
77 sub _type_print {
78 return
79 1 ▶ ref $_ ? ref $_
Subroutine _type_print: called CC=3 SCAR=12.7
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 0 1 1
defined $_ ? : 0 1 1
80 : defined $_ ? 'scalar<' . $_ . '>'
81 : 'scalar=undef';
82  
83 }
84  
85  
86  
87  
88  
89  
90  
91  
92  
93 sub add_overlay {
94 15 ▶ my ( $self, @args ) = @_;
Subroutine add_overlay: called CC=4 SCAR=13.9
Pod documented
95 15 ▶ if ( 1 == @args and blessed $args[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 == @args and builtin::blessed($args[0])) 7 8 15
Condition66%2/3
1 == @args and builtin::blessed($args[0])
!ll&&!rl&&r
087
MC/DC50%1/2
1 == @args and builtin::blessed($args[0])
1 == @args builtin::blessed($args[0])
Truth table66%2/3
A and B
A= 1 == @argsB= builtin::blessed($args[0])
ABresult
0X0
100
111
96 7 goto $self->can('_add_overlay_object');
97 }
98 8 ▶ if ( $_str->check( $args[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_str->check($args[0])) 7 1 8
99 7 goto $self->can('_add_overlay_string_path');
100 }
101 return exception(
102 ident => 'bad overlay type',
103 message => <<'EOF',
104 Unrecognised parameter types passed to add_overlay.
105 Expected: \n%{signatures}s.
106 Got: [%{type}s]}.
107 EOF
108 payload => {
109 3 signatures => ( join q{}, map { qq{ \$group->add_overlay( $_ );\n} } qw( Str Path::Tiny Gentoo::Overlay ) ),
110 1 type => ( join q{,}, map { _type_print } @args ),
111 },
112 );
113 }
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124 sub iterate {
125 3 ▶ my ( $self, $what, $callback ) = @_; ## no critic (Variables::ProhibitUnusedVarsStricter)
Subroutine iterate: called CC=2 SCAR=6.9
Pod documented
126 3 my %method_map = (
127 ebuilds => _iterate_ebuilds =>,
128 categories => _iterate_categories =>,
129 packages => _iterate_packages =>,
130 overlays => _iterate_overlays =>,
131 );
132 3 ▶ if ( exists $method_map{$what} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $method_map{$what}) 2 1 3
133 2 goto $self->can( $method_map{$what} );
134 }
135 1 return exception(
136 ident => 'bad iteration method',
137 message => 'The iteration method %{what_method}s is not a known way to iterate.',
138 payload => { what_method => $what, },
139 );
140 }
141  
142  
143  
144  
145  
146  
147  
148 sub _iterate_ebuilds {
149 0 ▶ my ( $self, undef, $callback ) = @_;
Subroutine _iterate_ebuilds: not called CC=1 SCAR=6.9
150 my $real_callback = sub {
151 0 ▶ my (%package_config) = %{ $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
152 my $inner_callback = sub {
153 0 ▶ my (%ebuild_config) = %{ $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
154 0 $self->$callback( { ( %package_config, %ebuild_config ) } );
155 0 };
156 0 $package_config{package}->_iterate_ebuilds( ebuilds => $inner_callback );
157 0 };
158 0 $self->_iterate_packages( packages => $real_callback );
159 0 return;
160 }
161  
162  
163  
164  
165  
166  
167  
168 # categories = { /overlays/categories
169  
170 sub _iterate_categories {
171 2 ▶ my ( $self, undef, $callback ) = @_;
Subroutine _iterate_categories: called CC=1 SCAR=0.0
172 my $real_callback = sub {
173 4 ▶ my (%overlay_config) = %{ $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.0
174 my $inner_callback = sub {
175 8 ▶ my (%category_config) = %{ $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.0
176 8 $self->$callback( { ( %overlay_config, %category_config ) } );
177 4 };
178 4 $overlay_config{overlay}->_iterate_categories( categories => $inner_callback );
179 2 };
180 2 $self->_iterate_overlays( overlays => $real_callback );
181 2 return;
182 }
183  
184  
185  
186  
187  
188  
189  
190 sub _iterate_packages {
191 1 ▶ my ( $self, undef, $callback ) = @_;
Subroutine _iterate_packages: called CC=1 SCAR=0.2
192 my $real_callback = sub {
193 4 ▶ my (%category_config) = %{ $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.8
194 my $inner_callback = sub {
195 0 ▶ my (%package_config) = %{ $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
196 0 $self->$callback( { ( %category_config, %package_config ) } );
197 4 };
198 4 $category_config{category}->_iterate_packages( packages => $inner_callback );
199 1 };
200 1 $self->_iterate_categories( categories => $real_callback );
201 1 return;
202 }
203  
204  
205  
206  
207  
208  
209  
210 # overlays = { /overlays }
211 sub _iterate_overlays {
212 2 ▶ my ( $self, undef, $callback ) = @_;
Subroutine _iterate_overlays: called CC=2 SCAR=6.9
213 2 my %overlays = $self->overlays;
214 2 my $num_overlays = scalar keys %overlays;
215 2 my $last_overlay = $num_overlays - 1;
216 2 my $offset = 0;
217 2 for my $overlay_name ( sort keys %overlays ) {
218 4 local $_ = $overlays{$overlay_name};
219 $self->$callback(
220 {
221 overlay_name => $overlay_name,
222 4 overlay => $overlays{$overlay_name},
223 num_overlays => $num_overlays,
224 last_overlay => $last_overlay,
225 overlay_num => $offset,
226 }
227 );
228 4 $offset++;
229 }
230 2 return;
231 }
232  
233 3 my $_gentoo_overlay = Gentoo__Overlay_Overlay();
234 3 my $_path_class_dir = Dir();
235  
236 # This would be better in M:M:TypeCoercion
237  
238  
239  
240  
241  
242  
243  
244 sub _add_overlay_object {
245 7 ▶ my ( $self, $overlay, @rest ) = @_;
Subroutine _add_overlay_object: called CC=3 SCAR=11.0
246  
247 7 ▶ if ( $_gentoo_overlay->check($overlay) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_gentoo_overlay->check($overlay)) 5 2 7
248 5 goto $self->can('_add_overlay_gentoo_object');
249 }
250 2 ▶ if ( $_path_class_dir->check($overlay) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_path_class_dir->check($overlay)) 1 1 2
251 1 goto $self->can('_add_overlay_path_class');
252 }
253 return exception(
254 ident => 'bad overlay object type',
255 message => <<'EOF',
256 Unrecognised parameter object types passed to add_overlay.
257 Expected: \n%{signatures}s.
258 Got: [%{type}s]}.
259 EOF
260 payload => {
261 3 signatures => ( join q{}, map { qq{ \$group->add_overlay( $_ );\n} } qw( Str Path::Tiny Gentoo::Overlay ) ),
262 1 type => ( join q{,}, blessed $overlay, map { _type_print } @rest ),
263 },
264 );
265 }
266  
267  
268  
269  
270  
271  
272  
273 sub _add_overlay_gentoo_object {
274 13 ▶ my ( $self, $overlay, ) = @_;
Subroutine _add_overlay_gentoo_object: called CC=2 SCAR=6.9
275 13 $_gentoo_overlay->assert_valid($overlay);
276 13 ▶ if ( $self->_has_overlay( $overlay->name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_overlay($overlay->name)) 1 12 13
277 1 return exception(
278 ident => 'overlay exists',
279 message => 'The overlay named %{overlay_name}s is already added to this group.',
280 payload => { overlay_name => $overlay->name },
281 );
282 }
283 12 $self->_set_overlay( $overlay->name, $overlay );
284 12 return;
285 }
286  
287  
288  
289  
290  
291  
292  
293 sub _add_overlay_path_class { ## no critic ( RequireArgUnpacking )
294 8 ▶ my ( $self, $path, ) = @_;
Subroutine _add_overlay_path_class: called CC=1 SCAR=0.0
295 8 $_path_class_dir->assert_valid($path);
296 8 my $go = Gentoo::Overlay->new( path => $path, );
297 8 @_ = ( $self, $go );
298 8 goto $self->can('_add_overlay_gentoo_object');
299 }
300  
301  
302  
303  
304  
305  
306  
307 sub _add_overlay_string_path { ## no critic ( RequireArgUnpacking )
308 7 ▶ my ( $self, $path_str, ) = @_;
Subroutine _add_overlay_string_path: called CC=1 SCAR=0.0
309 7 $_str->assert_valid($path_str);
310 7 my $path = $_path_class_dir->coerce($path_str);
311 7 @_ = ( $self, $path );
312 7 goto $self->can('_add_overlay_path_class');
313 }
314  
315 3 1;
316  
317 __END__
318  
319 =pod
320  
321 =encoding UTF-8
322  
323 =head1 NAME
324  
325 Gentoo::Overlay::Group - A collection of Gentoo::Overlay objects.
326  
327 =head1 VERSION
328  
329 version 1.000000
330  
331 =head1 SYNOPSIS
332  
333 This is a wrapper around L<< C<Gentoo::Overlay>|Gentoo::Overlay >> that makes it easier to perform actions on a group of overlays.
334  
335 my $group = Gentoo::Overlay::Group->new();
336 $group->add_overlay('/usr/portage');
337 $group->add_overlay('/usr/local/portage/');
338 $group->iterate( packages => sub {
339 my ( $self, $context ) = @_;
340 # Traverse-Order:
341 # ::gentoo
342 # category_a
343 # package_a
344 # package_b
345 # category_b
346 # package_a
347 # package_b
348 # ::hentoo
349 # category_a
350 # package_a
351 # package_b
352 # category_b
353 # package_a
354 # package_b
355 });
356  
357 =head1 METHODS
358  
359 =head2 add_overlay
360  
361 $object->add_overlay( '/path/to/overlay' );
362 $object->add_overlay( Path::Tiny::path( '/path/to/overlay' ) );
363 $object->add_overlay( Gentoo::Overlay->new( path => '/path/to/overlay' ) );
364  
365 =head2 iterate
366  
367 $object->iterate( ebuilds => sub {
368  
369  
370 });
371  
372 =head1 ATTRIBUTE ACCESSORS
373  
374 =head2 overlay_names
375  
376 my @names = $object->overlay_names
377  
378 =head2 overlays
379  
380 my @overlays = $object->overlays;
381  
382 =head2 get_overlay
383  
384 my $overlay = $object->get_overlay('gentoo');
385  
386 =head1 PRIVATE ATTRIBUTES
387  
388 =head2 _overlays
389  
390 isa => HashRef[ Gentoo__Overlay_Overlay ], ro, lazy
391  
392 =head1 PRIVATE ATTRIBUTE ACCESSORS
393  
394 =head2 _has_overlay
395  
396 if( $object->_has_overlay('gentoo') ){
397 Carp::croak('waah');
398 }
399  
400 =head2 _set_overlay
401  
402 $object->_set_overlay( 'gentoo' => $overlay_object );
403  
404 =head1 PRIVATE FUNCTIONS
405  
406 =head2 _type_print
407  
408 Lightweight flat dumper optimized for displaying user parameters in a format similar to a method signature.
409  
410 printf '[%s]', join q{,} , map { _type_print } @array
411  
412 =head1 PRIVATE METHODS
413  
414 =head2 _iterate_ebuilds
415  
416 $object->_iterate_ebuilds( ignored => sub { } );
417  
418 =head2 _iterate_categories
419  
420 $object->_iterate_categories( ignored => sub { } );
421  
422 =head2 _iterate_packages
423  
424 $object->_iterate_packages( ignored => sub { } );
425  
426 =head2 _iterate_overlays
427  
428 $object->_iterate_overlays( ignored => sub { } );
429  
430 =head2 _add_overlay_object
431  
432 $groupobject->_add_overlay_object( $object );
433  
434 =head2 _add_overlay_gentoo_object
435  
436 $groupobject->_add_overlay_gentoo_object( $gentoo_object );
437  
438 =head2 _add_overlay_path_class
439  
440 $groupobject->_add_overlay_path_class( $path_class_object );
441  
442 =head2 _add_overlay_string_path
443  
444 $groupobject->_add_overlay_string_path( $path_string );
445  
446 =head1 AUTHOR
447  
448 Kent Fredric <kentnl@cpan.org>
449  
450 =head1 COPYRIGHT AND LICENSE
451  
452 This software is copyright (c) 2014 by Kent Fredric <kentnl@cpan.org>.
453  
454 This is free software; you can redistribute it and/or modify it under
455 the same terms as the Perl 5 programming language system itself.
456  
457 =cut
« blib/lib/Gentoo/Overlay/Group.pm ↑ Summary