Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by Anonymous Monk
on Sep 26, 2019 at 20:36 UTC ( [id://11106764]=note: print w/replies, xml ) Need Help??


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

I seem to remember that Perl modules are "objects" or collections of them and I remember from the many attacks on my comprehension by "object-orientation" that "objects" can be ASKED this-or-that. (It's supposed to be a "feature.")

Sometimes you can learn about objects by dumping them:

perl -MHTTP::Tiny -MData::Dumper -le '$o=HTTP::Tiny->new;print Dumper +$o' $VAR1 = bless( { 'timeout' => 60, 'keep_alive' => 1, 'max_redirect' => 5, 'verify_SSL' => 0, 'agent' => 'HTTP-Tiny/0.070', 'no_proxy' => [] }, 'HTTP::Tiny' );
Ish:
perl -MHTTP::Tiny -le '$o=HTTP::Tiny->new;print "$_ = $o->{$_}" for so +rt keys %$o' agent = HTTP-Tiny/0.070 keep_alive = 1 max_redirect = 5 no_proxy = ARRAY(0x7fc821802fc8) timeout = 60 verify_SSL = 0
Sometimes, there's no params:
perl -MImage::Magick -MData::Dumper -le '$o=Image::Magick->new;print D +umper $o' $VAR1 = bless( [], 'Image::Magick' );
  • Comment on Re: Can a Perl module "inspect" itself and provide details about methods and parameters?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Can a Perl module "inspect" itself and provide details about methods and parameters?
by Fletch (Bishop) on Sep 26, 2019 at 21:04 UTC

    This "works", but be very aware you're breaking a fundamental tenet of OO (encapsulation) by doing so.

    And by so sinning you're lining yourself up for the inevitable great vengance and furious anger which will rain down upon you (c.f. Ezekiel 25:17) when the module author decides that mauve has more RAM and changes to inside-out objects in a subsequent release and whatever hack you came up with depending on the prior internal implementation breaks.

    Fine for pedagogical exploration; never do this in real code.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-23 22:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found