lib/Gentoo/Overlay/Package.pm

filter: Statementstmt 91.5% 87 / 95 Branchbran 54.5% 12 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.3% 21 / 23 Podpod 100% 4 / 4 totaltotal 86.1% 124 / 144 CC 13 SCAR 10.8
CC
13
Cov
85%
_build__ebuilds
6.2
iterate
6.0
exists
5.2
CRAP 2.9
« blib/lib/Gentoo/Overlay/Exceptions.pm ↑ Summary lib/Gentoo/Overlay/Ebuild.pm »
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::Package;
6  
7 3 our $VERSION = '2.001001';
8  
9 # ABSTRACT: Class for Package's in Gentoo Overlays
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 required lazy lazy_build);
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( Path );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use MooX::ClassAttribute qw( class_has );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Gentoo::Overlay::Types qw( Gentoo__Overlay_PackageName Gentoo__Overlay_Category );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use Gentoo::Overlay::Types qw( Gentoo__Overlay_RepositoryName Gentoo__Overlay_Category Gentoo__Overlay_Ebuild );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Gentoo::Overlay::Exceptions qw( exception);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
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  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68 3 has name => ( isa => Gentoo__Overlay_PackageName, required, ro, );
69 3 has category => ( isa => Gentoo__Overlay_Category, required, ro, handles => [qw( overlay )], );
70 has path => (
71 isa => Path,
72 ro,
73 lazy,
74 default => sub {
75 5 ▶ my ($self) = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
76 5 return $self->overlay->default_path( 'package', $self->category->name, $self->name );
77 },
78 3 );
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107 class_has _scan_blacklist => (
108 isa => HashRef [Str],
109 ro,
110 lazy,
111 default => sub {
112 2 ▶ return { map { $_ => 1 } qw( . .. metadata.xml ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
113 },
114 3 );
115  
116 sub _scan_blacklisted {
117 5 ▶ my ( $self, $what ) = @_;
Subroutine _scan_blacklisted: called CC=1 SCAR=0.0
118 5 return exists $self->_scan_blacklist->{$what};
119 }
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172 3 has _ebuilds => (
173 isa => HashRef [Gentoo__Overlay_Ebuild],
174 lazy,
175 builder => 1,
176 ro,
177 handles_via => 'Hash',
178 handles => {
179 _has_ebuild => exists =>,
180 ebuild_names => keys =>,
181 ebuilds => elements =>,
182 get_ebuild => get =>,
183 },
184 );
185  
186  
187  
188  
189  
190  
191  
192  
193  
194 sub _build__ebuilds {
195 1 ▶ my ($self) = shift;
Subroutine _build__ebuilds: called CC=6 SCAR=18.2
196 1 require Gentoo::Overlay::Ebuild;
197 1 my $it = $self->path->iterator();
198 1 my %out;
199 1 ▶ while ( defined( my $entry = $it->() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = &$it())) 1 1 2
200 1 my $ebuild = $entry->basename;
201 1 ▶ next if Gentoo::Overlay::Ebuild->is_blacklisted($ebuild);
Branch: 1 branch
BranchTrueFalseTotal
if "Gentoo::Overlay::Ebuild"->is_blacklisted($ebuild) 0 1 1
202 1 ▶ next if -d $entry;
Branch: 1 branch
BranchTrueFalseTotal
if -d $entry 0 1 1
203 ## no critic ( RegularExpressions )
204 1 ▶ next if $entry !~ /\.ebuild$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry =~ /\.ebuild$/ 0 1 1
205 1 my $e = Gentoo::Overlay::Ebuild->new(
206 name => $ebuild,
207 package => $self,
208 );
209 1 ▶ next unless $e->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $e->exists 0 1 1
210 1 $out{$ebuild} = $e;
211 }
212 1 return \%out;
213 }
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224 ## no critic ( ProhibitBuiltinHomonyms )
225 sub exists {
226 5 ▶ my $self = shift;
Subroutine exists: called CC=5 SCAR=16.6
Pod documented
227 5 ▶ return if q{.} eq $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if "." eq $self->name 0 5 5
228 5 ▶ return if q{..} eq $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if ".." eq $self->name 0 5 5
229 5 ▶ return if not -e $self->path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $self->path 0 5 5
230 5 ▶ return if not -d $self->path;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->path 4 1 5
231 1 return 1;
232 }
233  
234  
235  
236  
237  
238  
239  
240  
241  
242 sub is_blacklisted {
243 5 ▶ my ( $self, $name ) = @_;
Subroutine is_blacklisted: called CC=2 SCAR=7.6
Pod documented
244 5 ▶ if ( not defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 0 5 5
245 0 $name = $self->name;
246 }
247 5 return $self->_scan_blacklisted($name);
248 }
249  
250  
251  
252  
253  
254  
255  
256  
257  
258 sub pretty_name {
259 0 ▶ my $self = shift;
Subroutine pretty_name: not called CC=1 SCAR=6.9
Pod documented
260 0 return $self->category->name . q{/} . $self->name . q{::} . $self->overlay->name;
261 }
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289 sub iterate {
290 0 ▶ my ( $self, $what, $callback ) = @_; ## no critic (Variables::ProhibitUnusedVarsStricter)
Subroutine iterate: not called CC=2 SCAR=17.9
Pod documented
291 0 my %method_map = ( ebuilds => _iterate_ebuilds =>, );
292 0 ▶ if ( exists $method_map{$what} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $method_map{$what}) 0 0 0
293 0 goto $self->can( $method_map{$what} );
294 }
295 0 return exception(
296 ident => 'bad iteration method',
297 message => 'The iteration method %{what_method}s is not a known way to iterate.',
298 payload => { what_method => $what },
299 );
300 }
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312 # ebuilds = {/ebuilds }
313 sub _iterate_ebuilds {
314 1 ▶ my ( $self, undef, $callback ) = @_;
Subroutine _iterate_ebuilds: called CC=2 SCAR=6.9
315 1 my %ebuilds = $self->ebuilds();
316 1 my $num_ebuilds = scalar keys %ebuilds;
317 1 my $last_ebuild = $num_ebuilds - 1;
318 1 my $offset = 0;
319 1 for my $ename ( sort keys %ebuilds ) {
320 1 local $_ = $ebuilds{$ename};
321 $self->$callback(
322 {
323 ebuild_name => $ename,
324 1 ebuild => $ebuilds{$ename},
325 num_ebuilds => $num_ebuilds,
326 last_ebuild => $last_ebuild,
327 ebuild_num => $offset,
328 }
329 );
330 1 $offset++;
331 }
332 1 return;
333  
334 }
335 3 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
336 3 1;
337  
338 __END__
339  
340 =pod
341  
342 =encoding UTF-8
343  
344 =head1 NAME
345  
346 Gentoo::Overlay::Package - Class for Package's in Gentoo Overlays
347  
348 =head1 VERSION
349  
350 version 2.001001
351  
352 =head1 SYNOPSIS
353  
354 my $package = Overlay::Package->new(
355 name => 'Moose',
356 category => $category_object,
357 );
358  
359 $package->exists() # Moose exists
360  
361 print $package->pretty_name() # dev-perl/Moose::gentoo
362  
363 print $package->path() # /usr/portage/dev-perl/Moose
364  
365 ::Package->is_blacklisted("..") # '..' is not a valid package name
366 ::Package->is_blacklisted('metadata.xml') # is not a valid directory
367  
368 =head1 METHODS
369  
370 =head2 exists
371  
372 Does the Package exist, and is it a directory?
373  
374 $package->exists();
375  
376 =head2 is_blacklisted
377  
378 Does the package name appear on a blacklist meaning auto-scan should ignore this?
379  
380 ::Package->is_blacklisted('..') # true
381  
382 =head2 pretty_name
383  
384 A pretty form of the name
385  
386 $package->pretty_name # dev-perl/Moose::gentoo
387  
388 =head2 iterate
389  
390 $overlay->iterate( $what, sub {
391 my ( $context_information ) = shift;
392  
393 } );
394  
395 The iterate method provides a handy way to do walking across the whole tree stopping at each of a given type.
396  
397 =over 4
398  
399 =item * C<$what = 'ebuilds'>
400  
401 $overlay->iterate( ebuilds => sub {
402 my ( $self, $c ) = shift;
403 # $c->{ebuild_name} # String
404 # $c->{ebuild} # Ebuild Object
405 # $c->{num_ebuilds} # How many ebuild are there to iterate
406 # $c->{last_ebuild} # Index ID of the last ebuild.
407 # $c->{ebuild_num} # Index ID of the current ebuild.
408 } );
409  
410 =back
411  
412 =head1 ATTRIBUTES
413  
414 =head2 name
415  
416 The packages Short name.
417  
418 isa => Gentoo__Overlay_PackageName, required, ro
419  
420 L<< C<PackageName>|Gentoo::Overlay::Types/Gentoo__Overlay_PackageName >>
421  
422 =head2 category
423  
424 The category object that this package is in.
425  
426 isa => Gentoo__Overlay_Category, required, ro
427  
428 accessors => overlay
429  
430 L<< C<Category>|Gentoo::Overlay::Types/Gentoo__Overlay_Category >>
431  
432 L</overlay>
433  
434 =head2 path
435  
436 The full path to the package.
437  
438 isa => Dir, lazy, ro
439  
440 L<MooseX::Types::Path::Tiny/Dir>
441  
442 =head1 ATTRIBUTE ACCESSORS
443  
444 =head2 overlay
445  
446 $package->overlay -> Gentoo::Overlay::Category->overlay
447  
448 L<Gentoo::Overlay::Category/overlay>
449  
450 L</category>
451  
452 =head2 ebuild_names
453  
454 for( $package->ebuild_names ){
455 print $_;
456 }
457  
458 L</_ebuilds>
459  
460 =head2 ebuilds
461  
462 my %ebuilds = $package->ebuilds;
463  
464 L</_ebuilds>
465  
466 =head2 get_ebuild
467  
468 my $ebuild = $package->get_ebuild('Moose-2.0.0.ebuild');
469  
470 L</_ebuilds>
471  
472 =head1 PRIVATE ATTRIBUTES
473  
474 =head2 _ebuilds
475  
476 isa => HashRef[ Gentoo__Overlay_Ebuild ], lazy_build, ro
477  
478 accessors => _has_ebuild , ebuild_names,
479 ebuilds, get_ebuild
480  
481 L</_has_ebuild>
482  
483 L</ebuild_names>
484  
485 L</ebuilds>
486  
487 L</get_ebuild>
488  
489 =head1 PRIVATE ATTRIBUTE ACCESSORS
490  
491 =head2 _has_ebuild
492  
493 $package->_has_ebuild('Moose-2.0.0.ebuild');
494  
495 L</_ebuilds>
496  
497 =head1 PRIVATE CLASS ATTRIBUTES
498  
499 =head2 _scan_blacklist
500  
501 Class-Wide list of blacklisted package names.
502  
503 isa => HashRef[ Str ], ro, lazy,
504  
505 accessors => _scan_blacklisted
506  
507 L</_scan_blacklisted>
508  
509 L<< C<MooseX::Types::Moose>|MooseX::Types::Moose >>
510  
511 =head1 PRIVATE CLASS ATTRIBUTE ACCESSORS
512  
513 =head2 _scan_blacklisted
514  
515 is C<$arg> blacklisted in the Class Wide Blacklist?
516  
517 ::Package->_scan_blacklisted( $arg )
518 ->
519 exists ::Package->_scan_blacklist->{$arg}
520  
521 L</_scan_blacklist>
522  
523 =head1 PRIVATE METHODS
524  
525 =head2 _build__ebuilds
526  
527 Generates the ebuild Hash-Table, by scanning the package directory.
528  
529 L</_packages>
530  
531 =head2 _iterate_ebuilds
532  
533 $object->_iterate_ebuilds( ignored_value => sub { } );
534  
535 Handles dispatch call for
536  
537 $object->iterate( ebuilds => sub { } );
538  
539 =head1 AUTHOR
540  
541 Kent Fredric <kentnl@cpan.org>
542  
543 =head1 COPYRIGHT AND LICENSE
544  
545 This software is copyright (c) 2014 by Kent Fredric <kentnl@cpan.org>.
546  
547 This is free software; you can redistribute it and/or modify it under
548 the same terms as the Perl 5 programming language system itself.
549  
550 =cut
« blib/lib/Gentoo/Overlay/Exceptions.pm ↑ Summary lib/Gentoo/Overlay/Ebuild.pm »