It's maybe the start of an automated OO documentation tool. It provides 2 views of your class. The first is the flat view, where it lists all the methods available to an object implemented and inherited. The second is the expanded view, which lists all the implemented methods, then climbs down the classes inheritance heirarchy doing the same for each class (and tabbing it in appropriately too).
The example given in this script is to list the IO::File class, which has a deep enough heirarchy to show how this works.
-stvn#!/usr/bin/perl use strict; use warnings; no strict 'refs'; ## ------------------------------------------------------------------ # if you want certain methods ignored, # put their names in this string and it # will get weeded out with a reg-ex. my $IGNORE = ""; sub getClassMethodList { my $class = shift; return grep { !/^($IGNORE)$/ && defined &{"${class}::$_"} } keys %{"${class}::"}; } sub getCompleteClassMethodList { my ($class) = @_; my @methods = getClassMethodList($class); push @methods => map { getCompleteClassMethodList($_) } @{"${class}::ISA"}; return @methods; } ## ------------------------------------------------------------------ sub printExpandedClassView { my ($class, $tab_count) = @_; $tab_count ||= 0; if ($tab_count) { my $t = ("\t" x $tab_count); print "${t}$class\n"; print "${t}-------------------------------------------\n$t"; print join "\n${t}", getClassMethodList($class); print "\n"; } else { print("$class\n"); print "-------------------------------------------\n"; print join "\n" => getClassMethodList($class); print "\n"; } map { printExpandedClassView($_, $tab_count + 1) } @{"${class}::ISA"}; } sub printFlatClassView { my ($class) = @_; print("$class\n"); print "-------------------------------------------\n"; my %method = map { $_ => 1 } getCompleteClassMethodList($class); print join "\n" => keys %method; print "\n"; } ## ------------------------------------------------------------------ use IO::File; printFlatClassView("IO::File"); print "\n"; printExpandedClassView("IO::File"); print "\n"; 1;
In reply to Class/Object Method Lister by stvn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |