| 1 | package CPAN::Recent::Uploads; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | $CPAN::Recent::Uploads::VERSION = '0.16'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | #ABSTRACT: Find the distributions recently uploaded to CPAN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use YAML::XS (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use CPAN::Recent::Uploads::Retriever; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | my $MIRROR = 'http://www.cpan.org/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | my @times = qw(1h 6h 1d 1W 1M 1Q 1Y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | my %periods = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | '1h' => (60*60), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | '6h' => (60*60*6), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | '1d' => (60*60*24), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | '1W' => (60*60*24*7), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | '1M' => (60*60*24*30), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | '1Q' => (60*60*24*90), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | '1Y' => (60*60*24*365.25), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | sub recent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recent: called CC=19 SCAR=34.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | my $epoch = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | $epoch = shift if $epoch and eval { $epoch->isa(__PACKAGE__) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$epoch and eval {
do {
$epoch->isa(__PACKAGE__)
}
}
MC/DC0%0/2
$epoch and eval {
do {
$epoch->isa(__PACKAGE__)
}
}
$epoch
eval {
do {
$epoch->isa(__PACKAGE__)
}
}
Truth table33%1/3
A and B
A= $epochB= eval {
do {
$epoch->isa(__PACKAGE__)
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $epoch = ( time() - ( 7 * 24 * 60 * 60 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | unless $epoch and $epoch =~ /^\d+$/ and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | $epoch <= time() and $epoch >= ( time() - $periods{'1Y'} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$epoch and $epoch =~ /^\d+$/ and $epoch <= time and $epoch >= time - $periods{"1Y"}
$epoch and $epoch =~ /^\d+$/ and $epoch <= time
$epoch and $epoch =~ /^\d+$/
MC/DC0%0/4
$epoch and $epoch =~ /^\d+$/ and $epoch <= time and $epoch >= time - $periods{"1Y"}
$epoch
$epoch =~ /^\d+$/
$epoch <= time
$epoch >= time - $periods{"1Y"}
Truth table20%1/5
A and B and C and D
A= $epochB= $epoch =~ /^\d+$/C= $epoch <= timeD= $epoch >= time - $periods{"1Y"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | my $period = _period_from_epoch( $epoch ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | my $mirror = shift || $MIRROR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $MIRROR
MC/DC0%0/2
shift() || $MIRROR
shift()
$MIRROR
Truth table33%1/3
A || B
A= shift()B= $MIRROR
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | OUTER: foreach my $foo ( @times ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my $yaml = CPAN::Recent::Uploads::Retriever->retrieve( time => $foo, mirror => $mirror ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | my @yaml; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | eval { @yaml = YAML::XS::Load( $yaml ); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | croak "Unable to process YAML\n" unless @yaml; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $record = shift @yaml; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | die unless $record; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | RECENT: foreach my $recent ( reverse @{ $record->{recent} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 17 | ▶ | next RECENT unless $recent->{path} =~ /\.(tar\.gz|tgz|tar\.bz2|zip)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | if ( $recent->{type} eq 'new' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ( my $bar = $recent->{path} ) =~ s#^id/##; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | ▶ | next RECENT if $recent->{epoch} < $epoch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | my @parts = split m!/!, $bar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | next RECENT if $parts[3] =~ m!Perl6!i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | $data{ $bar } = $recent->{epoch}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ( my $bar = $recent->{path} ) =~ s#^id/##; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | delete $data{ $bar } if exists $data{ $foo }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | last if $foo eq $period; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | return \%data unless wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | return sort { $data{$a} <=> $data{$b} } keys %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub _period_from_epoch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_period_from_epoch: called CC=4 SCAR=15.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | my $epoch = shift || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | foreach my $period ( @times ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | return $period if ( time() - $periods{$period} ) < $epoch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | q[Whats uploaded, Doc?]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||