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??
[arc444]: hi. Anyone know how to filter the list of methods returned when querying an object in the perl debugger ?
[arc444]: for example : m $obj | grep blah

Reading help in the debugger hasn't shown anything related; reading confirmed such a feature didn't exist. So, the only way was to patch the debugger.

I didn't have much time, so the solution is ugly: the syntax for classes is different to the syntax for objects. For objects, you have to use strings and separate the argument by a comma, for classes, the comma is forbidden and the regex is specified directly without quotes:

$ perl -d -e 'sub foo { "bar" }; $o = bless {}, "main"' Loading DB routines from version 1.39_10 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(-e:1): sub foo { "bar" }; $o = bless {}, "main" DB<1> m $o foo via UNIVERSAL: DOES via UNIVERSAL: VERSION via UNIVERSAL: can via UNIVERSAL: isa DB<2> m $o, '(?i:o)' foo via UNIVERSAL: DOES via UNIVERSAL: VERSION DB<3> m main foo via UNIVERSAL: DOES via UNIVERSAL: VERSION via UNIVERSAL: can via UNIVERSAL: isa DB<4> m main (?i:o) foo via UNIVERSAL: DOES via UNIVERSAL: VERSION

And here's the patch:

diff --git a/lib/ b/lib/ index ecc49a814d..d50dfd22b4 100644 --- a/lib/ +++ b/lib/ @@ -767,7 +767,7 @@ sub eval { dumpit( $OUT, \@res ); } elsif ( $onetimeDump eq 'methods' ) { - methods( $res[0] ); + methods( @res ); } } ## end elsif ($onetimeDump) @res; @@ -2395,8 +2395,8 @@ sub _DB__handle_run_command_in_pager_command { sub _DB__handle_m_command { my ($obj) = @_; - if ($cmd =~ s#\Am\s+([\w:]+)\s*\z# #) { - methods($1); + if ($cmd =~ s#\Am\s+([\w:]+)\s*(.*)# #) { + methods($1, $2); next CMD; } @@ -8894,16 +8894,16 @@ sub methods { # Figure out the class - either this is the class or it's a refer +ence # to something blessed into that class. - my $class = shift; + my ($class, $filter) = @_; $class = ref $class if ref $class; local %seen; # Show the methods that this class has. - methods_via( $class, '', 1 ); + methods_via( $class, '', $filter, 1 ); # Show the methods that UNIVERSAL has. - methods_via( 'UNIVERSAL', 'UNIVERSAL', 0 ); + methods_via( 'UNIVERSAL', 'UNIVERSAL', $filter, 0 ); } ## end sub methods =head2 C<methods_via($class, $prefix, $crawl_upward)> @@ -8927,6 +8927,7 @@ sub methods_via { my $prepend = $prefix ? "via $prefix: " : ''; my @to_print; + my $filter = shift; # Extract from all the symbols in this class. my $class_ref = do { no strict "refs"; \%{$class . '::'} }; while (my ($name, $glob) = each %$class_ref) { @@ -8939,7 +8940,7 @@ sub methods_via { # \$glob will be SCALAR in both cases. if ((ref $glob || ($glob && ref \$glob eq 'GLOB' && defined & +$glob)) && !$seen{$name}++) { - push @to_print, "$prepend$name\n"; + push @to_print, "$prepend$name\n" unless $filter && $name + !~ /$filter/; } } @@ -8961,7 +8962,7 @@ sub methods_via { $prepend = $prefix ? $prefix . " -> $name" : $name; # Crawl up the tree and keep trying to crawl up. - methods_via( $name, $prepend, 1 ); + methods_via( $name, $prepend, $filter, 1 ); } } ## end sub methods_via

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

In reply to Filtering methods in Perl debugger by choroba

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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (4)
    As of 2018-08-18 17:53 GMT
    Find Nodes?
      Voting Booth?
      Asked to put a square peg in a round hole, I would:

      Results (185 votes). Check out past polls.