Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by swl (Parson)
on Sep 22, 2019 at 22:02 UTC ( [id://11106552]=note: print w/replies, xml ) Need Help??


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

Just a couple of data points, as others have discussed the overall issues with XS, AUTOLOAD and the like. Neither will process argument lists, so they only address part of the question.

Devel::Symdump will give a huge amount of information about packages, but I prefer Class::Inspector these days as it is simpler to use.

use Devel::Symdump; my $obj = Devel::Symdump->rnew( $package_name ); my @methods = $obj->functions(); # if you are sure private methods only start with underscore... my @public_methods = grep {$_ !~ /^_/} @methods;

and

use Class::Inspector; my $methods = Class::Inspector->methods( $package_name ); my $public_methods = Class::Inspector->methods( $package_name, 'public +' );
  • 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 Your Mother (Archbishop) on Sep 22, 2019 at 23:46 UTC

    Fun. Play stub–

    use 5.10.0; package DoReMe { use Moo; use namespace::autoclean; # Redacts introspection output significa +ntly! has "solfege" => is => "lazy"; } use Class::Inspector; my $methods = Class::Inspector->methods("DoReMe"); say join $/, @{$methods}; say "--"; use Devel::Symdump; my $obj = Devel::Symdump->rnew("DoReMe"); say join $/, $obj->functions;
    BUILDALL BUILDARGS DEMOLISHALL does meta new solfege -- DoReMe::new DoReMe::solfege
Re^2: Can a Perl module "inspect" itself and provide details about methods and parameters?
by Anonymous Monk on Sep 22, 2019 at 22:45 UTC
    Cool! Using a regex stolen from Class::Inspector:

    CORE functions:

    perl '-MData::Dumper()' -e '@_=sort grep {/\A[^\W\d]\w*\z/o} keys %{"$ +{CORE}::"};print Data::Dumper::Dumper\@_'
    CORE + Cwd import:
    perl '-MData::Dumper()' -MCwd -e '@_=sort grep {/\A[^\W\d]\w*\z/o} key +s %{"${CORE}::"};print Data::Dumper::Dumper\@_'
    Everything:
    perl '-MData::Dumper()' -e '@_=sort keys %{"${CORE}::"};print Data::Du +mper::Dumper\@_'
      > CORE functions:

      nope these are some plain named symbols in the %main:: STASH since your var $CORE is undef.

      Anyway you need to check the {CODE} slot of the glob-values to be sure that they hold a code-ref.

      DB<30> sub test { "bla" } DB<31> x map { \&$_ } grep {defined &$_ } values %:: 0 CODE(0x3477178) -> &main::test in (eval 40)[C:/Perl_524/lib/perl5db.pl:737]:2-2 1 CODE(0x3463838) -> &main::dumpvar in C:/Perl_524/lib/dumpvar.pl:474-501 2 CODE(0x3457a78) -> &main::dumpValue in C:/Perl_524/lib/dumpvar.pl:33-40 DB<32>

      dumpvar and dumpValue are internal debugger routines

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-18 00:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found