in reply to Re: How to override HTTP::UserAgent::request to return a subclassed HTTP::Response
in thread How to override HTTP::UserAgent::request to return a subclassed HTTP::Response

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.

  • Comment on Re^2: How to override HTTP::UserAgent::request to return a subclassed HTTP::Response

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

    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

      That is more of what I was thinking but I wasn't sure how to turn an HTTP::Response into a XXX::HTTP::Response (not liking the look of Acme::Damn). When you made your reply were you basically suggesting a combination of overriding LWP::UserAgent::request and cloning the HTTP::Response into an XXX::HTTP::Response?

      package XXX::LWP::UserAgent; use base qw(LWP::UserAgent); sub request { my $self = shift; my $resp = $self->SUPER::request(@_); return XXX::HTTP::Response::clone_from_http_response($resp); }

      or is there perhaps some other way of avoiding duplicating LWP::UserAgent::request.

        Yes, this is what I mean. As I don't know how you want to turn a HTTP::Response into your XXX::HTTP::Response, as you've kept the differences between the two well to yourself, I can't tell you any better way than to write some code that creates an XXX::HTTP::Response object from a HTTP::Response object.

Re^3: How to override HTTP::UserAgent::request to return a subclassed HTTP::Response
by ikegami (Patriarch) on Jun 01, 2009 at 15:21 UTC
    You could always subclass or wrap LWP::UserAgent