| 1 | package POE::Component::CPAN::SQLite::Info; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use CPAN::SQLite::Info; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use POE (qw( Wheel::Run Filter::Reference Filter::Line)); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub spawn { | ||||||||||||||||||||||||||
|
Subroutine
spawn: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 0 | my $package = shift; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | croak "Even number of arguments must be passed to $package" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | if @_ & 1; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | $params{ lc $_ } = delete $params{ $_ } for keys %params; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | delete $params{options} | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | unless ref $params{options} eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | unless ( exists $params{path} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | $params{path} = 'cpan_sqlite_info/'; | |||||||||||||||||||||||||||
| 29 | warn "Warning: No `path` parameter was specified\n" | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if $params{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | unless ( exists $params{mirror} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | $params{mirror} = 'http://cpan.perl.org'; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $self = bless \%params, $package; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | $self->{session_id} = POE::Session->create( | ||||||||||||||||||||||||||||
| 40 | object_states => [ | ||||||||||||||||||||||||||||
| 41 | $self => { | ||||||||||||||||||||||||||||
| 42 | freshen => '_freshen', | ||||||||||||||||||||||||||||
| 43 | fetch_info => '_fetch_info', | ||||||||||||||||||||||||||||
| 44 | shutdown => '_shutdown', | ||||||||||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||||||||||
| 46 | $self => [ | ||||||||||||||||||||||||||||
| 47 | qw( | ||||||||||||||||||||||||||||
| 48 | _child_error | ||||||||||||||||||||||||||||
| 49 | _child_close | ||||||||||||||||||||||||||||
| 50 | _child_stderr | ||||||||||||||||||||||||||||
| 51 | _child_stdout | ||||||||||||||||||||||||||||
| 52 | _sig_chld | ||||||||||||||||||||||||||||
| 53 | _start | ||||||||||||||||||||||||||||
| 54 | ) | ||||||||||||||||||||||||||||
| 55 | ], | ||||||||||||||||||||||||||||
| 56 | ], | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | ( exists $params{options} ? ( options => $params{options} ) : () ), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | )->ID; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return $self; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub _start { | ||||||||||||||||||||||||||
|
Subroutine
_start: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 64 | 0 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||||||||||||||||
| 65 | 0 | $self->{session_id} = $_[SESSION]->ID(); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( $self->{alias} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | $kernel->alias_set( $self->{alias} ); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||
| 71 | 0 | $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $self->{wheel} = POE::Wheel::Run->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | Program => \&_wheel, | ||||||||||||||||||||||||||||
| 76 | ErrorEvent => '_child_error', | ||||||||||||||||||||||||||||
| 77 | CloseEvent => '_child_close', | ||||||||||||||||||||||||||||
| 78 | StderrEvent => '_child_stderr', | ||||||||||||||||||||||||||||
| 79 | StdoutEvent => '_child_stdout', | ||||||||||||||||||||||||||||
| 80 | StdioFilter => POE::Filter::Reference->new, | ||||||||||||||||||||||||||||
| 81 | StderrFilter => POE::Filter::Line->new, | ||||||||||||||||||||||||||||
| 82 | ( $^O eq 'MSWin32' ? ( CloseOnCall => 0 ) : ( CloseOnCall => 1 ) ), | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | $kernel->call('shutdown') | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | unless $self->{wheel}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | $kernel->sig_child( $self->{wheel}->PID, '_sig_chld' ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub _sig_chld { | ||||||||||||||||||||||||||
|
Subroutine
_sig_chld: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 92 | 0 | $poe_kernel->sig_handled; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub _child_close { | ||||||||||||||||||||||||||
|
Subroutine
_child_close: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 96 | 0 | my ( $kernel, $self, $wheel_id ) = @_[ KERNEL, OBJECT, ARG0 ]; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | warn "_child_close called (@_[ARG0..$#_])\n" | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | delete $self->{wheel}; | |||||||||||||||||||||||||||
| 102 | $kernel->yield('shutdown') | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | unless $self->{shutdown}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | undef; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub _child_error { | ||||||||||||||||||||||||||
|
Subroutine
_child_error: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 109 | 0 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||||||||||||||||
| 110 | warn "_child_error called (@_[ARG0..$#_])\n" | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | delete $self->{wheel}; | |||||||||||||||||||||||||||
| 114 | $kernel->yield('shutdown') | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | unless $self->{shutdown}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | undef; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub _child_stderr { | ||||||||||||||||||||||||||
|
Subroutine
_child_stderr: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 121 | 0 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||||||||||||||||
| 122 | warn "_child_stderr: $_[ARG0]\n" | ||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | undef; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub _child_stdout { | ||||||||||||||||||||||||||
|
Subroutine
_child_stdout: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 129 | 0 | my ( $kernel, $self, $input ) = @_[ KERNEL, OBJECT, ARG0 ]; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | my $session = delete $input->{sender}; | |||||||||||||||||||||||||||
| 132 | 0 | my $event = delete $input->{event}; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | $kernel->post( $session, $event, $input ); | |||||||||||||||||||||||||||
| 135 | 0 | $kernel->refcount_decrement( $session => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | undef; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub shutdown { | ||||||||||||||||||||||||||
|
Subroutine
shutdown: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 142 | 0 | $poe_kernel->post( $self->{session_id} => 'shutdown' ); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub _shutdown { | ||||||||||||||||||||||||||
|
Subroutine
_shutdown: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 146 | 0 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||||||||||||||||
| 147 | 0 | $kernel->alarm_remove_all; | |||||||||||||||||||||||||||
| 148 | 0 | $kernel->alias_remove( $_ ) for $kernel->alias_list; | |||||||||||||||||||||||||||
| 149 | $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ ) | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | unless $self->{alias}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | $self->{shutdown} = 1; | |||||||||||||||||||||||||||
| 153 | $self->{wheel}->shutdown_stdin | ||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if $self->{wheel}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub session_id { | ||||||||||||||||||||||||||
|
Subroutine
session_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | 0 | return $_[0]->{session_id}; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub freshen { | ||||||||||||||||||||||||||
|
Subroutine
freshen: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 163 | 0 | $poe_kernel->post( $self->{session_id} => 'freshen' => @_ ); | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub fetch_info { | ||||||||||||||||||||||||||
|
Subroutine
fetch_info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 168 | 0 | $poe_kernel->post( $self->{session_id} => 'fetch_info' => @_ ); | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub _fetch_info { | ||||||||||||||||||||||||||
|
Subroutine
_fetch_info: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 172 | 0 | my ( $kernel, $self, $args )= @_[ KERNEL, OBJECT, ARG0 ]; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | my $sender = $_[SENDER]->ID; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | return | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if $self->{shutdown}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | $args->{ lc $_ } = delete $args->{ $_ } | ||||||||||||||||||||||||||||
| 180 | 0 | for grep { !/^_/ } keys %{ $args }; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ( $args->{session} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ( my $ref = $kernel->alias_resolve( $args->{session} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | $args->{sender} = $ref->ID; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | else { | ||||||||||||||||||||||||||||
| 188 | 0 | warn "Could not resolve `session` parameter to a " | |||||||||||||||||||||||||||
| 189 | . "valid POE session. Aborting..."; | ||||||||||||||||||||||||||||
| 190 | 0 | return; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | else { | ||||||||||||||||||||||||||||
| 194 | 0 | $args->{sender} = $sender; | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | ▶ | unless ( exists $args->{path} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 0 | $args->{path} = $self->{path}; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | delete $args->{freshen}; # to make sure wheel doesn't freshen by mistake | |||||||||||||||||||||||||||
| 202 | 0 | $kernel->refcount_increment( $args->{sender} => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 203 | 0 | $self->{wheel}->put( $args ); | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | undef; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | # yes, yes, the almost identical sub{} to the above one.... | ||||||||||||||||||||||||||||
| 210 | # fighting POE's "magik" in here is beyond me... | ||||||||||||||||||||||||||||
| 211 | # .. note to self: figure out wtf is going on. | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub _freshen { | ||||||||||||||||||||||||||
|
Subroutine
_freshen: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 214 | 0 | my ( $kernel, $self, $args )= @_[ KERNEL, OBJECT, ARG0 ]; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | my $sender = $_[SENDER]->ID; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | return | ||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if $self->{shutdown}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | $args->{ lc $_ } = delete $args->{ $_ } | ||||||||||||||||||||||||||||
| 222 | 0 | for grep { !/^_/ } keys %{ $args }; | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if ( $args->{session} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ( my $ref = $kernel->alias_resolve( $args->{session} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 0 | $args->{sender} = $ref->ID; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | else { | ||||||||||||||||||||||||||||
| 230 | 0 | warn "Could not resolve `session` parameter to a " | |||||||||||||||||||||||||||
| 231 | . "valid POE session. Aborting..."; | ||||||||||||||||||||||||||||
| 232 | 0 | return; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | else { | ||||||||||||||||||||||||||||
| 236 | 0 | $args->{sender} = $sender; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 0 | ▶ | unless ( exists $args->{path} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 0 | $args->{path} = $self->{path}; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | ▶ | unless ( exists $args->{mirror} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | $args->{mirror} = $self->{mirror}; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | unless ( exists $args->{ua_args}{timeout} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | 0 | $args->{ua_args}{timeout} = 30; | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | $args->{freshen} = 1; # for the wheel to know what to do. | |||||||||||||||||||||||||||
| 252 | 0 | $kernel->refcount_increment( $args->{sender} => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 253 | 0 | $self->{wheel}->put( $args ); | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 0 | undef; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub _wheel { | ||||||||||||||||||||||||||
|
Subroutine
_wheel: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if ( $^O eq 'MSWin32' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 0 | binmode STDIN; | |||||||||||||||||||||||||||
| 261 | 0 | binmode STDOUT; | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 0 | my $raw; | |||||||||||||||||||||||||||
| 265 | 0 | my $size = 4096; | |||||||||||||||||||||||||||
| 266 | 0 | my $filter = POE::Filter::Reference->new; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | ▶ | while ( sysread STDIN, $raw, $size ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 0 | my $requests = $filter->get( [ $raw ] ); | |||||||||||||||||||||||||||
| 270 | 0 | foreach my $req_ref ( @$requests ) { | |||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ( exists $req_ref->{freshen} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 0 | eval { _fetch_data_files( $req_ref ); }; | |||||||||||||||||||||||||||
| 274 | 0 | ▶ | $req_ref->{freshen_error} = $@ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | if $@; | ||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | else { | ||||||||||||||||||||||||||||
| 278 | 0 | _populate_info( $req_ref ); | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 0 | my $response = $filter->put( [ $req_ref ] ); | |||||||||||||||||||||||||||
| 282 | 0 | print STDOUT @$response; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | ▶ | sub _populate_info { | ||||||||||||||||||||||||||
|
Subroutine
_populate_info: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 288 | 0 | my $req_ref = shift; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 0 | my $info = CPAN::SQLite::Info->new( CPAN => $req_ref->{path} ); | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | # stupid ->fetch_info prints crap to STDOUT effectively | ||||||||||||||||||||||||||||
| 293 | # breaking Wheel ~_~ | ||||||||||||||||||||||||||||
| 294 | { | ||||||||||||||||||||||||||||
| 295 | 0 | local *STDOUT; | |||||||||||||||||||||||||||
| 296 | 0 | open STDOUT, '>', File::Spec->devnull; | |||||||||||||||||||||||||||
| 297 | 0 | $info->fetch_info; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | @$req_ref{ qw( dists mods auths ) } | ||||||||||||||||||||||||||||
| 301 | 0 | = @$info{ qw( dists mods auths ) }; | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 0 | undef; | |||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 0 | ▶ | sub _fetch_data_files { | ||||||||||||||||||||||||||
|
Subroutine
_fetch_data_files: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 307 | 0 | my $req_ref = shift; | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 0 | my $path = $req_ref->{path}; | |||||||||||||||||||||||||||
| 310 | 0 | my $mod_dir = File::Spec->catdir( $path, 'modules/' ); | |||||||||||||||||||||||||||
| 311 | 0 | my $auth_dir = File::Spec->catdir( $path, 'authors/' ); | |||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 0 | foreach my $dir ( $path, $mod_dir, $auth_dir ) { | |||||||||||||||||||||||||||
| 314 | 0 | ▶ | unless ( -e $dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | 0 | ▶ | mkdir $dir | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | or die "Failed to create directory `$dir` ($!)\n"; | ||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 0 | ▶ | my $ua = LWP::UserAgent->new( %{ $req_ref->{ua_args} || {} } ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$req_ref->{'ua_args'} || {}
MC/DC0%0/1
$req_ref->{'ua_args'} || {}
$req_ref->{'ua_args'}
Truth table0%0/2
A
A= $req_ref->{'ua_args'}
| |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 0 | my $mirror = $req_ref->{mirror}; | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | @{ $req_ref->{uris} }{ qw(modlist packages authors) } = ( | |||||||||||||||||||||||||||
| 325 | URI->new( $mirror ), | ||||||||||||||||||||||||||||
| 326 | URI->new( $mirror ), | ||||||||||||||||||||||||||||
| 327 | URI->new( $mirror ), | ||||||||||||||||||||||||||||
| 328 | ); | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 0 | my $uris_ref = $req_ref->{uris}; | |||||||||||||||||||||||||||
| 331 | 0 | $uris_ref->{modlist }->path('/modules/03modlist.data.gz'); | |||||||||||||||||||||||||||
| 332 | 0 | $uris_ref->{packages}->path('/modules/02packages.details.txt.gz'); | |||||||||||||||||||||||||||
| 333 | 0 | $uris_ref->{authors }->path('/authors/01mailrc.txt.gz'); | |||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 0 | $req_ref->{files}{ modlist } = File::Spec->catfile( | |||||||||||||||||||||||||||
| 336 | $mod_dir, | ||||||||||||||||||||||||||||
| 337 | '03modlist.data.gz', | ||||||||||||||||||||||||||||
| 338 | ); | ||||||||||||||||||||||||||||
| 339 | 0 | $req_ref->{files}{ packages } = File::Spec->catfile( | |||||||||||||||||||||||||||
| 340 | $mod_dir, | ||||||||||||||||||||||||||||
| 341 | '02packages.details.txt.gz', | ||||||||||||||||||||||||||||
| 342 | ); | ||||||||||||||||||||||||||||
| 343 | 0 | $req_ref->{files}{ authors } = File::Spec->catfile( | |||||||||||||||||||||||||||
| 344 | $auth_dir, | ||||||||||||||||||||||||||||
| 345 | '01mailrc.txt.gz', | ||||||||||||||||||||||||||||
| 346 | ); | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 0 | keys %{ $req_ref->{uris} }; | |||||||||||||||||||||||||||
| 349 | 0 | ▶ | while ( my ( $name, $uri ) = each %{ $req_ref->{uris} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | my $response = $ua->mirror( | ||||||||||||||||||||||||||||
| 352 | $uri, | ||||||||||||||||||||||||||||
| 353 | 0 | $req_ref->{files}{ $name }, | |||||||||||||||||||||||||||
| 354 | ); | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | # Modern LWP::UserAgent attaches a `response_done` handler holding a | ||||||||||||||||||||||||||||
| 357 | # CODE ref onto the HTTP::Response returned by mirror(). This response | ||||||||||||||||||||||||||||
| 358 | # is sent back to the parent session through POE::Filter::Reference, | ||||||||||||||||||||||||||||
| 359 | # which serialises with Storable, and Storable dies on CODE refs | ||||||||||||||||||||||||||||
| 360 | # ("Can't store CODE items"), killing the child wheel and hanging the | ||||||||||||||||||||||||||||
| 361 | # whole freshen. Drop the handlers slot before storing the response; | ||||||||||||||||||||||||||||
| 362 | # only its status is ever read downstream, and status_line() and | ||||||||||||||||||||||||||||
| 363 | # is_success() keep working. | ||||||||||||||||||||||||||||
| 364 | delete $response->{handlers} | ||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ref $response eq 'HTTP::Response'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 0 | $req_ref->{requests}{ $name } = $response; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 0 | my $requests_ref = $req_ref->{requests}; | |||||||||||||||||||||||||||
| 370 | # check for fetch errors, but do not consider 304 an error, | ||||||||||||||||||||||||||||
| 371 | # we are fine with that since it indicates that file is good | ||||||||||||||||||||||||||||
| 372 | # enough for that we need it. | ||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $requests_ref->{$name}->is_success and $requests_ref->{$name}->status_line ne "304 Not Modified"
MC/DC0%0/2
not $requests_ref->{$name}->is_success and $requests_ref->{$name}->status_line ne "304 Not Modified"
not $requests_ref->{$name}->is_success
$requests_ref->{$name}->status_line ne "304 Not Modified"
Truth table0%0/3
not(A) and B
A= not $requests_ref->{$name}->is_successB= $requests_ref->{$name}->status_line ne "304 Not Modified"
| |||||||||||||||||||||||||||||
| 374 | !$requests_ref->{ $name }->is_success | ||||||||||||||||||||||||||||
| 375 | and $requests_ref->{ $name }->status_line ne '304 Not Modified' | ||||||||||||||||||||||||||||
| 376 | ) { | ||||||||||||||||||||||||||||
| 377 | $req_ref->{freshen_errors}{ $name } | ||||||||||||||||||||||||||||
| 378 | 0 | = $req_ref->{requests}{ $name }->status_line; | |||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 0 | $req_ref->{freshen_error} = 'fetch'; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 0 | undef; | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | 1 | 1; | |||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | __END__ | ||||||||||||||||||||||||||||