Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: OOP introspection (composition)

by LanX (Saint)
on Apr 02, 2021 at 21:39 UTC ( [id://11130745]=note: print w/replies, xml ) Need Help??


in reply to OOP introspection

> Also in the case of composition how can I find out which class depends on which class?

That's a tougher one, because AFAIK does "classic Perl" only allow imports for "composition". Differing OO-frameworks might have differing approaches and builtin solutions for inspection.

But you can iterate over all subs in the namespace° of a class and inspect in which module it was originally defined.

There is a core module for that° Sub::Util (read the doc for subname ) ... or something like Sub::Identify from CPAN.

edit

°) This won't help you if the composition was done by changing AUTOLOAD , but I don't even know if this approach is even a thing in OOP (?)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) sorry I was wrong about that, Sub::Util is not implementing what Sub::Identify does. But the latter comes with a compact pure Perl implementation using the B backend to extract those informations. AFAICS it's the same approach like described in the book "Perl Hacks".

Replies are listed 'Best First'.
Re^2: OOP introspection (composition)
by LanX (Saint) on Apr 03, 2021 at 10:07 UTC
    could be that I totally misunderstood your question about composition as "composing" a class with roles

    compare

    https://perldoc.perl.org/perlootut#Roles

    vs

    https://perldoc.perl.org/perlootut#Composition °

    In case you meant the latter:

    This is extremely difficult in dynamically typed languages.

    You would of course parse the code for use of other classes and constructors named "new".

    But this would only give you a fragile approximation of dependencies at best, because of all the flexibility Perl offers.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    °) which is very generally speaking and fuzzy

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11130745]
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: (2)
As of 2024-04-26 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found