#!/usr/bin/env perl
use strict;
use warnings;
use File::Temp;
use Path::Class;
use Package::Locator;
use LWP::UserAgent;
use Pinto::SpecFactory;
use Dist::Metadata 0.923;
#-----------------------------------------------------------------------------
# Copyright 2013 Jeffrey Ryan Thalhammer <jeff@stratopan.com>
#-----------------------------------------------------------------------------
exit run(@ARGV) if not caller;
#-----------------------------------------------------------------------------
sub run {
my $target = shift or die 'Must specify a target';
my $spec = Pinto::SpecFactory->make_spec($target);
my $type = $target =~ m{/} ? 'distribution' : 'package';
my $locator = Package::Locator->new;
my $url = $locator->locate($type => $target) or die "Can't find $target";
my $tempdir = File::Temp->newdir;
my $local = file($tempdir, file($url->path)->basename);
my $ua = LWP::UserAgent->new;
my $resp = $ua->mirror($url => $local);
die "Mirror failed " . $resp->content if not $resp->is_success;
my $dm = Dist::Metadata->new(file => $local);
my $provides = $dm->provides;
for my $pkg ( sort keys %{$provides} ) {
print "$pkg => $provides->{$pkg}->{version}\n";
}
return 0;
}
#-----------------------------------------------------------------------------
1;
__END__
=head1 NAME
provides - Fetch a distribution and report the package index
=head1 SYNOPSIS
provides Module::Name
provides AUTHOR/Dist-Name-0.01.tar.gz
=head1 DESCRIPTION
This utility fetches a distribution from the CPAN and reports the
package index. The results should match what PAUSE would produce.
=head1 ARGUMENTS
The sole (mandatory) argument is a L<package spec|Pinto::PackageSpec>
or L<distribution spec|Pinto::DistributionSpec>.
=head1 AUTHOR
Jeffrey Ryan Thalhammer <thaljef@cpan.org>
=head1 COPYRIGHT
Imaginative Software Systems, 2012
=cut