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