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

Re^2: Can a Perl module "inspect" itself and provide details about methods and parameters?

by Br'er Rabbit (Novice)
on Sep 21, 2019 at 22:19 UTC ( [id://11106518]=note: print w/replies, xml ) Need Help??


in reply to Re: Can a Perl module "inspect" itself and provide details about methods and parameters?
in thread Can a Perl module "inspect" itself and provide details about methods and parameters?

@Stevieb

> I think it'd be a futile effort to try to sort out what params each subroutine accepts because they can come in and be handled in a myriad of ways.

This part is just sad: if objects were self-documenting, then they wouldn't have to rely on the existence of (good) external documentation.

"If I ever write one", (he wrote, pompously) "I'll sure gladly provide everything everybody would want to know."

Your code will nevertheless be a Big Help in filling in some holes about What's Actually Callable.

Thank you.

  • Comment on Re^2: Can a Perl module "inspect" itself and provide details about methods and parameters?

Replies are listed 'Best First'.
Re^3: Can a Perl module "inspect" itself and provide details about methods and parameters?
by stevieb (Canon) on Sep 21, 2019 at 22:42 UTC
    "This part is just sad: if objects were self-documenting, then they wouldn't have to rely on the existence of (good) external documentation."

    When I'm writing against an object, my IDE pops up with a list of valid methods to choose from, and autocompletes if I desire. To boot, once I've typed in the method name, it'll display to me what arguments the method (or function) accepts. Now, if the function/method is accepting a single hash for example, there's no way to know at all what key/value pairs are used within that hash. However, if all of the parameters are individual scalars in a specific order, it will list those (with their names included).

    Here's an image showing the IDE displaying a list of available methods to an external class (works on objects all the same).

    ...and here's an image showing the parameters for an object's method.

    A good IDE can help tremendously, especially when you're working with numerous classes at the same time. You can CTRL-click on any variable, method, function or anything, and you can make one click to go to the definition of it immediately.

    Rarely do I need to view documentation online, or the command line. Typically in Perl, we gather up all of our parameters at the top of each subroutine, so being able to go directly to the definition of a sub makes it trivial to see exactly how params are being used.

Re^3: Can a Perl module "inspect" itself and provide details about methods and parameters?
by Your Mother (Archbishop) on Sep 21, 2019 at 22:51 UTC

    With ImageMagic—since that was the genesis of the thread(s)—you have an added complication. You have to document, introspect the Perl interface/bindings and the C libs beneath. Documentation and code are not, and can never be, the same any more than even simple math could be. I don’t think it’s particularly sad. It is what it is. Perl’s deep flexibility, including lack of types, also precludes a perfect solution, maybe even a consistently decent one, to this kind of introspection. Temporarily suspending the excellent, at least interesting, ideas of affordance and literacy in code; a tool that is also its own manual will end up cumbersome and awkward as both. XML and XSLT come to mind for me here.

Re^3: Can a Perl module "inspect" itself and provide details about methods and parameters?
by Br'er Rabbit (Novice) on Sep 22, 2019 at 12:46 UTC

    @AllMonksWhoTookTheTime

    Thank you, esp. for explaining what must seem obvious to you by now. (I hope this thread survives: at my age, I'm sure I'll be back to read it... ;^) )

    Note @Stevieb: Re: Devel::Examine::Subs had to install a good number of other modules first, so out-of-touch was my CPAN, and now am only failing t/42 and t/43. Clearly, from you own observation, presaging others', about the "uncertainty" associated with retrieved parameters, the pressure to have and use the tool is off. I'll give it a few more good tries, but will otherwise take the hint and move on and look for my answers in the source. Thank you.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-18 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found