File Coverage

blib/lib/Perl/Dist/Asset/Binary.pm
Criterion Covered Total %
statement 20 26 76.9
branch 0 4 0.0
condition 0 3 0.0
subroutine 7 8 87.5
pod 1 1 100.0
total 28 42 66.6


line stmt bran cond sub pod time code
1             package Perl::Dist::Asset::Binary;
2              
3             =pod
4              
5             =head1 NAME
6              
7             Perl::Dist::Asset::Binary - "Binary Package" asset for a Win32 Perl
8              
9             =head1 SYNOPSIS
10              
11             my $binary = Perl::Dist::Asset::Binary->new(
12             name => 'dmake',
13             license => {
14             'dmake/COPYING' => 'dmake/COPYING',
15             'dmake/readme/license.txt' => 'dmake/license.txt',
16             },
17             install_to => {
18             'dmake/dmake.exe' => 'c/bin/dmake.exe',
19             'dmake/startup' => 'c/bin/startup',
20             },
21             );
22              
23             =head1 DESCRIPTION
24              
25             B is a data class that provides encapsulation
26             and error checking for a "binary package" to be installed in a
27             L-based Perl distribution.
28              
29             It is normally created on the fly by the C
30             method (and other things that call it).
31              
32             These packages will be simple zip or tar.gz files that are local files,
33             installed in a CPAN distribution's 'share' directory, or retrieved from
34             the internet via a URI.
35              
36             The specification of the location to retrieve the package is done via
37             the standard mechanism implemented in L.
38              
39             =head1 METHODS
40              
41             This class inherits from L and shares its API.
42              
43             =cut
44              
45 1     1   1723 use strict;
  1         3  
  1         30  
46 1     1   5 use Carp ();
  1         3  
  1         17  
47 1     1   6 use Params::Util qw{ _STRING _HASH };
  1         1  
  1         43  
48 1     1   82 use Perl::Dist::Asset ();
  1         2  
  1         17  
49              
50 1     1   5 use vars qw{$VERSION @ISA};
  1         1  
  1         130  
51             BEGIN {
52 1     1   10 $VERSION = '1.16';
53 1         44 @ISA = 'Perl::Dist::Asset';
54             }
55              
56 1         6 use Object::Tiny qw{
57             name
58             license
59             install_to
60 1     1   5 };
  1         2  
61              
62              
63              
64              
65              
66             #####################################################################
67             # Constructor and Accessors
68              
69             =pod
70              
71             =head2 new
72              
73             The C constructor takes a series of parameters, validates then
74             and returns a new B object.
75              
76             It inherits all the params described in the L C
77             method documentation, and adds some additional params.
78              
79             =over 4
80              
81             =item name
82              
83             The required C param is the logical (arbitrary) name of the package
84             for the purposes of identification.
85              
86             =item license
87              
88             During the installation build process, licenses files are pulled from
89             the various source packages and written to a single dedicated directory.
90              
91             The optional C param should be a reference to a HASH, where the keys
92             are the location of license files within the package, and the values are
93             locations within the "licenses" subdirectory of the final installation.
94              
95             =item install_to
96              
97             The required C param describes the location that the package
98             will be installed to.
99              
100             If the C param is a single string, such as "c" or "perl\foo"
101             the entire binary package will be installed, with the root of the package
102             archive being placed in the directory specified.
103              
104             If the C param is a reference to a HASH, it is taken to mean
105             that only some parts of the original binary package are required in the
106             final install. In this case, the keys should be the file or directories
107             desired, and the values are the names of the file or directory in the
108             final Perl installation.
109              
110             Although this param does not default when called directly, in practice
111             the L C method will default this value
112             to "c", as most binary installations are for C toolchain tools or
113             pre-compiled C libraries.
114              
115             =back
116              
117             The C constructor returns a B object,
118             or throws an exception (dies) if an invalid param is provided.
119              
120             =cut
121              
122             sub new {
123 0     0 1   my $self = shift->SUPER::new(@_);
124              
125             # Check params
126 0 0         unless ( _STRING($self->name) ) {
127 0           Carp::croak("Missing or invalid name param");
128             }
129 0 0 0       unless ( _STRING($self->install_to) or _HASH($self->install_to) ) {
130 0           Carp::croak("Missing or invalid install_to param");
131             }
132              
133 0           return $self;
134             }
135              
136             1;
137              
138             =pod
139              
140             =head1 SUPPORT
141              
142             Bugs should be reported via the CPAN bug tracker at
143              
144             L
145              
146             For other issues, contact the author.
147              
148             =head1 AUTHOR
149              
150             Adam Kennedy Eadamk@cpan.orgE
151              
152             =head1 SEE ALSO
153              
154             L, L, L
155              
156             =head1 COPYRIGHT
157              
158             Copyright 2007 - 2009 Adam Kennedy.
159              
160             This program is free software; you can redistribute
161             it and/or modify it under the same terms as Perl itself.
162              
163             The full text of the license can be found in the
164             LICENSE file included with this module.
165              
166             =cut