File Coverage

blib/lib/Module/Install/Bundle.pm
Criterion Covered Total %
statement 18 57 31.5
branch 0 24 0.0
condition 0 2 0.0
subroutine 6 11 54.5
pod 4 4 100.0
total 28 98 28.5


line stmt bran cond sub pod time code
1             package Module::Install::Bundle;
2              
3 1     1   1509 use strict;
  1         2  
  1         31  
4 1     1   5 use File::Spec;
  1         2  
  1         17  
5 1     1   4 use Module::Install::Base ();
  1         2  
  1         17  
6              
7 1     1   5 use vars qw{$VERSION @ISA $ISCORE};
  1         2  
  1         65  
8             BEGIN {
9 1     1   4 $VERSION = '1.21';
10 1         16 @ISA = 'Module::Install::Base';
11 1         490 $ISCORE = 1;
12             }
13              
14             sub auto_bundle {
15 0     0 1   my $self = shift;
16              
17 0 0         return $self->_install_bundled_dists unless $self->is_admin;
18              
19             # Flatten array of arrays into a single array
20 0           my @core = map @$_, map @$_, grep ref, $self->requires;
21              
22 0           $self->bundle(@core);
23             }
24              
25             sub bundle {
26 0     0 1   my $self = shift;
27              
28 0 0         return $self->_install_bundled_dists unless $self->is_admin;
29              
30 0           $self->admin->bundle(@_);
31             }
32              
33             sub auto_bundle_deps {
34 0     0 1   my $self = shift;
35              
36 0 0         return $self->_install_bundled_dists unless $self->is_admin;
37              
38             # Flatten array of arrays into a single array
39 0           my @core = map @$_, map @$_, grep ref, $self->requires;
40 0           while (my ($name, $version) = splice(@core, 0, 2)) {
41 0 0         next unless $name;
42 0           $self->bundle_deps($name, $version);
43             }
44             }
45              
46             sub bundle_deps {
47 0     0 1   my ($self, $pkg, $version) = @_;
48              
49 0 0         return $self->_install_bundled_dists unless $self->is_admin;
50              
51 0           my $deps = $self->admin->scan_dependencies($pkg);
52 0 0         if (scalar keys %$deps == 0) {
53             # Probably a user trying to install the package, read the dependencies from META.yml
54 0           %$deps = ( map { $$_[0] => undef } (@{$self->requires()}) );
  0            
  0            
55             }
56 0           foreach my $key (sort keys %$deps) {
57 0 0         $self->bundle($key, ($key eq $pkg) ? $version : 0);
58             }
59             }
60              
61             sub _install_bundled_dists {
62 0     0     my $self = shift;
63              
64             # process bundle only the first time this function is called
65 0 0         return if $self->{bundle_processed};
66              
67 0   0       $self->makemaker_args->{DIR} ||= [];
68              
69             # process all dists bundled in inc/BUNDLES/
70 0           my $bundle_dir = $self->_top->{bundle};
71 0           foreach my $sub_dir (glob File::Spec->catfile($bundle_dir,"*")) {
72              
73 0 0         next if -f $sub_dir;
74              
75             # ignore dot dirs/files if any
76 0           my $dot_file = File::Spec->catfile($bundle_dir,'\.');
77 1 0   1   577 next if index($sub_dir, $dot_file) >= $[;
  1         334  
  1         144  
  0            
78              
79             # EU::MM can't handle Build.PL based distributions
80 0 0         if (-f File::Spec->catfile($sub_dir, 'Build.PL')) {
81 0           warn "Skipped: $sub_dir has Build.PL.";
82 0           next;
83             }
84              
85             # EU::MM can't handle distributions without Makefile.PL
86             # (actually this is to cut blib in a wrong directory)
87 0 0         if (!-f File::Spec->catfile($sub_dir, 'Makefile.PL')) {
88 0           warn "Skipped: $sub_dir has no Makefile.PL.";
89 0           next;
90             }
91 0           push @{ $self->makemaker_args->{DIR} }, $sub_dir;
  0            
92             }
93              
94 0           $self->{bundle_processed} = 1;
95             }
96              
97             1;
98              
99             __END__
100              
101             =pod
102              
103             =head1 NAME
104              
105             Module::Install::Bundle - Bundle distributions along with your distribution
106              
107             =head1 SYNOPSIS
108              
109             Have your Makefile.PL read as follows:
110              
111             use inc::Module::Install;
112            
113             name 'Foo-Bar';
114             all_from 'lib/Foo/Bar.pm';
115             requires 'Baz' => '1.60';
116            
117             # one of either:
118             bundle 'Baz' => '1.60';
119             # OR:
120             auto_bundle;
121            
122             WriteAll;
123              
124             =head1 DESCRIPTION
125              
126             Module::Install::Bundle allows you to bundle a CPAN distribution within your
127             distribution. When your end-users install your distribution, the bundled
128             distribution will be installed along with yours, unless a newer version of
129             the bundled distribution already exists on their local filesystem.
130              
131             While bundling will increase the size of your distribution, it has several
132             benefits:
133              
134             Allows installation of bundled distributions when CPAN is unavailable
135             Allows installation of bundled distributions when networking is unavailable
136             Allows everything your distribution needs to be packaged in one place
137              
138             Bundling differs from auto-installation in that when it comes time to
139             install, a bundled distribution will be installed based on the distribution
140             bundled with your distribution, whereas with auto-installation the distribution
141             to be installed will be acquired from CPAN and then installed.
142              
143             =head1 METHODS
144              
145             =over 4
146              
147             =item * auto_bundle()
148              
149             Takes no arguments, will bundle every distribution specified by a C<requires()>.
150             When you, as a module author, do a C<perl Makefile.PL> the latest versions of
151             the distributions to be bundled will be acquired from CPAN and placed in
152             F<inc/BUNDLES/>.
153              
154             =item * bundle($name, $version)
155              
156             Takes a list of key/value pairs specifying a distribution name and version
157             number. When you, as a module author, do a perl Makefile.PL the distributions
158             that you specified with C<bundle()> will be acquired from CPAN and placed in
159             F<inc/BUNDLES/>.
160              
161             =item * bundle_deps($name, $version)
162              
163             Same as C<bundle>, except that all dependencies of the bundled modules are
164             also detected and bundled. To use this function, you need to declare the
165             minimum supported perl version first, like this:
166              
167             perl_version( '5.005' );
168              
169             =item * auto_bundle_deps
170              
171             Same as C<auto_bundle>, except that all dependencies of the bundled
172             modules are also detected and bundled. This function has the same constraints as bundle_deps.
173              
174             =back
175              
176             =head1 BUGS
177              
178             Please report any bugs to (patches welcome):
179              
180             http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Module-Install
181              
182             =head1 AUTHORS
183              
184             Audrey Tang E<lt>autrijus@autrijus.orgE<gt>
185              
186             Documentation by Adam Foxson E<lt>afoxson@pobox.comE<gt>
187              
188             =head1 COPYRIGHT
189              
190             Copyright 2003, 2004, 2005 by Audrey Tang E<lt>autrijus@autrijus.orgE<gt>.
191              
192             This program is free software; you can redistribute it and/or modify it under
193             the same terms as Perl itself.
194              
195             =cut