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