After a bit of RTFM-ing, reading the source and experimenting, I think the %matchspec is supposed to be used something like this:
use LWP::UserAgent qw( ); my $ua = LWP::UserAgent->new(); my $url = 'http://www.google.com/'; my $resp; $resp = $ua->get($url); print($resp->status_line(), "\n"); show(1); print("Added:\n"); $ua->add_handler( response_header => sub { print "HANDLER\n"; }, owner + => "myfunc"); show(2); $resp = $ua->get($url); print($resp->status_line(), "\n"); show(3); print("Removed:\n"); $ua->remove_handler('response_header', owner => "myfunc"); show(4); $resp = $ua->get($url); print($resp->status_line(), "\n"); show(5); sub show { print(join(" ", @_, $ua->handlers('response_header', $resp)), "\n"); } __END__ 200 OK 1 HASH(0x8c2440) Added: 2 HASH(0x8c2440) HASH(0x93b0e0) HANDLER HANDLER 200 OK 3 HASH(0x8c2440) HASH(0x93b0e0) Removed: 4 HASH(0x8c2440) 200 OK 5 HASH(0x8c2440)
where "myfunc" is some self-chosen name that you use to identify the callback for removal.
(When you dump the hashes, you can see that the one associated with the internal handler (HASH(0x8c2440)) has owner => 'LWP::UserAgent::parse_head')
As you can see, the internal callback remains intact this way.
In reply to Re^3: LWP handlers examples?
by almut
in thread LWP handlers examples?
by vitoco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |