Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

get the list of methods and variables

by PerlScript (Initiate)
on Jun 17, 2010 at 07:21 UTC ( #845154=perlquestion: print w/ replies, xml ) Need Help??
PerlScript has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have the child "child.pm" file. Inside this pm file it calls the parent packages with

use base parent.pm

From "parent.pm", it calls its parent packages with

use base grandparent.pm

Is there any way to get the all the methods and variables list to print from the child.pm

Regards
Muthu

Comment on get the list of methods and variables
Re: get the list of methods and variables
by Utilitarian (Vicar) on Jun 17, 2010 at 07:54 UTC
    PAR installs the scandeps.pl program which can be called on any Perl file and it will list the dependencies.

    You could take this dependency list and check for sub or (my|our|local) declarations, thus listing your methods and vars.

    That's the first approach that comes to mind, (because I've been fiddling with PAR recently), hope it helps

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
      scandeps lists modules/files, not methods/variables
Re: get the list of methods and variables
by Anonymous Monk on Jun 17, 2010 at 08:09 UTC
Re: get the list of methods and variables
by Khen1950fx (Canon) on Jun 17, 2010 at 09:17 UTC
    To get a list of methods and variables from child.pm, I would use Devel::Symdump. Here's an example:
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper::Concise; require Devel::Symdump; my @packs = qw(Data::Dumper::Concise); my $obj = Devel::Symdump->new(@packs); my @array = $obj->scalars; @array = $obj->arrays; @array = $obj->hashes; my $string = $obj->as_string; print $string, "\n";
    I substituted Data::Dumper::Concise for Grandparent::Parent::Child; also, make sure that you "use" the package just below use warnings.
Re: get the list of methods and variables
by almut (Canon) on Jun 17, 2010 at 09:36 UTC

    Class::Inspector might also help.  For example:

    #!/usr/bin/perl -l package PkgA; sub fooA {} sub barA {} package PkgB; use base "PkgA"; sub fooB {} package PkgC; use base "PkgB"; sub barC {} package main; use Class::Inspector; print for @{ Class::Inspector->methods('PkgC', 'full') }; __END__ PkgA::barA PkgC::barC PkgA::fooA PkgB::fooB

    Or, if you want to call it from within the child package (PkgC):

    ... package PkgC; ... use Class::Inspector; print for @{ Class::Inspector->methods(__PACKAGE__, 'full') };
Re: get the list of methods and variables
by planetscape (Canon) on Jun 17, 2010 at 16:53 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://845154]
Approved by Utilitarian
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-07-28 05:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (186 votes), past polls