I have to pick a nit. The second one doesn't answer "of the methods that the given class can handle, which ones are defined in the given class?". The (psuedo)code for that would be @local = grep defined &{$class . "::$_"}, $obj->list_all_my_methods. The second one answers the question "of all the symbols in the given class, which ones are names of methods of the given class?".

Case in point:

package Parent; sub foo { 1 } package Child; @ISA = 'Parent'; sub new { bless {}, shift } $foo = 10; package main; my $pkg = "Child"; print join(", ", grep defined &{ $pkg . "::$_" }, keys %{ $pkg . '::' +}), "\n"; print join(", ", grep $pkg->can( $_ ), keys %{ $pkg . '::' }), "\n";
This prints "new" on the first line, and "new, foo" on the second. I changed the defined() test a bit, because with $pkg in there, it's saying "of the symbols in $pkg, which are defined as functions in this current package I'm in?" rather than "... which are defined as functions in $pkg?".

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

In reply to Re^2: defined &{ $pkg . '::foo' } vs. $pkg->can( 'foo' ) by japhy
in thread defined &{ $pkg . '::foo' } vs. $pkg->can( 'foo' ) by tlm

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.