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.