Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^5: Introducing Class::InsideOut

by Anno (Deacon)
on Feb 15, 2006 at 09:46 UTC ( [id://530328]=note: print w/replies, xml ) Need Help??


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

Why? The common new can support it:

sub new { my $class = shift; bless @_ ? shift : \ my $x, $class; }

That way you can use an arbitrary foreign object as the donator of the new id.

Anno

Replies are listed 'Best First'.
Re^6: Introducing Class::InsideOut
by adrianh (Chancellor) on Feb 15, 2006 at 10:42 UTC

    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.

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (None)
    As of 2024-04-25 00:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found