Skip to content
Browse files

Add no_args option

  • Loading branch information...
1 parent a99b865 commit eb8547597f95095fd7655aef47eb40e6f661e24e @autarch committed Oct 6, 2011
Showing with 63 additions and 5 deletions.
  1. +18 −5 lib/Devel/StackTrace.pm
  2. +45 −0 t/07-no-args.t
View
23 lib/Devel/StackTrace.pm
@@ -40,17 +40,25 @@ sub _record_caller_data {
# We exclude this method by starting one frame back.
my $x = 1;
while (
- my @c = do {
+ my @c
+ = $self->{no_args}
+ ? caller( $x++ )
+ : do {
package # the newline keeps dzil from adding a version here
DB;
@DB::args = ();
caller( $x++ );
}
) {
- my @args = @DB::args;
- if ( $self->{no_refs} ) {
- @args = map { ref $_ ? $self->_ref_to_string($_) : $_ } @args;
+ my @args;
+
+ unless ( $self->{no_args} ) {
+ @args = @DB::args;
+
+ if ( $self->{no_refs} ) {
+ @args = map { ref $_ ? $self->_ref_to_string($_) : $_ } @args;
+ }
}
push @{ $self->{raw} },
@@ -99,7 +107,7 @@ sub _make_frame_filter {
my ( @i_pack_re, %i_class );
if ( $self->{ignore_package} ) {
$self->{ignore_package} = [ $self->{ignore_package} ]
- unless UNIVERSAL::isa( $self->{ignore_package}, 'ARRAY' );
+ unless eval { @{ $self->{ignore_package} } };
@i_pack_re
= map { ref $_ ? $_ : qr/^\Q$_\E$/ } @{ $self->{ignore_package} };
@@ -338,6 +346,11 @@ your objects go out of scope.
Devel::StackTrace replaces any references with their stringified
representation.
+=item * no_args => $boolean
+
+If this parameter is true, then Devel::StackTrace will not store caller
+arguments in stack trace frames at all.
+
=item * respect_overload => $boolean
By default, Devel::StackTrace will call C<overload::AddrRef()> to get
View
45 t/07-no-args.t
@@ -0,0 +1,45 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use Devel::StackTrace;
+
+{
+ my $trace = foo( 1, 2 );
+ is_deeply(
+ [ map { [ $_->args() ] } $trace->frames() ],
+ [
+ ['Devel::StackTrace'],
+ [ 3, 4 ],
+ [ 1, 2 ],
+ ],
+ 'trace includes args'
+ );
+
+ $trace = foo( 0, 2 );
+ is_deeply(
+ [ map { [ $_->args() ] } $trace->frames() ],
+ [
+ [],
+ [],
+ [],
+ ],
+ 'trace does not include args'
+ );
+
+}
+
+done_testing();
+
+sub foo {
+ $_[0] ? bar( 3, 4 ) : baz( 3, 4 );
+}
+
+sub bar {
+ return Devel::StackTrace->new();
+}
+
+sub baz {
+ return Devel::StackTrace->new( no_args => 1 );
+}

0 comments on commit eb85475

Please sign in to comment.
Something went wrong with that request. Please try again.