File Coverage

blib/lib/Perl/Dist/Asset/Distribution.pm
Criterion Covered Total %
statement 56 64 87.5
branch 11 20 55.0
condition 5 11 45.4
subroutine 15 15 100.0
pod 1 3 33.3
total 88 113 77.8


line stmt bran cond sub pod time code
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 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 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 where the newest release is broken, but an older
32             release is known to be good.
33              
34             B is a data class that provides
35             encapsulation and error checking for a "Perl Distribution" to be
36             installed in a L-based Perl distribution using this
37             secondary method.
38              
39             It is normally created on the fly by the
40             C 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.
44              
45             =head1 METHODS
46              
47             This class inherits from L and shares its API.
48              
49             =cut
50              
51 1     1   27562 use strict;
  1         2  
  1         25  
52 1     1   5 use Carp ();
  1         1  
  1         18  
53 1     1   1004 use Params::Util qw{ _STRING _ARRAY _INSTANCE };
  1         5543  
  1         71  
54 1     1   8 use File::Spec ();
  1         1  
  1         12  
55 1     1   5 use File::Spec::Unix ();
  1         1  
  1         11  
56 1     1   909 use URI ();
  1         5358  
  1         28  
57 1     1   1120 use URI::file ();
  1         8919  
  1         27  
58 1     1   537 use Perl::Dist::Asset ();
  1         4  
  1         27  
59              
60 1     1   6 use vars qw{$VERSION @ISA};
  1         1  
  1         68  
61             BEGIN {
62 1     1   3 $VERSION = '1.16';
63 1         41 @ISA = 'Perl::Dist::Asset';
64             }
65              
66 1         5 use Object::Tiny qw{
67             name
68             inject
69             force
70             automated_testing
71             release_testing
72             makefilepl_param
73 1     1   6 };
  1         2  
74              
75              
76              
77              
78              
79             #####################################################################
80             # Constructor
81              
82             =pod
83              
84             =head2 new
85              
86             The C constructor takes a series of parameters, validates then
87             and returns a new B object.
88              
89             It inherits all the params described in the L C
90             method documentation, and adds some additional params.
91              
92             =over 4
93              
94             =item name
95              
96             The required C 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 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 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 param lets you specify that the
123             module should be installed with the B 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 tests.
131              
132             The optional C param lets you specify that the module
133             tests should be run with the additional C environment
134             flag set.
135              
136             By default, C is set to false to squelch any accidental
137             execution of release tests when L itself is being tested
138             under C.
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 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 method returns a B object,
151             or throws an exception (dies) on error.
152              
153             =cut
154              
155             sub new {
156 2     2 1 840 my $self = shift->SUPER::new(@_);
157              
158             # Normalize params
159 2         98 $self->{force} = !! $self->force;
160 2         47 $self->{automated_testing} = !! $self->automated_testing;
161 2         44 $self->{release_testing} = !! $self->release_testing;
162              
163             # Check params
164 2 50       44 unless ( _STRING($self->name) ) {
165 0         0 Carp::croak("Missing or invalid name param");
166             }
167 2 50 66     47 if ( $self->name eq $self->url and not _DIST($self->name) ) {
168 0         0 Carp::croak("Missing or invalid name param");
169             }
170 2 50       38 if ( defined $self->inject ) {
171 0 0       0 unless ( _INSTANCE($self->inject, 'URI') ) {
172 0         0 Carp::croak("The inject param must be a fully resolved URI");
173             }
174             }
175 2 50 33     53 if ( defined $self->makefilepl_param and ! _ARRAY($self->makefilepl_param) ) {
176 0         0 Carp::croak("Invalid makefilepl_param param");
177             }
178 2   50     23 $self->{makefilepl_param} ||= [];
179              
180 2         6 return $self;
181             }
182              
183 15 100   15 0 2349 sub url { $_[0]->{url} || $_[0]->{name} }
184              
185              
186              
187              
188              
189             #####################################################################
190             # Main Methods
191              
192             sub abs_uri {
193 2     2 0 3832 my $self = shift;
194              
195             # Get the base path
196 2         23 my $cpan = _INSTANCE(shift, 'URI');
197 2 50       148 unless ( $cpan ) {
198 0         0 Carp::croak("Did not pass a cpan URI");
199             }
200              
201             # If we have an explicit absolute URI use it directly.
202 2         21 my $new_abs = URI->new_abs($self->url, $cpan);
203 2 100       499 if ( $new_abs eq $self->url ) {
204 1         8 return $new_abs;
205             }
206              
207             # Generate the full relative path
208 1         31 my $name = $self->name;
209 1         18 my $path = File::Spec::Unix->catfile( 'authors', 'id',
210             substr($name, 0, 1),
211             substr($name, 0, 2),
212             $name,
213             );
214              
215 1         5 URI->new_abs( $path, $cpan );
216             }
217              
218              
219              
220              
221              
222             #####################################################################
223             # Support Methods
224              
225             sub _DIST {
226 1     1   6 my $it = shift;
227 1 50 33     7 unless ( defined $it and ! ref $it ) {
228 0         0 return undef;
229             }
230 1 50       8 unless ( $it =~ q|^([A-Z]){2,}/| ) {
231 0         0 return undef;
232             }
233 1         4 return $it;
234             }
235              
236             1;
237              
238             =pod
239              
240             =head1 SUPPORT
241              
242             Bugs should be reported via the CPAN bug tracker at
243              
244             L
245              
246             For other issues, contact the author.
247              
248             =head1 AUTHOR
249              
250             Adam Kennedy Eadamk@cpan.orgE
251              
252             =head1 SEE ALSO
253              
254             L, L, L
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