in reply to Inheritance problem: Not a HASH ref

Furl is implemented as a reference to a reference, not as a reference to a hash. This makes adding fields to it a bit harder.

The easier way would be to delegate to it instead of inheriting from Furl:

package XYZ; use strict; use warnings; our $VERSION = 1; use parent 'Furl'; sub new { my $class = $_[0]; my $furl = Furl->new(); my $self = { furl => $furl, }; bless($self, $class); # rebless to our own class # setting some own data in self: $self->{'debug'} = 1; $self->{'ABC'} = 42; return $self }

This of course means that you will need to implement all "inherited" methods from Furl as stubs in your class:

for my $method (qw(get put whatever)) { *$method = sub { my $self = shift; $self->{furl}->$method( @_ ); } };

Replies are listed 'Best First'.
Re^2: Inheritance problem: Not a HASH ref
by bliako (Abbot) on Feb 25, 2019 at 18:39 UTC
    This of course means that you will need to implement all "inherited" methods from Furl as stubs in your class:

    please no! Any way to access that "reference to a reference"?

    Basically, what I am looking for is a fast equivalent to LWP::UserAgent which also allows for adding handlers. (I am not sure Furl offers handlers but it was just an experiment). Curl obviously comes to mind. But I did not find it dramatically faster than LWP. Whereas Furl was dramatically faster. What's your experience? The situation is 15,20 hits per minute. More than speed is the CPU load as it will be on a rented host.

      This is NOT a good idea (Breaks encapsulation) .. but it could work for a POC for this case:
      $$self->{MyAdditionToFURL}= "MyValue"; #<< Extra "$" here, to access the extra indirection used by 'furl'
      (UNTESTED)

                      As a computer, I find your faith in technology amusing.

        Thanks for the word of caution NetWallah and stevieb. Stability is in the *$^&£@&* of the beholder, I say, though it sounds cockier than it is.

        As a side remark, personally I would never publish anything which can not be expanded or inherited by 3rd party. If I can't do it, even if it is "lightning fast" I would consign it to the catacombs. But everyone is different and everyone has their reasons and not everyone can write "lightning fast" browsers.

        For the record, Furl does not offer adding callbacks (LWP::UserAgent's add_handler()) to be called at the various phases of the transaction, so it does not serve my purpose. I ended using LWP::Protocol::Net::Curl which, so far, keeps its word as "drop-in curl replacement for LWP::UserAgent", including callbacks and some speed improvement by mere use LWP::Protocol::Net::Curl; uuse parent 'LWP::UserAgent';

        bw, bliako

        Breaks encapsulation

        I have been regurgitating this for awhile and I wonder if it isn't too extreme. In the sense of "since when inheritance breaks encapsulation?"

        that works, thanks