line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Component::WWW::DoingItWrongCom::RandImage; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
342639
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use POE qw( Filter::Reference Filter::Line Wheel::Run ); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
9
|
|
9
|
1
|
|
|
1
|
|
586
|
use WWW::DoingItWrongCom::RandImage; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
10
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1569
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub spawn { |
13
|
0
|
|
|
0
|
1
|
|
my $package = shift; |
14
|
0
|
0
|
|
|
|
|
croak "$package requires an even number of arguments" |
15
|
|
|
|
|
|
|
if @_ & 1; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my %params = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
$params{ lc $_ } = delete $params{ $_ } for keys %params; |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
delete $params{options} |
22
|
|
|
|
|
|
|
unless ref $params{options} eq 'HASH'; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
0
|
|
|
|
croak "`ua_args` parameter must be a hashref" |
25
|
|
|
|
|
|
|
if exists $params{ua_args} |
26
|
|
|
|
|
|
|
and ref $params{ua_args} ne 'HASH'; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
unless ( exists $params{ua_args}{timeout} ) { |
29
|
0
|
|
|
|
|
|
$params{ua_args}{timeout} = 30; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $self = bless \%params, $package; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
$self->{session_id} = POE::Session->create( |
35
|
|
|
|
|
|
|
object_states => [ |
36
|
|
|
|
|
|
|
$self => { |
37
|
|
|
|
|
|
|
fetch => '_fetch', |
38
|
|
|
|
|
|
|
shutdown => '_shutdown', |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
$self => [ |
41
|
|
|
|
|
|
|
qw( |
42
|
|
|
|
|
|
|
_child_error |
43
|
|
|
|
|
|
|
_child_closed |
44
|
|
|
|
|
|
|
_child_stdout |
45
|
|
|
|
|
|
|
_child_stderr |
46
|
|
|
|
|
|
|
_sig_child |
47
|
|
|
|
|
|
|
_start |
48
|
|
|
|
|
|
|
) |
49
|
|
|
|
|
|
|
] |
50
|
|
|
|
|
|
|
], |
51
|
|
|
|
|
|
|
( defined $params{options} ? ( options => $params{options} ) : () ), |
52
|
|
|
|
|
|
|
)->ID(); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _start { |
58
|
0
|
|
|
0
|
|
|
my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; |
59
|
0
|
|
|
|
|
|
$self->{session_id} = $_[SESSION]->ID(); |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
if ( $self->{alias} ) { |
62
|
0
|
|
|
|
|
|
$kernel->alias_set( $self->{alias} ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
0
|
|
|
|
|
|
$kernel->refcount_increment( $self->{session_id} => __PACKAGE__ ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$self->{wheel} = POE::Wheel::Run->new( |
69
|
0
|
|
|
0
|
|
|
Program => sub { _wheel( $self->{ua_args} ); }, |
70
|
0
|
0
|
|
|
|
|
ErrorEvent => '_child_error', |
71
|
|
|
|
|
|
|
CloseEvent => '_child_close', |
72
|
|
|
|
|
|
|
StdoutEvent => '_child_stdout', |
73
|
|
|
|
|
|
|
StderrEvent => '_child_stderr', |
74
|
|
|
|
|
|
|
StdioFilter => POE::Filter::Reference->new, |
75
|
|
|
|
|
|
|
StderrFilter => POE::Filter::Line->new, |
76
|
|
|
|
|
|
|
( $^O eq 'MSWin32' ? ( CloseOnCall => 0 ) : ( CloseOnCall => 1 ) ) |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
$kernel->yield('shutdown') |
80
|
|
|
|
|
|
|
unless $self->{wheel}; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$kernel->sig_child( $self->{wheel}->PID(), '_sig_child' ); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _sig_child { |
88
|
0
|
|
|
0
|
|
|
$poe_kernel->sig_handled; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub session_id { |
92
|
0
|
|
|
0
|
1
|
|
return $_[0]->{session_id}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub fetch { |
96
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
97
|
0
|
|
|
|
|
|
$poe_kernel->post( $self->{session_id} => 'fetch' => @_ ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _fetch { |
101
|
0
|
|
|
0
|
|
|
my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; |
102
|
0
|
|
|
|
|
|
my $sender = $_[SENDER]->ID; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
return |
105
|
0
|
0
|
|
|
|
|
if $self->{shutdown}; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my $args; |
108
|
0
|
0
|
|
|
|
|
if ( ref $_[ARG0] eq 'HASH' ) { |
109
|
0
|
|
|
|
|
|
$args = { %{ $_[ARG0] } }; |
|
0
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
0
|
|
|
|
|
|
carp "First parameter must be a hashref, trying to adjust..."; |
113
|
0
|
|
|
|
|
|
$args = { @_[ARG0 .. $#_] }; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$args->{ lc $_ } = delete $args->{ $_ } |
117
|
0
|
|
|
|
|
|
for grep { !/^_/ } keys %{ $args }; |
|
0
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
unless ( $args->{event} ) { |
120
|
0
|
|
|
|
|
|
carp "Missing 'event' parameter to fetch"; |
121
|
0
|
|
|
|
|
|
return; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
if ( $args->{session} ) { |
125
|
0
|
0
|
|
|
|
|
if ( my $ref = $kernel->alias_resolve( $args->{session} ) ) { |
126
|
0
|
|
|
|
|
|
$args->{sender} = $ref->ID; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
else { |
129
|
0
|
|
|
|
|
|
carp "Could not resolve 'session' parameter to a valid" |
130
|
|
|
|
|
|
|
. " POE session"; |
131
|
0
|
|
|
|
|
|
return; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
else { |
135
|
0
|
|
|
|
|
|
$args->{sender} = $sender; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$kernel->refcount_increment( $args->{sender} => __PACKAGE__ ); |
139
|
0
|
|
|
|
|
|
$self->{wheel}->put( $args ); |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
undef; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub shutdown { |
145
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
146
|
0
|
|
|
|
|
|
$poe_kernel->call( $self->{session_id} => 'shutdown' => @_ ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub _shutdown { |
150
|
0
|
|
|
0
|
|
|
my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; |
151
|
0
|
|
|
|
|
|
$kernel->alarm_remove_all; |
152
|
0
|
|
|
|
|
|
$kernel->alias_remove( $_ ) for $kernel->alias_list; |
153
|
0
|
0
|
|
|
|
|
$kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ ) |
154
|
|
|
|
|
|
|
unless $self->{alias}; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$self->{shutdown} = 1; |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
|
$self->{wheel}->shutdown_stdin |
159
|
|
|
|
|
|
|
if $self->{wheel}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub _child_closed { |
163
|
0
|
|
|
0
|
|
|
my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; |
164
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
|
warn "_child_closed called (@_[ARG0..$#_])\n" |
166
|
|
|
|
|
|
|
if $self->{debug}; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
delete $self->{wheel}; |
169
|
0
|
0
|
|
|
|
|
$kernel->yield('shutdown') |
170
|
|
|
|
|
|
|
unless $self->{shutdown}; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
undef; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _child_error { |
176
|
0
|
|
|
0
|
|
|
my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; |
177
|
0
|
0
|
|
|
|
|
warn "_child_error called (@_[ARG0..$#_])\n" |
178
|
|
|
|
|
|
|
if $self->{debug}; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
delete $self->{wheel}; |
181
|
0
|
0
|
|
|
|
|
$kernel->yield('shutdown') |
182
|
|
|
|
|
|
|
unless $self->{shutdown}; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
undef; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub _child_stderr { |
188
|
0
|
|
|
0
|
|
|
my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; |
189
|
0
|
0
|
|
|
|
|
warn "_child_stderr: $_[ARG0]\n" |
190
|
|
|
|
|
|
|
if $self->{debug}; |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
undef; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub _child_stdout { |
196
|
0
|
|
|
0
|
|
|
my ( $kernel, $self, $input ) = @_[ KERNEL, OBJECT, ARG0 ]; |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
my $session = delete $input->{sender}; |
199
|
0
|
|
|
|
|
|
my $event = delete $input->{event}; |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
$kernel->post( $session, $event, $input ); |
202
|
0
|
|
|
|
|
|
$kernel->refcount_decrement( $session => __PACKAGE__ ); |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
undef; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub _wheel { |
208
|
0
|
|
|
0
|
|
|
my $ua_args = shift; |
209
|
|
|
|
|
|
|
|
210
|
0
|
0
|
|
|
|
|
if ( $^O eq 'MSWin32' ) { |
211
|
0
|
|
|
|
|
|
binmode STDIN; |
212
|
0
|
|
|
|
|
|
binmode STDOUT; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $raw; |
216
|
0
|
|
|
|
|
|
my $size = 4096; |
217
|
0
|
|
|
|
|
|
my $filter = POE::Filter::Reference->new; |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
my $wrong = WWW::DoingItWrongCom::RandImage->new( |
220
|
|
|
|
|
|
|
ua_args => $ua_args, |
221
|
|
|
|
|
|
|
); |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
while ( sysread STDIN, $raw, $size ) { |
224
|
0
|
|
|
|
|
|
my $requests = $filter->get( [ $raw ] ); |
225
|
0
|
|
|
|
|
|
foreach my $req ( @$requests ) { |
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
$req->{out} = $wrong->fetch; |
228
|
|
|
|
|
|
|
|
229
|
0
|
0
|
|
|
|
|
unless ( defined $req->{out} ) { |
230
|
0
|
|
|
|
|
|
delete $req->{out}; |
231
|
0
|
|
|
|
|
|
$req->{error} = $wrong->err_str; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
my $response = $filter->put( [ $req ] ); |
235
|
0
|
|
|
|
|
|
print STDOUT @$response; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
1; |
242
|
|
|
|
|
|
|
__END__ |