Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: OOP introspection

by perlfan (Vicar)
on Apr 02, 2021 at 22:07 UTC ( [id://11130747]=note: print w/replies, xml ) Need Help??


in reply to OOP introspection

I suppose one way to do it would be to go "up the chain"; utlizing SUPER (i.e., $self->SUPER::new + ref on the ancestor to get __PACKAGE__, it's reasonable to assume you could explore the turtles all the way up). Start with your initial blessed reference; recreate parent using my $father = $son->SUPER::new; use $father to recreated grandfather, so on and so forth. This example relies on each having new; but seems to reason it would work in Moo, Moose, and their elk.

Replies are listed 'Best First'.
Re^2: OOP introspection
by dsheroh (Monsignor) on Apr 03, 2021 at 11:37 UTC
    Aside from the reliance on a predictably-named constructor (->new), this also implicitly assumes single inheritance. I'm not sure that there's any practical way to get all the ancestors in a multiple-inheritance scenario other than iterating the @ISAs.
      I didn't consider multiple inheritenace. I suppose I need to play with SUPER to see what it does in that case.
Re^2: OOP introspection
by roboticus (Chancellor) on Apr 03, 2021 at 12:22 UTC

    perlfan:

    If the system allowed additional upvodes, I'd give an extra one just for that last word. ;^)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2024-04-16 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found