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.