Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Devel-StackTrace CPAN distribution.

Report information
The Basics
Id: 47415
Status: resolved
Priority: 0/
Queue: Devel-StackTrace

People
Owner: Nobody in particular
Requestors: rafl [...] debian.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.20
Fixed in: 1.21



Subject: Allow skipping of frames at the top of the trace
There should be a way to skip frames at the top of a stack trace, until some condition is met. That's useful for other objects storing Devel::StackTrace instances inside them and constructing them when they are constructed. Most of the time they don't want the stack frames of their own construction in their Devel::StackTrace. Throwable is one example for this.
Subject: 0001-Add-possibility-to-determine-the-start-of-the-trace-.patch
From 21c65217ea1f2282af167e90cbfba681b18c354b Mon Sep 17 00:00:00 2001 From: Florian Ragwitz <rafl@debian.org> Date: Tue, 16 Jun 2009 00:52:10 +0200 Subject: [PATCH 1/2] Add possibility to determine the start of the trace using a callback. --- lib/Devel/StackTrace.pm | 12 +++++++++--- t/03-skip-start.t | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 t/03-skip-start.t diff --git a/lib/Devel/StackTrace.pm b/lib/Devel/StackTrace.pm index 90df0f6..e96c317 100644 --- a/lib/Devel/StackTrace.pm +++ b/lib/Devel/StackTrace.pm @@ -26,9 +26,10 @@ sub new if exists $p{no_object_refs}; my $self = - bless { index => undef, - frames => [], - raw => [], + bless { index => undef, + frames => [], + raw => [], + find_start_frame => sub { 1 }, %p, }, $class; @@ -118,8 +119,13 @@ sub _make_frames push @i_pack_re, qr/^\Q$p\E$/; my $raw = delete $self->{raw}; + my $found_start = 0; + for my $r ( @{$raw} ) { + $found_start ||= $self->{find_start_frame}->($r); + next unless $found_start; + next if grep { $r->{caller}[0] =~ /$_/ } @i_pack_re; next if grep { $r->{caller}[0]->isa($_) } keys %i_class; diff --git a/t/03-skip-start.t b/t/03-skip-start.t new file mode 100644 index 0000000..a54271b --- /dev/null +++ b/t/03-skip-start.t @@ -0,0 +1,30 @@ +use strict; +use warnings; + +use Test::More tests => 4; + +use Devel::StackTrace; + +sub foo +{ + bar(); +} + +sub bar +{ + my $i = 0; + return ( + Devel::StackTrace->new, + Devel::StackTrace->new(find_start_frame => sub { $i++ }), + ); +} + +my @frames = map { [$_->frames] } foo(); +is(scalar @{ $frames[0] }, 3); +is(scalar @{ $frames[1] }, 2); + +shift @{ $frames[0] }; +for my $i (0 .. $#{ $frames[0] }) +{ + is($frames[0]->[$i]->as_string, $frames[1]->[$i]->as_string); +} -- 1.6.3.1.57.gbd5ef
Oh, there's docs, too!
From 6e6b84b51c7c9103c18bd594b6747a60e1cada4f Mon Sep 17 00:00:00 2001 From: Florian Ragwitz <rafl@debian.org> Date: Sun, 28 Jun 2009 16:23:45 +0200 Subject: [PATCH 2/2] Add docs for find_start_frame. --- lib/Devel/StackTrace.pm | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/lib/Devel/StackTrace.pm b/lib/Devel/StackTrace.pm index e96c317..85fb2b7 100644 --- a/lib/Devel/StackTrace.pm +++ b/lib/Devel/StackTrace.pm @@ -490,6 +490,17 @@ each subroutine call. Setting this parameter causes it to truncate the argument's string representation if it is longer than this number of characters. +=item * find_start_frame => \&subroutine + +By default, Devel::StackTrace will include all stack frames above the +call to its constructor. Sometimes, for example when your putting your +logic to construct stack traces in its own function, you want to skip +additional frames at the top of the stack. To do that, you can specify +a code reference for the C<find_start_frame> option. The coderef will +be called for each raw frame (a hash reference with C<caller> and +C<args> keys) until it returns a true value. The first frame it +returns something true for, will be the start of the trace. + =back =item * $trace->next_frame -- 1.6.3.1.57.gbd5ef