[Chicago-talk] Asking an class for its method list

Ed Summers ehs at pobox.com
Sun Jan 25 19:34:16 CST 2004


On Sun, Jan 25, 2004 at 06:06:10PM -0600, Steven Lembark wrote:
> I don't know if the Module::Info gives you all of the
> inherited methods; I certianly know that it cannot
> extrapolate AUTOLOAD results a-priori (except for auto
> split, and even that can be problematic).

AUTOLOAD is trouble yeah :) Module::Info has a useful superclasses() method
to get at parent classes, which (with a bit of recursion) can return the 
subs:

    #!/usr/bin/perl

    use Module::Info;

    print printSubs( shift );

    sub printSubs {
        my $class = shift;
        return() if ! $class;

        my $module = Module::Info->new_from_module( $class );
        my %subs = $module->subroutines();
        map { print $_."\n" } keys( %subs );

        foreach my $parent ( $module->superclasses() ) {
            printSubs( $parent );
        }
    }

//Ed


    



More information about the Chicago-talk mailing list