Benchmarker/GetPOEdists.pm

filter: Statementstmt 48.4% 31 / 64 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 81.8% 9 / 11 Podpod 100% 1 / 1 totaltotal 36.6% 41 / 112 CC 17 SCAR 52.6
CC
17
Cov
32%
getPOEdists
306.0
__ANON__
2.0
BEGIN
1.0
CRAP 193.1
« Benchmarker/Imager.pm ↑ Summary Benchmarker/Utils.pm »
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
BranchTrueFalseTotal
if (-d 'poedists') { } 0 0 0
30 0 ▶ if ( $debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
31 0 print "[GETPOEDISTS] chdir( 'poedists' )\n";
32 }
33  
34 0 ▶ if ( ! chdir( 'poedists' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir "poedists") 0 0 0
35 0 die "Unable to chdir to 'poedists' dir: $!";
36 }
37 } else {
38 0 ▶ if ( $debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
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
BranchTrueFalseTotal
if $debug 0 0 0
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
BranchTrueFalseTotal
if ($res->is_error) 0 0 0
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
BranchTrueFalseTotal
if ($link->[0] eq "a" and $link->[1] eq "href") 0 0 0
Condition0%0/3
$link->[0] eq "a" and $link->[1] eq "href"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
66 # get the actual POE dists!
67 0 ▶ if ( $link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/) 0 0 0
Condition0%0/3
$link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/
!ll&&!rl&&r
000
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$/
ABresult
0X0
100
111
68 # download the tarball!
69 0 ▶ print "Mirroring $link->[2] via LWP\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
70 0 my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] );
71 0 ▶ if ( $mirror_result->is_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mirror_result->is_error) 0 0 0
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
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
80 # extract it!
81 0 ▶ print "Extracting $link->[2] via Tar\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
82 0 my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } );
83 0 ▶ if ( $files == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($files == 0) 0 0 0
84 0 warn "unable to extract $link->[2]";
85 }
86 }
87 }
88 }
89 }
90  
91 0 return;
92 }
93  
94 1 1;
95 __END__
« Benchmarker/Imager.pm ↑ Summary Benchmarker/Utils.pm »