| 1 | # Declare our package | ||||||||||||||||||||||||||||
| 2 | package POE::Devel::Benchmarker::GetPOEdists; | ||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # Initialize our version | ||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | $VERSION = '0.05'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # auto-export the only sub we have | ||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use base qw( Exporter ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | our @EXPORT = qw( getPOEdists ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # import the helper modules | ||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use HTML::LinkExtor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use URI::URL; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Archive::Tar; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # autoflush, please! | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | STDOUT->autoflush( 1 ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # actually retrieves the dists! | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub getPOEdists { | ||||||||||||||||||||||||||
|
Subroutine
getPOEdists: not called CC=17 SCAR=57.2
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | # should we debug? | ||||||||||||||||||||||||||||
| 26 | 0 | my $debug = shift; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # okay, should we change directory? | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ( -d 'poedists' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ( $debug ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | print "[GETPOEDISTS] chdir( 'poedists' )\n"; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ( ! chdir( 'poedists' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | die "Unable to chdir to 'poedists' dir: $!"; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( $debug ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | print "[GETPOEDISTS] downloading to current directory\n"; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # set the default URL | ||||||||||||||||||||||||||||
| 44 | 0 | my $url = "http://backpan.cpan.org/authors/id/R/RC/RCAPUTO/"; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # create our objects | ||||||||||||||||||||||||||||
| 47 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||
| 48 | 0 | my $p = HTML::LinkExtor->new; | |||||||||||||||||||||||||||
| 49 | 0 | my $tar = Archive::Tar->new; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # Request document and parse it as it arrives | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | print "Getting $url via LWP\n" if $debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | my $res = $ua->request( HTTP::Request->new( GET => $url ), | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub { $p->parse( $_[0] ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 55 | 0 | ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # did we successfully download? | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( $res->is_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | die "unable to download directory index on BACKPAN: " . $res->status_line; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # Download every one! | ||||||||||||||||||||||||||||
| 63 | 0 | foreach my $link ( $p->links ) { | |||||||||||||||||||||||||||
| 64 | # skip IMG stuff | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $link->[0] eq 'a' and $link->[1] eq 'href' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$link->[0] eq "a" and $link->[1] eq "href"
MC/DC0%0/2
$link->[0] eq "a" and $link->[1] eq "href"
$link->[0] eq "a"
$link->[1] eq "href"
Truth table0%0/3
A and B
A= $link->[0] eq "a"B= $link->[1] eq "href"
| |||||||||||||||||||||||||||||
| 66 | # get the actual POE dists! | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( $link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/
MC/DC0%0/2
$link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/
$link->[2] =~ /^POE\-\d/
$link->[2] =~ /\.tar\.gz$/
Truth table0%0/3
A and B
A= $link->[2] =~ /^POE\-\d/B= $link->[2] =~ /\.tar\.gz$/
| |||||||||||||||||||||||||||||
| 68 | # download the tarball! | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | print "Mirroring $link->[2] via LWP\n" if $debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] ); | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( $mirror_result->is_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | warn "unable to mirror $link->[2]: " . $mirror_result->status_line; | |||||||||||||||||||||||||||
| 73 | 0 | next; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # did we already untar this one? | ||||||||||||||||||||||||||||
| 77 | 0 | my $dir = $link->[2]; | |||||||||||||||||||||||||||
| 78 | 0 | $dir =~ s/\.tar\.gz$//; | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ( ! -d $dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | # extract it! | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | print "Extracting $link->[2] via Tar\n" if $debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } ); | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ( $files == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | warn "unable to extract $link->[2]"; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | return; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 1 | 1; | |||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||