File Coverage

blib/lib/Module/Install/Admin/Include.pm
Criterion Covered Total %
statement 11 71 15.4
branch 0 18 0.0
condition n/a
subroutine 4 13 30.7
pod 3 7 42.8
total 18 109 16.5


line stmt bran cond sub pod time code
1             package Module::Install::Admin::Include;
2              
3 1     1   1482 use strict;
  1         3  
  1         32  
4 1     1   7 use Module::Install::Base;
  1         74  
  1         75  
5              
6 1     1   16 use vars qw{$VERSION @ISA};
  1         2  
  1         65  
7             BEGIN {
8 1     1   3 $VERSION = '1.21';
9 1         1274 @ISA = qw{Module::Install::Base};
10             }
11              
12             sub include {
13 0     0 0   my $self = shift;
14 0           foreach my $rv ( $self->admin->glob_in_inc($_[0]) ) {
15 0           $self->admin->copy_package(@$rv);
16 0           my @build_requires;
17 0 0         foreach (@{ $self->build_requires || [] }) {
  0            
18 0 0         next if $_->[0] eq $rv->[0];
19 0           push @build_requires, $_;
20             }
21 0           $self->Meta->{values}{build_requires} = \@build_requires;
22             }
23             }
24              
25             sub include_deps {
26 0     0 0   my ($self, $module, $version) = @_;
27 0 0         my $deps = $self->admin->scan_dependencies($module, $self->perl_version, $version) or return;
28 0           foreach my $key ( sort keys %$deps ) {
29 0           $self->include($key);
30             }
31             }
32              
33             sub auto_include {
34 0     0 0   my $self = shift;
35 0           foreach my $module (
36 0           map { $_->[0] }
37 0           map { @$_ }
38 0           grep { $_ }
39             $self->build_requires
40             ) {
41 0           $self->include($module);
42             }
43             }
44              
45             sub auto_include_deps {
46 0     0 0   my $self = shift;
47 0           foreach my $module (
48 0           map { $_ }
49 0           map { @$_ }
50 0           grep { $_ }
51             $self->build_requires
52             ) {
53 0           my ($name, $version) = @{$module};
  0            
54 0           $self->include_deps($name, $version);
55             }
56             }
57              
58             =pod
59              
60             =head1 NAME
61              
62             Module::Install::Admin::Include - include methods for Module::Install
63              
64             =head2 auto_include_dependent_dists
65              
66             Grabs everything in this module's build_requires and attempts to
67             include everything (at the whole distribution level) recursively.
68              
69             =cut
70              
71             sub auto_include_dependent_dists {
72 0     0 1   my $self = shift;
73 0           foreach my $module (
74 0           map { $_->[0] }
75 0           map { @$_ }
76 0           grep { $_ }
77             $self->build_requires
78             ) {
79 0           $self->include_dependent_dists($module);
80             }
81             }
82              
83             =pod
84              
85             =head2 include_dependent_dists $package
86              
87             Given a module package name, recursively include every package that
88             module needs.
89              
90             =cut
91              
92             sub include_dependent_dists {
93 0     0 1   my $self = shift;
94 0           my $pkg = shift;
95 0 0         return unless $pkg;
96 0 0         return if $self->{including_dep_dist}->{ $self->_pkg_to_dist($pkg) }++;
97 0           $self->include_one_dist($pkg);
98 0           foreach my $mod ( @{ $self->_dist_to_mods( $self->_pkg_to_dist($pkg) ) } ) {
  0            
99 0 0         my $deps = $self->admin->scan_dependencies($mod) or return;
100 0           foreach my $key ( sort grep { $_ } keys %$deps ) {
  0            
101 0           $self->include_dependent_dists($key);
102             }
103             }
104             }
105              
106             =pod
107              
108             =head2 include_one_dist $module
109              
110             Given a module name, C<$module>, figures out which modules are in the
111             dist containing that module and copies all those files to ./inc. I bet
112             there's a way to harness smarter logic from L<PAR>.
113              
114             =cut
115              
116             sub include_one_dist {
117 0     0 1   my $self = shift;
118 0           my @mods = $self->_dist_to_mods( $self->_pkg_to_dist($_[0]) );
119 0           foreach my $pattern ( grep { $_ } @mods ) {
  0            
120 0           foreach my $rv ( $self->admin->glob_in_inc($pattern) ) {
121 0           $self->admin->copy_package(@$rv);
122 0           my @build_requires;
123 0 0         foreach (@{ $self->build_requires || [] }) {
  0            
124 0 0         next if $_->[0] eq $rv->[0];
125 0           push @build_requires, $_;
126             }
127 0           $self->Meta->{values}{build_requires} = \@build_requires;
128             }
129             }
130             }
131              
132             =pod
133              
134             =for private _pkg_to_dist $modname
135              
136             Given a module name, returns the file on CPAN containing
137             its latest version.
138              
139             =cut
140              
141             sub _pkg_to_dist {
142 0     0     require CPAN;
143 0 0         my $mod = CPAN::Shell->expand( Module => $_[1] ) or return;
144 0           $mod->cpan_file;
145             }
146              
147             =pod
148              
149             =for private _dist_to_mods $distname
150              
151             Takes the output of CPAN::Module->cpan_file and return all the modules
152             that CPAN.pm knows are in that dist. There's probably a better way using CPANPLUS
153              
154             =cut
155              
156             sub _dist_to_mods {
157 0     0     CPAN::Shell->expand( Distribution => $_[1] )->containsmods;
158             }
159              
160             1;