#!/usr/local/bin/perl -w
######################################################################
# cpan-unwind -- 2005, Mike Schilli <m@perlmeister.com>
######################################################################
use strict;

my  $VERSION = "0.01";

use Pod::Usage;
use Log::Log4perl qw(:easy);
use CPAN::Unwind;
use Getopt::Std;
use LWP::Simple;
use File::Basename;

getopts("v", \my %opts);

Log::Log4perl->easy_init($opts{v} ? $DEBUG : $ERROR);

for(@ARGV) {
    my $agent = CPAN::Unwind->new();

    my $url = $agent->tarball_url($_);

    pod2usage "Cannot find url for $_" unless defined $url;

    my $file = basename($url);

    getstore($url, $file) or pod2usage "Download failed ($!)";

    print "$file ready.\n";
}

print "\n";

__END__

=head1 NAME

    cpan-download - Download a module's tarball from CPAN 

=head1 SYNOPSIS

    cpan-download Some::Module::Name

=head1 DESCRIPTION

C<cpan-download> determines a module's distribution tarball on CPAN
and downloads it.

=head1 EXAMPLES

    $ cpan-download Net::Amazon
    Net-Amazon-0.33.tar.gz ready.
    
=head1 LEGALESE

Copyright 2005 by Mike Schilli, all rights reserved.
This program is free software, you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 AUTHOR

2005, Mike Schilli <m@perlmeister.com>
