X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCPANPLUS%2FBackend.pm;h=1431ce0cd984c0e485ce1922c17e48bbd1711d85;hb=a0995fd479a7e2e390969122c63171250070a660;hp=fb71fcf8df68111eda6ceaba4e6495b091220e5d;hpb=1c82faa77213de8d77d404d205d3731944559f65;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/CPANPLUS/Backend.pm b/lib/CPANPLUS/Backend.pm index fb71fcf..1431ce0 100644 --- a/lib/CPANPLUS/Backend.pm +++ b/lib/CPANPLUS/Backend.pm @@ -14,6 +14,7 @@ use CPANPLUS::Backend::RV; use FileHandle; use File::Spec (); use File::Spec::Unix (); +use File::Basename (); use Params::Check qw[check]; use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext'; @@ -405,7 +406,7 @@ for my $func (qw[fetch extract install readme files distributions]) { =pod -=head2 $mod_obj = $cb->parse_module( module => $modname|$distname|$modobj|URI ) +=head2 $mod_obj = $cb->parse_module( module => $modname|$distname|$modobj|URI|PATH ) C tries to find a C object that matches your query. Here's a list of examples you could give to @@ -429,6 +430,12 @@ C; =item file:///tmp/Text-Bastardize-1.06.tar.gz +=item /tmp/Text-Bastardize-1.06 + +=item ./Text-Bastardize-1.06 + +=item . + =back These items would all come up with a C object for @@ -436,6 +443,11 @@ C. The ones marked explicitly as being version 1.06 would give back a C object of that version. Even if the version on CPAN is currently higher. +The last three are examples of PATH resolution. In the first, we supply +an absolute path to the unwrapped distribution. In the second the +distribution is relative to the current working directory. +In the third, we will use the current working directory. + If C is unable to actually find the module you are looking for in its module tree, but you supplied it with an author, module and version part in a distribution name or URI, it will create a fake @@ -480,6 +492,42 @@ sub parse_module { return $maybe if IS_MODOBJ->( module => $maybe ); } + ### Special case arbitary file paths such as '.' etc. + if (-d File::Spec->rel2abs($mod) ) { + my $dir = File::Spec->rel2abs($mod); + my $parent = File::Spec->rel2abs( File::Spec->catdir( $dir, '..' ) ); + + my $dist = $mod = File::Basename::basename($dir); + $dist .= '-0' unless $dist =~ /\-[0-9._]+$/; + $dist .= '.tar.gz' unless $dist =~ /\.[A-Za-z]+$/; + + my $modobj = CPANPLUS::Module::Fake->new( + module => $mod, + version => 0, + package => $dist, + path => $parent, + author => CPANPLUS::Module::Author::Fake->new + ); + + ### better guess for the version + $modobj->version( $modobj->package_version ) + if defined $modobj->package_version; + + ### better guess at module name, if possible + if ( my $pkgname = $modobj->package_name ) { + $pkgname =~ s/-/::/g; + + ### no sense replacing it unless we changed something + $modobj->module( $pkgname ) + if ($pkgname ne $modobj->package_name) || $pkgname !~ /-/; + } + + $modobj->status->fetch( $parent ); + $modobj->status->extract( $dir ); + $modobj->get_installer_type; + return $modobj; + } + ### ok, so it looks like a distribution then? my @parts = split '/', $mod; my $dist = pop @parts;