Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^2: Saving HTTP::Cookies into Netscape format using bless/re-bless

by bliako (Monsignor)
on May 19, 2021 at 07:30 UTC ( #11132730=note: print w/replies, xml ) Need Help??

in reply to Re: Saving HTTP::Cookies into Netscape format using bless/re-bless
in thread Saving HTTP::Cookies into Netscape format using bless/re-bless

Hmmm, you are doing this: HTTP::Cookies::Netscape::save($jar, "mycookies.txt"); which as you say has the problem if internally save() calls any of the "overwritten" methods (quoted because they are not overwritten at all). In this case these are just save() and load(). And I see one more special-but-common case: if it recurses save(). Also calling a logger helper method would be printing parent class signature.

I am reblessing from a parent class and not just any class, so all state variables and internal methods that may be needed by the child will be inherited. That minimizes the risks. But are there still any?

I see one, if subclass has its own state variables which are set/changed during operations prior to save() for example if it implements its own set_cookie() or new(). That bug will hurt! But it will not affect subclass-specific constants and such, these will assume their initial value upon reblessing.

The use-case I had in mind is to use this "method" in order to transform from one cookie format to another using all those subclasses under HTTP::Cookies but I will have to examine each of these for above problems. I am not sure if other OO-based languages avoid this problem. I don't think Java does that or indeed can do that. It's up to the programmer to adhere to the "princaiples" (sic).

bw, bliako

Replies are listed 'Best First'.
Re^3: Saving HTTP::Cookies into Netscape format using bless/re-bless
by tobyink (Canon) on May 20, 2021 at 08:57 UTC

    Actually, these behave differently:

    Some::Class::method( $obj, @args ); $obj->Some::Class::method( @args );

    If Some::Class doesn't contain a sub called method, the former will fail, but the latter will walk Some::Class's @ISA.

      thanks++, I did not know that.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132730]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2023-12-01 00:22 GMT
Find Nodes?
    Voting Booth?

    No recent polls found