mje has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to override some methods in HTTP:Response and provide some new methods - that part is fine, a subclass. How do I make LWP::UserAgent->request return my subclassed HTTP::Response instead of a HTTP::Response?
  • Comment on How to override HTTP::UserAgent::request to return a subclassed HTTP::Response

Replies are listed 'Best First'.
Re: How to override HTTP::UserAgent::request to return a subclassed HTTP::Response
by ikegami (Patriarch) on Jun 01, 2009 at 15:09 UTC

    Why don't you give your class a constructor that clones an HTTP::Response.

    my $response = My::HTTP::Response->new_from_lwp( $ua->request(...) );

      I could do that but that would mean I'd have to change every user of the LWP::UserAgent::request method to clone the response. I was hoping to make the change at a higher level.

        Why not override the request method and do the change there? That way, all users of the request method will get your new request class. Also see perltoot

        You could always subclass or wrap LWP::UserAgent