Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-20 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found