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

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.

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

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

    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.

        How about just overriding the HTTP::Response::content method then?

        require HTTP::Response; use Carp 'cluck'; my $old_content = \&HTTP::Response::content; *HTTP::Response::content = sub { cluck "HTTP::Response::content called - do you want HTTP::Response +::decoded_content instead?"; goto &$old_content; };

        You could get fancy and check whether it's HTTP::Response::decoded_content that is calling you and then suppress your warning, by using caller.