Debian Codegraph @

examples/cpanget

raw
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4
5 use Getopt::Lucid qw( :all );
6 use WWW::Mechanize;
7
8 my $CPAN_DIST_URL = 'http://search.cpan.org/dist/';
9
10 my @option_specs = (
11 Param('--dist|-d')->required,
12 Param('--version|-v'),
13 );
14
15 my $opt = Getopt::Lucid->getopt( \@option_specs );
16
17 my $dist_name = $opt->get_dist . $opt->get_version;
18
19 print "Looking for $dist_name...\n";
20
21 my $output_file = $dist_name . ".tar.gz";
22
23 my $mech = WWW::Mechanize->new( autocheck => 1 );
24 $mech->get( $CPAN_DIST_URL . $dist_name );
25
26 my $download_url = $mech->find_link( text_regex => qr/download/i );
27
28 die "Couldn't find $dist_name\n" unless $download_url;
29
30 my $filename = ( split q{/}, $download_url->url )[-1] || $output_file;
31
32 print "Downloading $filename\n";
33
34 $mech->get( $download_url->url_abs, ':content_file' => $filename);
35