File Coverage

blib/lib/CPAN/Bundle.pm
Criterion Covered Total %
statement 9 158 5.7
branch 0 88 0.0
condition 0 23 0.0
subroutine 3 23 13.0
pod 0 20 0.0
total 12 312 3.8


line stmt bran cond sub pod time code
1             # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2             # vim: ts=4 sts=4 sw=4:
3             package CPAN::Bundle;
4 12     12   59 use strict;
  12         15  
  12         446  
5 12     12   4503 use CPAN::Module;
  12         25  
  12         549  
6             @CPAN::Bundle::ISA = qw(CPAN::Module);
7              
8 12         20721 use vars qw(
9             $VERSION
10 12     12   123 );
  12         18  
11             $VERSION = "5.5001";
12              
13             sub look {
14 0     0 0   my $self = shift;
15 0           $CPAN::Frontend->myprint($self->as_string);
16             }
17              
18             #-> CPAN::Bundle::undelay
19             sub undelay {
20 0     0 0   my $self = shift;
21 0           delete $self->{later};
22 0           for my $c ( $self->contains ) {
23 0 0         my $obj = CPAN::Shell->expandany($c) or next;
24 0           $obj->undelay;
25             }
26             }
27              
28             # mark as dirty/clean
29             #-> sub CPAN::Bundle::color_cmd_tmps ;
30             sub color_cmd_tmps {
31 0     0 0   my($self) = shift;
32 0   0       my($depth) = shift || 0;
33 0   0       my($color) = shift || 0;
34 0   0       my($ancestors) = shift || [];
35             # a module needs to recurse to its cpan_file, a distribution needs
36             # to recurse into its prereq_pms, a bundle needs to recurse into its modules
37              
38 0 0 0       return if exists $self->{incommandcolor}
      0        
39             && $color==1
40             && $self->{incommandcolor}==$color;
41 0 0         if ($depth>=$CPAN::MAX_RECURSION) {
42 0           die(CPAN::Exception::RecursiveDependency->new($ancestors));
43             }
44             # warn "color_cmd_tmps $depth $color " . $self->id; # sleep 1;
45              
46 0           for my $c ( $self->contains ) {
47 0 0         my $obj = CPAN::Shell->expandany($c) or next;
48 0 0         CPAN->debug("c[$c]obj[$obj]") if $CPAN::DEBUG;
49 0           $obj->color_cmd_tmps($depth+1,$color,[@$ancestors, $self->id]);
50             }
51             # never reached code?
52             #if ($color==0) {
53             #delete $self->{badtestcnt};
54             #}
55 0           $self->{incommandcolor} = $color;
56             }
57              
58             #-> sub CPAN::Bundle::as_string ;
59             sub as_string {
60 0     0 0   my($self) = @_;
61 0           $self->contains;
62             # following line must be "=", not "||=" because we have a moving target
63 0           $self->{INST_VERSION} = $self->inst_version;
64 0           return $self->SUPER::as_string;
65             }
66              
67             #-> sub CPAN::Bundle::contains ;
68             sub contains {
69 0     0 0   my($self) = @_;
70 0   0       my($inst_file) = $self->inst_file || "";
71 0           my($id) = $self->id;
72 0 0         $self->debug("inst_file[$inst_file]id[$id]") if $CPAN::DEBUG;
73 0 0 0       if ($inst_file && CPAN::Version->vlt($self->inst_version,$self->cpan_version)) {
74 0           undef $inst_file;
75             }
76 0 0         unless ($inst_file) {
77             # Try to get at it in the cpan directory
78 0 0         $self->debug("no inst_file") if $CPAN::DEBUG;
79 0           my $cpan_file;
80 0 0         $CPAN::Frontend->mydie("I don't know a bundle with ID $id\n") unless
81             $cpan_file = $self->cpan_file;
82 0 0         if ($cpan_file eq "N/A") {
83 0           $CPAN::Frontend->mydie("Bundle $id not found on disk and not on CPAN.
84             Maybe stale symlink? Maybe removed during session? Giving up.\n");
85             }
86 0           my $dist = $CPAN::META->instance('CPAN::Distribution',
87             $self->cpan_file);
88 0 0         $self->debug("before get id[$dist->{ID}]") if $CPAN::DEBUG;
89 0           $dist->get;
90 0 0         $self->debug("after get id[$dist->{ID}]") if $CPAN::DEBUG;
91 0           my($todir) = $CPAN::Config->{'cpan_home'};
92 0           my(@me,$from,$to,$me);
93 0           @me = split /::/, $self->id;
94 0           $me[-1] .= ".pm";
95 0           $me = File::Spec->catfile(@me);
96 0           $from = $self->find_bundle_file($dist->{build_dir},join('/',@me));
97 0           $to = File::Spec->catfile($todir,$me);
98 0           File::Path::mkpath(File::Basename::dirname($to));
99 0 0         File::Copy::copy($from, $to)
100             or Carp::confess("Couldn't copy $from to $to: $!");
101 0           $inst_file = $to;
102             }
103 0           my @result;
104 0           my $fh = FileHandle->new;
105 0           local $/ = "\n";
106 0 0         open($fh,$inst_file) or die "Could not open '$inst_file': $!";
107 0           my $in_cont = 0;
108 0 0         $self->debug("inst_file[$inst_file]") if $CPAN::DEBUG;
109 0           while (<$fh>) {
110 0 0         $in_cont = m/^=(?!head1\s+(?i-xsm:CONTENTS))/ ? 0 :
    0          
111             m/^=head1\s+(?i-xsm:CONTENTS)/ ? 1 : $in_cont;
112 0 0         next unless $in_cont;
113 0 0         next if /^=/;
114 0           s/\#.*//;
115 0 0         next if /^\s+$/;
116 0           chomp;
117 0           push @result, (split " ", $_, 2)[0];
118             }
119 0           close $fh;
120 0           delete $self->{STATUS};
121 0           $self->{CONTAINS} = \@result;
122 0 0         $self->debug("CONTAINS[@result]") if $CPAN::DEBUG;
123 0 0         unless (@result) {
124 0           $CPAN::Frontend->mywarn(qq{
125             The bundle file "$inst_file" may be a broken
126             bundlefile. It seems not to contain any bundle definition.
127             Please check the file and if it is bogus, please delete it.
128             Sorry for the inconvenience.
129             });
130             }
131 0           @result;
132             }
133              
134             #-> sub CPAN::Bundle::find_bundle_file
135             # $where is in local format, $what is in unix format
136             sub find_bundle_file {
137 0     0 0   my($self,$where,$what) = @_;
138 0 0         $self->debug("where[$where]what[$what]") if $CPAN::DEBUG;
139             ### The following two lines let CPAN.pm become Bundle/CPAN.pm :-(
140             ### my $bu = File::Spec->catfile($where,$what);
141             ### return $bu if -f $bu;
142 0           my $manifest = File::Spec->catfile($where,"MANIFEST");
143 0 0         unless (-f $manifest) {
144 0           require ExtUtils::Manifest;
145 0           my $cwd = CPAN::anycwd();
146 0           $self->safe_chdir($where);
147 0           ExtUtils::Manifest::mkmanifest();
148 0           $self->safe_chdir($cwd);
149             }
150 0 0         my $fh = FileHandle->new($manifest)
151             or Carp::croak("Couldn't open $manifest: $!");
152 0           local($/) = "\n";
153 0           my $bundle_filename = $what;
154 0           $bundle_filename =~ s|Bundle.*/||;
155 0           my $bundle_unixpath;
156 0           while (<$fh>) {
157 0 0         next if /^\s*\#/;
158 0           my($file) = /(\S+)/;
159 0 0         if ($file =~ m|\Q$what\E$|) {
160 0           $bundle_unixpath = $file;
161             # return File::Spec->catfile($where,$bundle_unixpath); # bad
162 0           last;
163             }
164             # retry if she managed to have no Bundle directory
165 0 0         $bundle_unixpath = $file if $file =~ m|\Q$bundle_filename\E$|;
166             }
167 0 0         return File::Spec->catfile($where, split /\//, $bundle_unixpath)
168             if $bundle_unixpath;
169 0           Carp::croak("Couldn't find a Bundle file in $where");
170             }
171              
172             # needs to work quite differently from Module::inst_file because of
173             # cpan_home/Bundle/ directory and the possibility that we have
174             # shadowing effect. As it makes no sense to take the first in @INC for
175             # Bundles, we parse them all for $VERSION and take the newest.
176              
177             #-> sub CPAN::Bundle::inst_file ;
178             sub inst_file {
179 0     0 0   my($self) = @_;
180 0           my($inst_file);
181             my(@me);
182 0           @me = split /::/, $self->id;
183 0           $me[-1] .= ".pm";
184 0           my($incdir,$bestv);
185 0           foreach $incdir ($CPAN::Config->{'cpan_home'},@INC) {
186 0           my $parsefile = File::Spec->catfile($incdir, @me);
187 0 0         CPAN->debug("parsefile[$parsefile]") if $CPAN::DEBUG;
188 0 0         next unless -f $parsefile;
189 0           my $have = eval { MM->parse_version($parsefile); };
  0            
190 0 0         if ($@) {
191 0           $CPAN::Frontend->mywarn("Error while parsing version number in file '$parsefile'\n");
192             }
193 0 0 0       if (!$bestv || CPAN::Version->vgt($have,$bestv)) {
194 0           $self->{INST_FILE} = $parsefile;
195 0           $self->{INST_VERSION} = $bestv = $have;
196             }
197             }
198 0           $self->{INST_FILE};
199             }
200              
201             #-> sub CPAN::Bundle::inst_version ;
202             sub inst_version {
203 0     0 0   my($self) = @_;
204 0           $self->inst_file; # finds INST_VERSION as side effect
205 0           $self->{INST_VERSION};
206             }
207              
208             #-> sub CPAN::Bundle::rematein ;
209             sub rematein {
210 0     0 0   my($self,$meth) = @_;
211 0 0         $self->debug("self[$self] meth[$meth]") if $CPAN::DEBUG;
212 0           my($id) = $self->id;
213 0 0 0       Carp::croak( "Can't $meth $id, don't have an associated bundle file. :-(\n" )
214             unless $self->inst_file || $self->cpan_file;
215 0           my($s,%fail);
216 0           for $s ($self->contains) {
217 0 0         my($type) = $s =~ m|/| ? 'CPAN::Distribution' :
    0          
218             $s =~ m|^Bundle::| ? 'CPAN::Bundle' : 'CPAN::Module';
219 0 0         if ($type eq 'CPAN::Distribution') {
220 0           $CPAN::Frontend->mywarn(qq{
221             The Bundle }.$self->id.qq{ contains
222             explicitly a file '$s'.
223             Going to $meth that.
224             });
225 0           $CPAN::Frontend->mysleep(5);
226             }
227             # possibly noisy action:
228 0 0         $self->debug("type[$type] s[$s]") if $CPAN::DEBUG;
229 0           my $obj = $CPAN::META->instance($type,$s);
230 0           $obj->{reqtype} = $self->{reqtype};
231             # $obj->$meth();
232             # XXX should optional be based on whether bundle was optional? -- xdg, 2012-04-01
233             # A: Sure, what could demand otherwise? --andk, 2013-11-25
234 0           CPAN::Queue->queue_item(qmod => $obj->id, reqtype => $self->{reqtype}, optional => !$self->{mandatory});
235             }
236             }
237              
238             # If a bundle contains another that contains an xs_file we have here,
239             # we just don't bother I suppose
240             #-> sub CPAN::Bundle::xs_file
241             sub xs_file {
242 0     0 0   return 0;
243             }
244              
245             #-> sub CPAN::Bundle::force ;
246 0     0 0   sub fforce { shift->rematein('fforce',@_); }
247             #-> sub CPAN::Bundle::force ;
248 0     0 0   sub force { shift->rematein('force',@_); }
249             #-> sub CPAN::Bundle::notest ;
250 0     0 0   sub notest { shift->rematein('notest',@_); }
251             #-> sub CPAN::Bundle::get ;
252 0     0 0   sub get { shift->rematein('get',@_); }
253             #-> sub CPAN::Bundle::make ;
254 0     0 0   sub make { shift->rematein('make',@_); }
255             #-> sub CPAN::Bundle::test ;
256             sub test {
257 0     0 0   my $self = shift;
258             # $self->{badtestcnt} ||= 0;
259 0           $self->rematein('test',@_);
260             }
261             #-> sub CPAN::Bundle::install ;
262             sub install {
263 0     0 0   my $self = shift;
264 0           $self->rematein('install',@_);
265             }
266             #-> sub CPAN::Bundle::clean ;
267 0     0 0   sub clean { shift->rematein('clean',@_); }
268              
269             #-> sub CPAN::Bundle::uptodate ;
270             sub uptodate {
271 0     0 0   my($self) = @_;
272 0 0         return 0 unless $self->SUPER::uptodate; # we must have the current Bundle def
273 0           my $c;
274 0           foreach $c ($self->contains) {
275 0           my $obj = CPAN::Shell->expandany($c);
276 0 0         return 0 unless $obj->uptodate;
277             }
278 0           return 1;
279             }
280              
281             #-> sub CPAN::Bundle::readme ;
282             sub readme {
283 0     0 0   my($self) = @_;
284 0 0         my($file) = $self->cpan_file or $CPAN::Frontend->myprint(qq{
285             No File found for bundle } . $self->id . qq{\n}), return;
286 0 0         $self->debug("self[$self] file[$file]") if $CPAN::DEBUG;
287 0           $CPAN::META->instance('CPAN::Distribution',$file)->readme;
288             }
289              
290             1;