Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This is a nice module, and should be combined with Symbol::Sub::Approx to actively help (while issuing a warning). :-)

There's a major problem with it though; the usual AUTOLOAD problem. Maybe another class in the inheritance tree has an AUTOLOAD to handle it. Then Help isn't really helping--rather the opposite. So you need to do

use 5.010; use mro; # Make next::can available. use Sub::Name (); # Used to make next::can work # in anonymous subroutines. sub AUTOLOAD { my ($bottom_class, $method) = $AUTOLOAD =~ /(.*)::(.*)/s; # Note the /s above. It's legal to have # newlines in packages and symbols. my $next = Sub::Name::subname( $method => sub { $bottom_class->next::can } )->(); goto &$next if $next; ...; }
By adding just two more statements in AUTOLOAD you illustrate a new Perl 5.10 feature. :-)

But when moving onto Perl 5.10 your algorithm, while elegant and simple, becomes fragile due to the new method resolution orders (mro). Utilizing the lovely Devel::Symdump module by Andreas J. König you can replace

my %known_method; my @classes = ($bottom_class); while (@classes) { my $class = shift @classes; next if $class eq __PACKAGE__; unshift @classes, @{"$class\::ISA"}; for my $name (keys %{"$class\::"}) { next unless defined &{"$class\::$name"}; $known_method{$name} ||= $class; } }
use Devel::Symdump; my %known_method = reverse map /(.*)::(.*)/s, map Devel::Symdump::->functions($_), grep $_ ne __PACKAGE__, @{mro::get_linear_isa($class)} ;
If you're on a pre 5.10 perl you can use Class::ISA's self_and_super_path. (I've contacted Mr Burke, the maintainer of Class::ISA, about updating it to use mro::get_linear_isa when it's available. Currently you need to figure out that yourself.)

Of course, this makes it much less educational about the symbol table. :-)

Update: I remembered that Help makes itself part of the inheritance tree, so I've removed the import of &subname to avoid it being inherited, and removed Help from %known_method.


In reply to Re: automatically explains how to use misused objects by lodin
in thread automatically explains how to use misused objects by Dominus

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2022-11-28 19:11 GMT
Find Nodes?
    Voting Booth?