blib/lib/Perl/Dist/Asset/Distribution.pm

filter: Statementstmt 87.6% 57 / 65 Branchbran 55.0% 11 / 20 Conditioncond 45.4% 5 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 15 / 15 Podpod 33.3% 1 / 3 totaltotal 73.5% 89 / 121 CC 15 SCAR 19.1
CC
15
Cov
76%
new
16.6
_DIST
5.6
abs_uri
3.0
CRAP 6.8
« blib/lib/Perl/Dist/Machine.pm ↑ Summary blib/lib/Perl/Dist/Util/Toolchain.pm »
1 package Perl::Dist::Asset::Distribution;
2  
3 =pod
4  
5 =head1 NAME
6  
7 Perl::Dist::Asset::Distribution - "Perl Distribution" asset for a Win32 Perl
8  
9 =head1 SYNOPSIS
10  
11 my $distribution = Perl::Dist::Asset::Distribution->new(
12 name => 'MSERGEANT/DBD-SQLite-1.14.tar.gz',
13 force => 1,
14 );
15  
16 =head1 DESCRIPTION
17  
18 L<Perl::Dist::Inno> supports two methods for adding Perl modules to the
19 installation. The main method is to install it via the CPAN shell.
20  
21 The second is to download, make, test and install the Perl distribution
22 package independantly, avoiding the use of the CPAN client. Unlike the
23 CPAN installation method, installation the distribution directly does
24 C<not> allow the installation of dependencies, or the ability to discover
25 and install the most recent release of the module.
26  
27 This secondary method is primarily used to deal with cases where the CPAN
28 shell either fails or does not yet exist. Installation of the Perl
29 toolchain to get a working CPAN client is done exclusively using the
30 direct method, as well as the installation of a few special case modules
31 such as L<DBD::SQLite> where the newest release is broken, but an older
32 release is known to be good.
33  
34 B<Perl::Dist::Asset::Distribution> is a data class that provides
35 encapsulation and error checking for a "Perl Distribution" to be
36 installed in a L<Perl::Dist>-based Perl distribution using this
37 secondary method.
38  
39 It is normally created on the fly by the <Perl::Dist::Inno>
40 C<install_distribution> method (and other things that call it).
41  
42 The specification of the location to retrieve the package is done via
43 the standard mechanism implemented in L<Perl::Dist::Asset>.
44  
45 =head1 METHODS
46  
47 This class inherits from L<Perl::Dist::Asset> and shares its API.
48  
49 =cut
50  
51 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
53 2 ▶use Params::Util qw{ _STRING _ARRAY _INSTANCE };
Subroutine BEGIN: called CC=1 SCAR=0.0
54 2 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
55 2 ▶use File::Spec::Unix ();
Subroutine BEGIN: called CC=1 SCAR=0.0
56 2 ▶use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
57 2 ▶use URI::file ();
Subroutine BEGIN: called CC=1 SCAR=0.0
58 2 ▶use Perl::Dist::Asset ();
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 2 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
61 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
62 2 $VERSION = '1.16';
63 2 @ISA = 'Perl::Dist::Asset';
64 }
65  
66 2 ▶use Object::Tiny qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
67 name
68 inject
69 force
70 automated_testing
71 release_testing
72 makefilepl_param
73 2 };
74  
75  
76  
77  
78  
79 #####################################################################
80 # Constructor
81  
82 =pod
83  
84 =head2 new
85  
86 The C<new> constructor takes a series of parameters, validates then
87 and returns a new B<Perl::Dist::Asset::Binary> object.
88  
89 It inherits all the params described in the L<Perl::Dist::Asset> C<new>
90 method documentation, and adds some additional params.
91  
92 =over 4
93  
94 =item name
95  
96 The required C<name> param is the name of the package for the purposes
97 of identification.
98  
99 This should match the name of the Perl distribution without any version
100 numbers. For example, "File-Spec" or "libwww-perl".
101  
102 Alternatively, the C<name> param can be a CPAN path to the distribution
103 such as shown in the synopsis.
104  
105 In this case, the url to fetch from will be derived from the name.
106  
107 =item force
108  
109 Unlike in the CPAN client installation, in which all modules MUST pass
110 their tests to be added, the secondary method allows for cases where
111 it is known that the tests can be safely "forced".
112  
113 The optional boolean C<force> param allows you to specify is the tests
114 should be skipped and the module installed without validating it.
115  
116 =item automated_testing
117  
118 Many modules contain additional long-running tests, tests that require
119 additional dependencies, or have differing behaviour when installing
120 in a non-user automated environment.
121  
122 The optional C<automated_testing> param lets you specify that the
123 module should be installed with the B<AUTOMATED_TESTING> environment
124 variable set to true, to make the distribution behave properly in an
125 automated environment (in cases where it doesn't otherwise).
126  
127 =item release_testing
128  
129 Some modules contain release-time only tests, that require even heavier
130 additional dependencies compared to even the C<automated_testing> tests.
131  
132 The optional C<release_testing> param lets you specify that the module
133 tests should be run with the additional C<RELEASE_TESTING> environment
134 flag set.
135  
136 By default, C<release_testing> is set to false to squelch any accidental
137 execution of release tests when L<Perl::Dist> itself is being tested
138 under C<RELEASE_TESTING>.
139  
140 =item makefilepl_param
141  
142 Some distributions illegally require you to pass additional non-standard
143 parameters when you invoke "perl Makefile.PL".
144  
145 The optional C<makefilepl_param> param should be a reference to an ARRAY
146 where each element contains the argument to pass to the Makefile.PL.
147  
148 =back
149  
150 The C<new> method returns a B<Perl::Dist::Asset::Distribution> object,
151 or throws an exception (dies) on error.
152  
153 =cut
154  
155 2 ▶sub new {
Subroutine new: called CC=9 SCAR=28.1
Pod documented
156 2 my $self = shift->SUPER::new(@_);
157  
158 # Normalize params
159 2 $self->{force} = !! $self->force;
160 2 $self->{automated_testing} = !! $self->automated_testing;
161 2 $self->{release_testing} = !! $self->release_testing;
162  
163 # Check params
164 2 ▶ unless ( _STRING($self->name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&_STRING(scalar $self->name)) 0 2 2
165 0 Carp::croak("Missing or invalid name param");
166 }
167 2 ▶ if ( $self->name eq $self->url and not _DIST($self->name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->name eq $self->url and not _DIST($self->name)) 0 2 2
Condition66%2/3
$self->name eq $self->url and not _DIST($self->name)
!ll&&!rl&&r
110
MC/DC0%0/2
$self->name eq $self->url and not _DIST($self->name)
$self->name eq $self->url not _DIST($self->name)
Truth table66%2/3
A and not(B)
A= $self->name eq $self->urlB= not _DIST($self->name)
ABresult
0X0
100
111
168 0 Carp::croak("Missing or invalid name param");
169 }
170 2 ▶ if ( defined $self->inject ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->inject) 0 2 2
171 0 ▶ unless ( _INSTANCE($self->inject, 'URI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&_INSTANCE(scalar $self->inject, "URI")) 0 0 0
172 0 Carp::croak("The inject param must be a fully resolved URI");
173 }
174 }
175 2 ▶ if ( defined $self->makefilepl_param and ! _ARRAY($self->makefilepl_param) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->makefilepl_param and not &_ARRAY(scalar $self->makefilepl_param)) 0 2 2
Condition33%1/3
defined $self->makefilepl_param and not &_ARRAY(scalar $self->makefilepl_param)
!ll&&!rl&&r
200
MC/DC0%0/2
defined $self->makefilepl_param and not &_ARRAY(scalar $self->makefilepl_param)
defined $self->makefilepl_param not &_ARRAY(scalar $self->makefilepl_param)
Truth table33%1/3
A and not(B)
A= defined $self->makefilepl_paramB= not &_ARRAY(scalar $self->makefilepl_param)
ABresult
0X0
100
111
176 0 Carp::croak("Invalid makefilepl_param param");
177 }
178 2 ▶ $self->{makefilepl_param} ||= [];
Condition50%1/2
$self->{"makefilepl_param"} ||= []
l!l
02
MC/DC0%0/1
$self->{"makefilepl_param"} ||= []
$self->{"makefilepl_param"}
Truth table50%1/2
A
A= $self->{"makefilepl_param"}
Aresult
11
00
179  
180 2 return $self;
181 }
182  
183 15 ▶sub url { $_[0]->{url} || $_[0]->{name} }
Subroutine url: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"url"} or $_[0]{"name"} 8 7 15
184  
185  
186  
187  
188  
189 #####################################################################
190 # Main Methods
191  
192 2 ▶sub abs_uri {
Subroutine abs_uri: called CC=3 SCAR=11.1
Pod undocumented
193 2 my $self = shift;
194  
195 # Get the base path
196 2 my $cpan = _INSTANCE(shift, 'URI');
197 2 ▶ unless ( $cpan ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cpan) 0 2 2
198 0 Carp::croak("Did not pass a cpan URI");
199 }
200  
201 # If we have an explicit absolute URI use it directly.
202 2 my $new_abs = URI->new_abs($self->url, $cpan);
203 2 ▶ if ( $new_abs eq $self->url ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_abs eq $self->url) 1 1 2
204 1 return $new_abs;
205 }
206  
207 # Generate the full relative path
208 1 my $name = $self->name;
209 1 my $path = File::Spec::Unix->catfile( 'authors', 'id',
210 substr($name, 0, 1),
211 substr($name, 0, 2),
212 $name,
213 );
214  
215 1 URI->new_abs( $path, $cpan );
216 }
217  
218  
219  
220  
221  
222 #####################################################################
223 # Support Methods
224  
225 1 ▶sub _DIST {
Subroutine _DIST: called CC=4 SCAR=17.2
226 1 my $it = shift;
227 1 ▶ unless ( defined $it and ! ref $it ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $it and not ref $it) 0 1 1
Condition33%1/3
defined $it and not ref $it
!ll&&!rl&&r
001
MC/DC0%0/2
defined $it and not ref $it
defined $it not ref $it
Truth table33%1/3
A and not(B)
A= defined $itB= not ref $it
ABresult
0X0
100
111
228 0 return undef;
229 }
230 1 ▶ unless ( $it =~ q|^([A-Z]){2,}/| ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($it =~ m[^([A-Z]){2,}/]) 0 1 1
231 0 return undef;
232 }
233 1 return $it;
234 }
235  
236 2 1;
237  
238 =pod
239  
240 =head1 SUPPORT
241  
242 Bugs should be reported via the CPAN bug tracker at
243  
244 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Perl-Dist>
245  
246 For other issues, contact the author.
247  
248 =head1 AUTHOR
249  
250 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
251  
252 =head1 SEE ALSO
253  
254 L<Perl::Dist>, L<Perl::Dist::Inno>, L<Perl::Dist::Asset>
255  
256 =head1 COPYRIGHT
257  
258 Copyright 2007 - 2009 Adam Kennedy.
259  
260 This program is free software; you can redistribute
261 it and/or modify it under the same terms as Perl itself.
262  
263 The full text of the license can be found in the
264 LICENSE file included with this module.
265  
266 =cut
« blib/lib/Perl/Dist/Machine.pm ↑ Summary blib/lib/Perl/Dist/Util/Toolchain.pm »