Hello Br'er Rabbit,

> Can a Perl module "inspect" itself and provide details about methods..

Yes! You can parse a perl document with PPI two oneliners just to get started:

# a bare package provided as string perl -MPPI -e "print $_->content for @{ PPI::Document->new(\'package M +yPack{ sub new{ bless{}, shift} }')->find('PPI::Statement::Sub') }" #output sub new{ bless{}, shift} # inspecting Data::Dump module (getting its path from %INC) perl -MPPI -MData::Dump -e "print $_->content for @{ PPI::Document->ne +w( $INC{'Data/Dump.pm'} )->find('PPI::Statement::Sub') }; " #output sub dump { local %seen; local %refcnt; local %require; local @fixup; ...

You can go further trying to extract arguments received (good luck ;) and maybe you have to learn what PPI PDOM Tree is:

perl -MPPI -MPPI::Dumper -e "PPI::Dumper->new( PPI::Document->new(\'pa +ckage MyPack{ sub new{my class shift; return bless{},$class} }') )-> +print" PPI::Document PPI::Statement::Package PPI::Token::Word 'package' PPI::Token::Whitespace ' ' PPI::Token::Word 'MyPack' PPI::Structure::Block { ... } PPI::Token::Whitespace ' ' PPI::Statement::Sub PPI::Token::Word 'sub' PPI::Token::Whitespace ' ' PPI::Token::Word 'new' PPI::Structure::Block { ... } PPI::Statement::Variable PPI::Token::Word 'my' PPI::Token::Whitespace ' ' PPI::Token::Word 'class' PPI::Token::Whitespace ' ' PPI::Token::Word 'shift' PPI::Token::Structure ';' PPI::Token::Whitespace ' ' PPI::Statement::Break PPI::Token::Word 'return' PPI::Token::Whitespace ' ' PPI::Token::Word 'bless' PPI::Structure::Constructor { ... } PPI::Token::Operator ',' PPI::Token::Symbol '$class' PPI::Token::Whitespace ' '

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Can a Perl module "inspect" itself and provide details about methods and parameters? -- oneliner by Discipulus
in thread Can a Perl module "inspect" itself and provide details about methods and parameters? by Br'er Rabbit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.