File Coverage

blib/lib/CPAN/Bundle.pm
Criterion Covered Total %
statement 9 166 5.4
branch 0 92 0.0
condition 0 25 0.0
subroutine 3 23 13.0
pod 0 20 0.0
total 12 326 3.6


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