Re: how to: request($r, $self->callback, 4069)

Abraham Ingersoll (abe@honestabe.net)
Thu, 5 Oct 2000 20:51:31 -0700 (PDT)


---2112353274-2128247503-970803954=:30898
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-ID: <Pine.LNX.4.21.0010052046551.30898@we-24-130-6-12.we.mediaone.net>

				
I tried sub { $self->callback }, and it doesn't work. $self is passed, but
that's it. See the attached file test.pm for all the code, but basically
this --
	my $res = $ua->request($req, sub { $self->callback }, 4096);
<snip>
sub callback {
	#my ($self, $data, $res_obj, $protocol_obj) = @_;
	warn "start callback\n";
	foreach (@_) {
		warn "passed value: $_\n";
	}
	warn "end callback\n";
}

yields this --

start callback
passed value: test=HASH(0x835b854)
end callback

What I've thought about doing to get around this is to make $arg an object
reference, and then have LWP::Protocol::collect call a hard-coded method
of that object ($obj->callback) .. rather than have collect eval the CODE
ref ($arg). I tried changing lines 252 to 259 of LWP/Protocl.pm --

	eval {
		&$arg($$content, $response, $self)
	};
	if ($@) {
		chomp($@);
		$response->header('X-Died' => $@);
		last;
	}
to this
	my ($e, $e_message) = $arg->callback($$content, $response, $self);
	if ($e) {
		$response->header('X-Died' => $error_message);
		last;
	}

(along with changing the preceding CODE ref tests to HASH tests) but don't
know if I screwed anything else up. My mod_perl app will now sometimes
just stop processing text in the middle of a chunk, return, and leave no
trace of why it quit. :( 

Thanks so much for your time!
Abe


On 5 Oct 2000, Gisle Aas wrote:

> Abraham Ingersoll <abe@honestabe.net> writes:
> 
> > Could anyone kindly tell me how I can have LWP::UserAgent::request call a
> > subroutine using perl's OOP synxtax. Like yea:
> > 
> > my $res = $UA->request($req, \&{ $self->callback }, 4069);
> 
> You should write this as:
> 
>   my $res = $UA->request($req, sub { $self->callback }, 4069);
> 
> BTW, where did you get that 4069 number from?  :-)
> 
> Regards,
> Gisle
> 
> 
> > The above works in that it calls CurrentClass::datahandler, but it
> > then doesn't pass the content, response or protocol objects that would be
> > there if you called it like yea:
> > 
> > my $res = $UA->request($req, \&callback, 4069);
> 

---2112353274-2128247503-970803954=:30898
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; NAME="test.pm"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.21.0010052045540.30898@we-24-130-6-12.we.mediaone.net>
Content-Description: 
Content-Disposition: ATTACHMENT; FILENAME="test.pm"

cGFja2FnZSB0ZXN0Ow0KDQp1c2Ugc3RyaWN0Ow0KdXNlIEFwYWNoZTo6Q29u
c3RhbnRzIHF3KDpjb21tb24pOw0KdXNlIEFwYWNoZTo6TG9nOw0KdXNlIEFw
YWNoZTo6VGFibGU7DQp1c2UgQXBhY2hlOjpSZXF1ZXN0Ow0KdXNlIExXUDo6
VXNlckFnZW50Ow0KDQpzdWIgbmV3IHsgDQoJYmxlc3MgeyB9LCAkX1swXSAN
Cn0NCg0Kc3ViIGhhbmRsZXIgew0KCW15ICRyID0gc2hpZnQ7DQoJbXkgJHRl
c3QgPSB0ZXN0LT5uZXc7DQoJJHRlc3QtPnByb3h5KCRyKTsNCgl3YXJuICJk
b25lLlxuIjsNCn0NCg0Kc3ViIHByb3h5IHsNCglteSAoJHNlbGYsICRyKSA9
IEBfOw0KCXdhcm4gInRlc3Q6OnByb3h5IHNlbGYgPSAkc2VsZlxuIjsNCglt
eSAkcmVxID0gSFRUUDo6UmVxdWVzdC0+bmV3KCRyLT5tZXRob2QgPT4gJ2h0
dHA6Ly9ob25lc3RhYmUubmV0Jyk7DQoNCglteSAlaGVhZGVycyA9ICRyLT5o
ZWFkZXJzX2luOw0KCWZvcmVhY2ggbXkgJGhlYWRlciAoa2V5cyAlaGVhZGVy
cykgew0KCQluZXh0IGlmICRoZWFkZXIgZXEgJ0Nvbm5lY3Rpb24nOw0KCQlu
ZXh0IGlmICRoZWFkZXIgZXEgJ0hvc3QnOw0KCQkkcmVxLT5wdXNoX2hlYWRl
cigkaGVhZGVyID0+ICRoZWFkZXJzeyRoZWFkZXJ9KTsNCgl9IA0KDQoJbXkg
JHVhID0gTFdQOj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