clueless newbie has asked for the wisdom of the Perl Monks concerning the following question:
Given the following chunk of code:
#!/usr/bin/env perl use 5.032001; use warnings; my @packages; package Fee; push @packages,__PACKAGE__; sub one { say __PACKAGE__.q{::one}; }; package Fi; push @packages,__PACKAGE__; sub two { say __PACKAGE__.q{::two}; }; { package Foo; push @packages,__PACKAGE__; sub three { say __PACKAGE__.q{::three}; }; }; # End of package Foo! sub four { say __PACKAGE__.q{:four}; }; # Dump symbols for my $package (@packages) { no strict; my %stash = %{"${package}::"}; use strict; warn Data::Dumper->new([\$package,\%stash],[qw(*package *stash)])- +>Deepcopy(1)->Indent(1)->Maxdepth(3)->Sortkeys(1)->Dump(),q{ }; }; 1; __DATA__
While Devel::Examine::Subs suggests:
'one', 'two', 'three', 'four'
dumping the symbols suggests
\'Fee' ( 'one' => *Fee::one ) \'Fi' ( 'BEGIN' => *Fi::BEGIN, 'DATA' => *Fi::DATA, 'four' => *Fi::four, 'two' => *Fi::two ) \'Foo' ( 'three' => *Foo::three )
My attempts to extract the full subroutine names using PPI have been failures. I can get the sub names and I can get the packages but not the needed relationship --- ie Fee::one, Fi::two etc. I would greatly appreciate knowing how to use PPI to extract the subroutine names in conjunction with their containing package.
Thanks!
|
---|