Skip to content

Commit 74c3257

Browse files
committed
Pass in handler hash to the handler callback.
1 parent c554ba9 commit 74c3257

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎lib/LWP/Protocol.pm‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ sub collect
125125

126126
if (delete $response->{default_add_content}) {
127127
push(@{$response->{handlers}{response_data}}, sub {
128-
$_[0]->add_content($_[2]);
128+
$_[0]->add_content($_[3]);
129129
1;
130130
});
131131
}
@@ -138,7 +138,7 @@ sub collect
138138
while ($content = &$collector, length $$content) {
139139
for my $h ($ua->handlers("response_data", $response)) {
140140
next if $skip_h{$h};
141-
unless ($h->($response, $ua, $$content)) {
141+
unless ($h->{callback}->($response, $ua, $h, $$content)) {
142142
# XXX remove from $response->{handlers}{response_data} if present
143143
$skip_h{$h}++;
144144
}

‎lib/LWP/UserAgent.pm‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,10 @@ sub handlers {
766766
my($self, $phase, $o) = @_;
767767
my @h;
768768
if ($o->{handlers} && $o->{handlers}{$phase}) {
769-
push(@h, @{$o->{handlers}{$phase}});
769+
push(@h, map +{ callback => $_ }, @{$o->{handlers}{$phase}});
770770
}
771771
if (my $conf = $self->{handlers}{$phase}) {
772-
push(@h, map { $_->{callback} } $conf->matching($o));
772+
push(@h, $conf->matching($o));
773773
}
774774
return @h;
775775
}
@@ -778,14 +778,14 @@ sub run_handlers {
778778
my($self, $phase, $o) = @_;
779779
if (defined(wantarray)) {
780780
for my $h ($self->handlers($phase, $o)) {
781-
my $ret = $h->($o, $self);
781+
my $ret = $h->{callback}->($o, $self, $h);
782782
return $ret if $ret;
783783
}
784784
return undef;
785785
}
786786

787787
for my $h ($self->handlers($phase, $o)) {
788-
$h->($o, $self);
788+
$h->{callback}->($o, $self, $h);
789789
}
790790
}
791791

@@ -1336,15 +1336,15 @@ The possible values $phase are:
13361336
13371337
=over
13381338
1339-
=item request_preprepare => sub { my($request, $ua) = @_; ... }
1339+
=item request_preprepare => sub { my($request, $ua, $h) = @_; ... }
13401340
13411341
The handler is called before the C<request_prepare> and other standard
13421342
initialization of of the request. This can be used to set up headers
13431343
and attributes that the C<request_prepare> handler depends on. Proxy
13441344
initialization should take place here; but in general don't register
13451345
handlers for this phase.
13461346
1347-
=item request_prepare => sub { my($request, $ua) = @_; ... }
1347+
=item request_prepare => sub { my($request, $ua, $h) = @_; ... }
13481348
13491349
The handler is called before the request is sent and can modify the
13501350
request any way it see hit. This can for instance be used to add
@@ -1356,7 +1356,7 @@ request that is sent fully.
13561356
The return value from the callback is ignored. Exceptions are
13571357
not trapped and are propagated to the outer request method.
13581358
1359-
=item request_send => sub { my($request, $ua) = @_; ... }
1359+
=item request_send => sub { my($request, $ua, $h) = @_; ... }
13601360
13611361
This handler get a chance of handling requests before it's sent to the
13621362
protocol handlers. It should return an HTTP::Response object if it
@@ -1365,7 +1365,7 @@ wishes to terminate the processing; otherwise it should return nothing.
13651365
The C<response_header> and C<response_data> handlers will not be
13661366
invoked for this response, but the C<response_done> will be.
13671367
1368-
=item response_header => sub { my($response, $ua) = @_; ... }
1368+
=item response_header => sub { my($response, $ua, $h) = @_; ... }
13691369
13701370
This handler is called right after the response headers have been
13711371
received, but before any content data. The handler might set up
@@ -1377,21 +1377,21 @@ directly. This will initially be false if the $ua->request() method
13771377
was called with a ':content_filename' or ':content_callbak' argument;
13781378
otherwise true.
13791379
1380-
=item response_data => sub { my($response, $ua, $data) = @_; ... }
1380+
=item response_data => sub { my($response, $ua, $h, $data) = @_; ... }
13811381
13821382
This handlers is called for each chunk of data received for the
13831383
response. The handler might croak to abort the request.
13841384
13851385
This handler need to return a TRUE value to be called again for
13861386
subsequent chunks for the same request.
13871387
1388-
=item response_done => sub { my($response, $ua) = @_; ... }
1388+
=item response_done => sub { my($response, $ua, $h) = @_; ... }
13891389
13901390
The handler is called after the response has been fully received, but
13911391
before any redirect handling is attempted. The handler can be used to
13921392
extract information or modify the response.
13931393
1394-
=item response_redirect => sub { my($response, $ua) = @_; ... }
1394+
=item response_redirect => sub { my($response, $ua, $h) = @_; ... }
13951395
13961396
The handler is called in $ua->request after C<response_done>. If the
13971397
handler return an HTTP::Request object we'll start over with processing

0 commit comments

Comments
 (0)