http://qs321.pair.com?node_id=845154

v.muthukumaran 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

Replies are listed 'Best First'.
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 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::Concisefor Grandparent::Parent::Child; also, make sure that you "use" the package just below use warnings.
Re: get the list of methods and variables
by planetscape (Chancellor) on Jun 17, 2010 at 16:53 UTC
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