blib/lib/Gentoo/Overlay/Ebuild.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 92 SCAR 37.4
CC
6
Cov
0%
exists
30.0
is_blacklisted
6.0
_scan_blacklisted
2.0
CRAP 42.0
1 use 5.006;
2 use strict;
3 use warnings;
4  
5 package Gentoo::Overlay::Ebuild;
6  
7 our $VERSION = '2.001000';
8  
9 # ABSTRACT: A Class for Ebuilds in Gentoo Overlays
10  
11 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 use Moo qw( has );
14 use MooseX::Has::Sugar qw( required ro lazy );
15 use Types::Standard qw( HashRef Str );
16 use Types::Path::Tiny qw( File Dir );
17 use MooX::ClassAttribute qw( class_has );
18 use Gentoo::Overlay::Types qw( Gentoo__Overlay_EbuildName Gentoo__Overlay_Package );
19 use namespace::clean -except => 'meta';
20  
21  
22  
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  
69  
70  
71  
72  
73  
74  
75  
76  
77 has name => ( isa => Gentoo__Overlay_EbuildName, required, ro );
78 has package => (
79 isa => Gentoo__Overlay_Package,
80 required, ro,
81 handles => [qw( overlay category )],
82 );
83  
84 has path => (
85 isa => File,
86 ro,
87 lazy,
88 default => sub {
89 my ($self) = shift;
90 return $self->overlay->default_path( 'ebuild', $self->category->name, $self->package->name, $self->name );
91 },
92 );
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121 class_has _scan_blacklist => (
122 isa => HashRef [Str],
123 ro,
124 lazy,
125 default => sub {
126 return { map { $_ => 1 } qw( . .. ChangeLog Manifest metadata.xml ) };
127 },
128 );
129  
130 sub _scan_blacklisted {
131 my ( $self, $what ) = @_;
132 return exists $self->_scan_blacklist->{$what};
133 }
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144 ## no critic ( ProhibitBuiltinHomonyms )
145 sub exists {
146 my $self = shift;
147 return if q{.} eq $self->name;
148 return if q{..} eq $self->name;
149 return unless $self->path->exists;
150 return if $self->path->is_dir;
151 return 1;
152 }
153  
154  
155  
156  
157  
158  
159  
160  
161  
162 sub is_blacklisted {
163 my ( $self, $name ) = @_;
164 if ( not defined $name ) {
165 $name = $self->name;
166 }
167 return $self->_scan_blacklisted($name);
168 }
169  
170  
171  
172  
173  
174  
175  
176  
177  
178 sub pretty_name {
179 my $self = shift;
180 my $filename = $self->name;
181 ## no critic (RegularExpressions)
182 $filename =~ s/\.ebuild$//;
183 return q{=} . $self->category->name . q{/} . $filename . q{::} . $self->overlay->name;
184 }
185  
186 no Moo;
187 1;
188  
189 __END__
190  
191 =pod
192  
193 =encoding UTF-8
194  
195 =head1 NAME
196  
197 Gentoo::Overlay::Ebuild - A Class for Ebuilds in Gentoo Overlays
198  
199 =head1 VERSION
200  
201 version 2.001000
202  
203 =head1 SYNOPSIS
204  
205 my $ebuild = Overlay::Ebuild->new(
206 name => 'Moose-2.0.0.ebuild',
207 package => $package_object,
208 );
209  
210 $ebuild->exists(); # Ebuild listed exists.
211  
212 print $ebuild->pretty_name # =dev-perl/Moose-2.0.0::gentoo
213  
214 print $ebuild->path # /usr/portage/dev-perl/Moose/Moose-2.0.0.ebuild
215  
216 =head1 METHODS
217  
218 =head2 exists
219  
220 Does the Ebuild exist, and is it a file?
221  
222 $ebuild->exists();
223  
224 =head2 is_blacklisted
225  
226 Does the ebuild name appear on a blacklist meaning auto-scan should ignore this?
227  
228 ::Ebuild->is_blacklisted('..') # true
229  
230 =head2 pretty_name
231  
232 A pretty form of the name
233  
234 $ebuild->pretty_name # =dev-perl/Moose-2.0.0::gentoo
235  
236 =head1 ATTRIBUTES
237  
238 =head2 name
239  
240 The Ebuilds short name
241  
242 isa => Gentoo__Overlay_EbuildName, required, ro
243  
244 L<< C<EbuildName>|Gentoo::Overlay::Types/Gentoo__Overlay_EbuildName >>
245  
246 =head2 package
247  
248 The package object this ebuild is within.
249  
250 isa => Gentoo__Overlay_EbuildName, required, ro
251  
252 accessors => overlay category
253  
254 L<< C<Package>|Gentoo::Overlay::Types/Gentoo__Overlay_Package >>
255  
256 L</overlay>
257  
258 L</category>
259  
260 =head2 path
261  
262 The full path to the ebuild.
263  
264 isa => File, lazy, ro
265  
266 L<MooseX::Types::Path::Tiny/File>
267  
268 =head1 ATTRIBUTE ACCESSORS
269  
270 =head2 overlay
271  
272 $ebuild->overlay -> Gentoo::Overlay::Package->overlay
273  
274 L<Gentoo::Overlay::Package/overlay>
275  
276 L</package>
277  
278 =head2 category
279  
280 $ebuild->category -> Gentoo::Overlay::Package->category
281  
282 L<Gentoo::Overlay::Package/category>
283  
284 L</package>
285  
286 =head1 PRIVATE CLASS ATTRIBUTES
287  
288 =head2 _scan_blacklist
289  
290 Class-Wide list of blacklisted ebuild names.
291  
292 isa => HashRef[ Str ], ro, lazy,
293  
294 accessors => _scan_blacklisted
295  
296 L</_scan_blacklisted>
297  
298 L<< C<MooseX::Types::Moose>|MooseX::Types::Moose >>
299  
300 =head1 PRIVATE CLASS ATTRIBUTE ACCESSORS
301  
302 =head2 _scan_blacklisted
303  
304 is C<$arg> blacklisted in the Class Wide Blacklist?
305  
306 ::Ebuild->_scan_blacklisted( $arg )
307 ->
308 exists ::Ebuild->_scan_blacklist->{$arg}
309  
310 L</_scan_blacklist>
311  
312 =head1 AUTHOR
313  
314 Kent Fredric <kentnl@cpan.org>
315  
316 =head1 COPYRIGHT AND LICENSE
317  
318 This software is copyright (c) 2014 by Kent Fredric <kentnl@cpan.org>.
319  
320 This is free software; you can redistribute it and/or modify it under
321 the same terms as the Perl 5 programming language system itself.
322  
323 =cut