in reply to Re^5: Introducing Class::InsideOut
in thread Introducing Class::InsideOut

Sorry - I fail to see how this helps in subclassing an pre-existing class. What you seem to be doing here is taking an existing object and re-blessing it into your new class - which will break inheritance, method resolution, etc.

Replies are listed 'Best First'.
Re^7: Introducing Class::InsideOut
by xdg (Monsignor) on Feb 15, 2006 at 12:20 UTC

    It will work as long as the @ISA gets set up correctly. It's no different than what Class::InsideOut does to support inside-out objects. All anno's solution does is provide a default constructor that can take a foreign object.

    That said, I'm not sure where it really helps as his solution still either requires an overridding new to add an initialization call or else will provide an explicit call to an init or BUILD. The former approach doesn't really save any code and the latter approach is another straightjacket -- however comfy. Put differently, his new just makes it easier to generate either an anonymous scalar or to rebless an existing object.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      It will work as long as the @ISA gets set up correctly. It's no different than what Class::InsideOut does to support inside-out objects. All anno's solution does is provide a default constructor that can take a foreign object.

      Ah. Quite right. If you setup ISA appropriately it will still work. Still reblessing an already initialised object seems far more evil than the coupling of creation/initialisation it's trying to avoid. Not something I'd expect if I was reading the code.

      Not that I disagree with the general concept - but I think C::IO made the right decision in not providing a default constructor. It makes it much easier to apply it to pre-existing class hierarchies no matter how they're organised.

        Ah. Quite right. If you setup ISA appropriately it will still work. Still reblessing an already initialised object seems far more evil than the coupling of creation/initialisation it's trying to avoid. Not something I'd expect if I was reading the code.

        If you want to inherit from a foreign class in this particular way (substituting the foreign object for the standard undefined scalar), reblessing must be expected. Apart from esthetic objections I don't see a big problem with that.

        Anno