On 28 Feb 2008, at 09:22, Smylers wrote:
That should be s/return 1/return/ at the end. Sorry, I edited from my
real ~/.perldb (which contains a load of other stuff) ...
Oooh, what other stuff? As somebody who doesn't have a .perldb at all
(I'm not even sure I was aware of it before this thread) I'm intrigued
as to what's possible.
Well it's messy and apart from the "stop at test #n" hack it's nearly
all
either Mac/TextMate specific or Perl 5.10 specific - but here it is.
use TextMate::JumpTo qw(jumpto);
use File::Spec;
my @opts = qw( windowSize=30 );
if ( $] >= 5.010000 ) {
push @opts, "HistFile='" . glob( '~/.perldb_history' ) . "'";
}
parse_options( $_ ) for @opts;
@DB::testbreak = ();
# Monkeypatch cmd_b (set breakpoint)
my $cmd_b = \&DB::cmd_b;
*DB::cmd_b = sub {
my ( $cmd, $line, $dbline ) = @_;
if ( $line =~ /\s*#\s*(\d+(?:\s*,\s*\d+)*)$/ ) {
my %seen;
@DB::testbreak = grep { !$seen{$_}++ }
sort { $a <=> $b } ( split( /\s*,\s*/, $1 ),
@DB::testbreak );
require Test::Builder;
}
else {
$cmd_b->( @_ );
}
};
sub afterinit {
$trace |= 4; # Enable watchfunction
# Needed to work out where filenames are relative to
chomp( $base_dir = `pwd` );
$option{animate} = 0;
push @options, 'animate';
}
sub watchfunction {
if ( @DB::testbreak ) {
my $current = Test::Builder->new->current_test;
if ( $current + 1 >= $DB::testbreak[0] ) {
shift @DB::testbreak
while @DB::testbreak && $current + 1 >=
$DB::testbreak[0];
my $depth = 1;
while ( 1 ) {
my ( $package, $file, $line ) = caller $depth;
last unless defined $package;
last unless $package =~ /^Test::/;
$depth++;
}
$DB::stack[ -$depth ] = 1;
}
}
return textmate( @_ );
}
sub textmate {
my ( $package, $file, $line ) = @_;
return unless $single || $signal || $option{animate};
return if $file =~ m{/perl5db[.]pl$};
local $trace = 0;
# Doesn't really work
if ( $file =~ /^\(eval\s+\d+\)\[(.+?):(\d+)\]/ ) {
$file = $1;
$line += $2 - 1;
}
jumpto(
file => File::Spec->rel2abs( $file, $base_dir ),
line => $line,
bg => 1
);
return 1;
}
I use the debugger only infrequently, but perhaps with some tweaked
config I'd be inclined to use it more.
Having command history (5.10 only) was a key factor in getting me to use
it more. The gubbins that syncs debugger position with my editor is,
frankly, a mixed blessing. Generally it's a good thing but I probably
need to add an option to turn it off in the case that I'm debugging
something that I don't want to have open in my editor.
The editor sync is also the reason I wanted the break-at-test-#n hack to
exit any Test::* packages before stopping. Without that I end up with
half of Test::Builder / Test::More / Test::Whatever open in my editor :)
Any chance of a 'Me and My .perldb' (lightning) talk somewhere?
Well there's not that much to mine yet. But I am planning to do a talk
(Leeds.pm) on the Perl tools I use which would include those debugger
hacks. If it goes well with the home crowd I could probably do the same
talk for London.pm sometime :)
--
Andy Armstrong, Hexten