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.

#!/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;
-stvn

In reply to Class/Object Method Lister by stvn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.