| 1 | package POE::Component::SmokeBox::Uploads::CPAN::Mini; | ||||||||||||||||||||||||||||
| 2 | 1 | $POE::Component::SmokeBox::Uploads::CPAN::Mini::VERSION = '1.02'; | |||||||||||||||||||||||||||
| 3 | #ABSTRACT: Obtain uploaded CPAN modules via a CPAN::Mini mirror | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use POE qw(Wheel::Run); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use CPAN::Mini; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub spawn { | ||||||||||||||||||||||||||
|
Subroutine
spawn: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 0 | my $package = shift; | |||||||||||||||||||||||||||
| 13 | 0 | my %opts = @_; | |||||||||||||||||||||||||||
| 14 | 0 | $opts{lc $_} = delete $opts{$_} for keys %opts; | |||||||||||||||||||||||||||
| 15 | 0 | ▶ | croak "$package requires an 'event' argument\n" unless $opts{event}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | croak "$package requires a 'remote' argument\n" unless $opts{remote}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | croak "$package requires a 'local' argument\n" unless $opts{local}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | $opts{trace} = 1; | |||||||||||||||||||||||||||
| 19 | 0 | $opts{errors} = 1; | |||||||||||||||||||||||||||
| 20 | 0 | ▶ | $opts{skip_perl} = 0 unless $opts{skip_perl}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $opts{force} = 1 unless defined $opts{force} and !$opts{force}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $opts{"force"} and not $opts{"force"}
MC/DC0%0/2
defined $opts{"force"} and not $opts{"force"}
defined $opts{"force"}
not $opts{"force"}
Truth table0%0/3
A and not(B)
A= defined $opts{"force"}B= not $opts{"force"}
| |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ( $opts{class} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | eval "require $opts{class}"; | |||||||||||||||||||||||||||
| 24 | 0 | ▶ | croak "$@\n" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | else { | ||||||||||||||||||||||||||||
| 27 | 0 | $opts{class} = 'CPAN::Mini'; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 0 | my $options = delete $opts{options}; | |||||||||||||||||||||||||||
| 30 | 0 | my $self = bless \%opts, $package; | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | $self->{session_id} = POE::Session->create( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | object_states => [ | ||||||||||||||||||||||||||||
| 33 | $self => { shutdown => '_shutdown', }, | ||||||||||||||||||||||||||||
| 34 | $self => [ qw(_start _update_mirror _sig_chld _wheel_stdout _wheel_stderr _wheel_close) ], | ||||||||||||||||||||||||||||
| 35 | ], | ||||||||||||||||||||||||||||
| 36 | heap => $self, | ||||||||||||||||||||||||||||
| 37 | ( ref($options) eq 'HASH' ? ( options => $options ) : () ), | ||||||||||||||||||||||||||||
| 38 | )->ID(); | ||||||||||||||||||||||||||||
| 39 | 0 | return $self; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub session_id { | ||||||||||||||||||||||||||
|
Subroutine
session_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 0 | return $_[0]->{session_id}; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub shutdown { | ||||||||||||||||||||||||||
|
Subroutine
shutdown: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 0 | $poe_kernel->post( $self->{session_id}, 'shutdown' ); | |||||||||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub _shutdown { | ||||||||||||||||||||||||||
|
Subroutine
_shutdown: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 53 | 0 | my ($kernel,$self) = @_[KERNEL,OBJECT]; | |||||||||||||||||||||||||||
| 54 | 0 | $kernel->alias_remove( $_ ) for $kernel->alias_list(); | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | $kernel->refcount_decrement( $self->{session_id}, __PACKAGE__ ) unless $self->{alias}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | $kernel->refcount_decrement( $self->{sender_id}, __PACKAGE__ ); | |||||||||||||||||||||||||||
| 57 | 0 | $self->{_shutdown} = 1; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | $self->{wheel}->kill() if $self->{wheel}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | return; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub _start { | ||||||||||||||||||||||||||
|
Subroutine
_start: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 63 | 0 | my ($kernel,$session,$sender,$self) = @_[KERNEL,SESSION,SENDER,OBJECT]; | |||||||||||||||||||||||||||
| 64 | 0 | $self->{session_id} = $session->ID(); | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $kernel == $sender and !$self->{session} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$kernel == $sender and not $self->{"session"}
MC/DC0%0/2
$kernel == $sender and not $self->{"session"}
$kernel == $sender
not $self->{"session"}
Truth table0%0/3
A and not(B)
A= $kernel == $senderB= not $self->{"session"}
| |||||||||||||||||||||||||||||
| 66 | 0 | croak "Not called from another POE session and 'session' wasn't set\n"; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 0 | my $sender_id; | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ( $self->{session} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ( my $ref = $kernel->alias_resolve( $self->{session} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | $sender_id = $ref->ID(); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||
| 74 | 0 | croak "Could not resolve 'session' to a valid POE session\n"; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||
| 78 | 0 | $sender_id = $sender->ID(); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 0 | $kernel->refcount_increment( $sender_id, __PACKAGE__ ); | |||||||||||||||||||||||||||
| 81 | 0 | $self->{sender_id} = $sender_id; | |||||||||||||||||||||||||||
| 82 | 0 | $kernel->yield( '_update_mirror' ); | |||||||||||||||||||||||||||
| 83 | 0 | return; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub _update_mirror { | ||||||||||||||||||||||||||
|
Subroutine
_update_mirror: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 87 | 0 | my ($kernel,$self) = @_[KERNEL,OBJECT]; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | return if $self->{wheel}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | $self->{buffer} = []; | |||||||||||||||||||||||||||
| 90 | 0 | $self->{_errors} = []; | |||||||||||||||||||||||||||
| 91 | $self->{wheel} = POE::Wheel::Run->new( | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | Program => sub { $self->{class}->update_mirror( @_ ); }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | ProgramArgs => [ map { defined $self->{$_} ? ( $_ => $self->{$_} ) : () } qw(remote local skip_perl dirmode force trace errors skip_cleanup) ], | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | CloseEvent => '_wheel_close', | ||||||||||||||||||||||||||||
| 95 | ErrorEvent => '_wheel_close', | ||||||||||||||||||||||||||||
| 96 | StdoutEvent => '_wheel_stdout', | ||||||||||||||||||||||||||||
| 97 | StderrEvent => '_wheel_stderr', | ||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||
| 99 | 0 | $kernel->sig_child( $self->{wheel}->PID(), '_sig_chld' ); | |||||||||||||||||||||||||||
| 100 | 0 | return; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub _sig_chld { | ||||||||||||||||||||||||||
|
Subroutine
_sig_chld: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 104 | 0 | my($kernel,$self,$sig,$pid,$exit_val) = @_[KERNEL,OBJECT,ARG0..ARG2]; | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | return $kernel->sig_handled() if $self->{_shutdown}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | my $data = { }; | |||||||||||||||||||||||||||
| 107 | 0 | for ( @{ $self->{buffer} } ) { | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ( /^cleaning/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | my $path = ( split /\s+/ )[1]; | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | next unless $path =~ /\.(tar\.gz|tgz|tar\.bz2|zip)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | my ($short) = $path =~ m!authors/id/(.+)$!i; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | next unless $short; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | push @{ $data->{cleaned} }, $short; | |||||||||||||||||||||||||||
| 114 | 0 | next; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 0 | my $line = ( split /\s+/ )[0]; | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | next unless $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | next unless $line =~ /^authors/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | next unless $line =~ /\.(tar\.gz|tgz|tar\.bz2|zip)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | $line =~ s!authors/id/!!; | |||||||||||||||||||||||||||
| 121 | 0 | push @{ $data->{uploads} }, $line; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $data->{buffer} = delete $self->{buffer} if $self->{dump}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $data->{errors} = delete $self->{_errors} if $self->{dump}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | $data->{status} = $exit_val; | |||||||||||||||||||||||||||
| 126 | 0 | $kernel->post( $self->{sender_id}, $self->{event}, $data ); | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | $kernel->delay( '_update_mirror', $self->{interval} || 14400 ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'interval'} || 14400
MC/DC0%0/1
$self->{'interval'} || 14400
$self->{'interval'}
Truth table0%0/2
A
A= $self->{'interval'}
| |||||||||||||||||||||||||||||
| 128 | 0 | return $kernel->sig_handled(); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub _wheel_close { | ||||||||||||||||||||||||||
|
Subroutine
_wheel_close: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 132 | 0 | delete $_[OBJECT]->{wheel}; | |||||||||||||||||||||||||||
| 133 | 0 | return; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub _wheel_stdout { | ||||||||||||||||||||||||||
|
Subroutine
_wheel_stdout: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 137 | 0 | my ($self,$input) = @_[OBJECT,ARG0]; | |||||||||||||||||||||||||||
| 138 | 0 | push @{ $self->{buffer} }, $input; | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | warn $input, "\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | return; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | sub _wheel_stderr { | ||||||||||||||||||||||||||
|
Subroutine
_wheel_stderr: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 144 | 0 | my ($self,$input) = @_[OBJECT,ARG0]; | |||||||||||||||||||||||||||
| 145 | 0 | push @{ $self->{_errors} }, $input; | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | warn $input, "\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | return; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 1 | 1; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | __END__ | ||||||||||||||||||||||||||||