Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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":

  • 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, 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, 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (8)
    As of 2021-05-06 12:38 GMT
    Find Nodes?
      Voting Booth?
      Perl 7 will be out ...

      Results (74 votes). Check out past polls.