in reply to Re^2: 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

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

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

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

    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.

        Initially I wanted to trap someone calling the HTTP::Response content method by accident when it mostly should be the decoded_content method.