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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.