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

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

my $response = My::HTTP::Response->new_from_lwp( $ua->request(...) );
  • Comment on Re: How to override HTTP::UserAgent::request to return a subclassed HTTP::Response
  • Download Code

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

    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

        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.

      You could always subclass or wrap LWP::UserAgent