| 1 | package DB::Pluggable::Dumper; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use 5.008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Data::Dumper (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use parent 'DB::Pluggable::Plugin'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | my $eval = \&DB::eval; | ||
| 11 | |||
| 12 | sub register { | ||
| 13 | my ( $self, $context ) = @_; | ||
| 14 | $self->make_command( xx => sub { }, ); | ||
| 15 | } | ||
| 16 | |||
| 17 | # XXX I couldn't make this work by pushing the eval override into | ||
| 18 | # DB::Pluggable :( | ||
| 19 | { | ||
| 20 | package # hide from pause | ||
| 21 | DB; | ||
| 22 | *eval = sub { | ||
| 23 | if ( $DB::evalarg =~ s/\n\s*xx\s+([^\n]+)$/\n $1/ ) { | ||
| 24 | no warnings 'redefine'; | ||
| 25 | local $DB::onetimeDump = 'dump'; # main::dumpvar shows the output | ||
| 26 | local *DB::dumpit = sub { | ||
| 27 | my ( $fh, $res ) = @_; | ||
| 28 | my $dd = Data::Dumper->new( [] ); | ||
| 29 | $dd->Terse(1)->Indent(1)->Useqq(1)->Deparse(1)->Quotekeys(0) | ||
| 30 | ->Sortkeys(1); | ||
| 31 | print $fh $dd->Values($res)->Dump; | ||
| 32 | }; | ||
| 33 | $eval->(); | ||
| 34 | } | ||
| 35 | else { | ||
| 36 | $eval->(); | ||
| 37 | } | ||
| 38 | }; | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; | ||
| 42 | |||
| 43 | =head1 NAME | ||
| 44 | |||
| 45 | DB::Pluggable::Dumper - Add 'xx' dumper to debugger | ||
| 46 | |||
| 47 | =head1 VERSION | ||
| 48 | |||
| 49 | Version 0.01 | ||
| 50 | |||
| 51 | =cut | ||
| 52 | |||
| 53 | our $VERSION = '0.01'; | ||
| 54 | |||
| 55 | =head1 SYNOPSIS | ||
| 56 | |||
| 57 | In your C<$HOME/.perldb>: | ||
| 58 | |||
| 59 | #!/usr/bin/env perl | ||
| 60 | |||
| 61 | use DB::Pluggable; | ||
| 62 | use YAML; | ||
| 63 | |||
| 64 | $DB::PluginHandler = DB::Pluggable->new( config => Load <<'END'); | ||
| 65 | global: | ||
| 66 | log: | ||
| 67 | level: error | ||
| 68 | |||
| 69 | plugins: | ||
| 70 | - module: Dumper | ||
| 71 | END | ||
| 72 | |||
| 73 | $DB::PluginHandler->run; | ||
| 74 | |||
| 75 | =head1 DESCRIPTION | ||
| 76 | |||
| 77 | This module adds the C<xx> command to the debugger. It's like the C<x> | ||
| 78 | command, but outputs pretty L<Data::Dumper> format. Here's the output of a | ||
| 79 | data structure with 'x': | ||
| 80 | |||
| 81 | auto(-2) DB<2> x $before | ||
| 82 | 0 HASH(0x100e7e8f0) | ||
| 83 | 'aref' => ARRAY(0x1009000d8) | ||
| 84 | 0 1 | ||
| 85 | 1 2 | ||
| 86 | 2 4 | ||
| 87 | 'guess' => CODE(0x100829568) | ||
| 88 | -> &main::testit in run.pl:3-6 | ||
| 89 | 'uno' => HASH(0x100803108) | ||
| 90 | 'this' => 'that' | ||
| 91 | 'what?' => HASH(0x100e3d508) | ||
| 92 | 'this' => 'them' | ||
| 93 | |||
| 94 | Here's the same data structure with 'xx': | ||
| 95 | |||
| 96 | auto(-1) DB<3> xx $after | ||
| 97 | { | ||
| 98 | aref => [ | ||
| 99 | 1, | ||
| 100 | 2, | ||
| 101 | 4 | ||
| 102 | ], | ||
| 103 | guess => sub { | ||
| 104 | my $x = shift @_; | ||
| 105 | return $x + 1; | ||
| 106 | }, | ||
| 107 | uno => { | ||
| 108 | this => "that", | ||
| 109 | "what?" => { | ||
| 110 | this => "them" | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | Which would you rather debug? | ||
| 116 | |||
| 117 | =head1 TODO | ||
| 118 | |||
| 119 | =over 4 | ||
| 120 | |||
| 121 | =item * Add support for L<Data::Dump::Streamer>. | ||
| 122 | |||
| 123 | =item * Push the eval hack back into L<DB::Pluggable>. | ||
| 124 | |||
| 125 | =item * Allow control over dumper configuration. | ||
| 126 | |||
| 127 | =back | ||
| 128 | |||
| 129 | =head1 SEE ALSO | ||
| 130 | |||
| 131 | =over 4 | ||
| 132 | |||
| 133 | =item * L<DB::Pluggable> | ||
| 134 | |||
| 135 | Marcel GrĂ¼nauer wrote this to add plugin support to the Perl debugger. Has | ||
| 136 | L<DB::Pluggable::BreakOnTestNumber> and L<DB::Pluggable::TypeAhead> included. | ||
| 137 | |||
| 138 | =item * L<DB::Pluggable::StackTraceAsHTML> | ||
| 139 | |||
| 140 | Adds a 'C<Th>' command to the debugger. Opens up a strack trace in your | ||
| 141 | browswer, complete with lexicals. | ||
| 142 | |||
| 143 | =head1 NOTE | ||
| 144 | |||
| 145 | This code is an awful hack because the perl debugger (C<perl5db.pl>) is an | ||
| 146 | awful hack. My apologies. | ||
| 147 | |||
| 148 | =back | ||
| 149 | |||
| 150 | =head1 AUTHOR | ||
| 151 | |||
| 152 | Curtis "Ovid" Poe, C<< <ovid at cpan.org> >> | ||
| 153 | |||
| 154 | =head1 BUGS | ||
| 155 | |||
| 156 | Please report any bugs or feature requests to C<bug-db-pluggable-dumper at | ||
| 157 | rt.cpan.org>, or through the web interface at | ||
| 158 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DB-Pluggable-Dumper>. I will | ||
| 159 | be notified, and then you'll automatically be notified of progress on your bug | ||
| 160 | as I make changes. | ||
| 161 | |||
| 162 | =head1 SUPPORT | ||
| 163 | |||
| 164 | You can find documentation for this module with the perldoc command. | ||
| 165 | |||
| 166 | perldoc DB::Pluggable::Dumper | ||
| 167 | |||
| 168 | You can also look for information at: | ||
| 169 | |||
| 170 | =over 4 | ||
| 171 | |||
| 172 | =item * RT: CPAN's request tracker | ||
| 173 | |||
| 174 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DB-Pluggable-Dumper> | ||
| 175 | |||
| 176 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 177 | |||
| 178 | L<http://annocpan.org/dist/DB-Pluggable-Dumper> | ||
| 179 | |||
| 180 | =item * CPAN Ratings | ||
| 181 | |||
| 182 | L<http://cpanratings.perl.org/d/DB-Pluggable-Dumper> | ||
| 183 | |||
| 184 | =item * Search CPAN | ||
| 185 | |||
| 186 | L<http://search.cpan.org/dist/DB-Pluggable-Dumper/> | ||
| 187 | |||
| 188 | =back | ||
| 189 | |||
| 190 | =head1 ACKNOWLEDGEMENTS | ||
| 191 | |||
| 192 | =over 4 | ||
| 193 | |||
| 194 | =item * Marcel GrĂ¼nauer (for L<DB::Pluggable>) | ||
| 195 | |||
| 196 | =item * Matt Trout (for L<Data::Dumper::Concise>) | ||
| 197 | |||
| 198 | =item * Vienna.pm, for sponsoring the 2010 Perl QA Hackathon | ||
| 199 | |||
| 200 | =back | ||
| 201 | |||
| 202 | =head1 COPYRIGHT & LICENSE | ||
| 203 | |||
| 204 | Copyright 2010 Curtis "Ovid" Poe, all rights reserved. | ||
| 205 | |||
| 206 | This program is free software; you can redistribute it and/or modify it | ||
| 207 | under the same terms as Perl itself. | ||
| 208 | |||
| 209 | =cut | ||
| 210 | |||
| 211 | 1; # End of DB::Pluggable::Dumper | ||