diff -r 299de5a1f25e -r 778dc4a6d56c lib/Devel/StackTrace.pm
--- a/lib/Devel/StackTrace.pm Fri Feb 22 11:09:55 2008 -0800
+++ b/lib/Devel/StackTrace.pm Tue Feb 26 13:48:23 2008 -0800
@@ -12,7 +12,6 @@ use overload
fallback => 1;
$VERSION = '1.16';
-
sub new
{
@@ -127,7 +126,7 @@ sub _add_frame
}
push @{ $self->{frames} },
- Devel::StackTraceFrame->new( $c, $args, $self->{respect_overload} );
+ Devel::StackTraceFrame->new( $c, $args, $self->{respect_overload}, $self->{max_arg_length} );
}
sub _ref_as_string
@@ -265,6 +264,8 @@ BEGIN
$self->{args} = $_[1];
$self->{respect_overload} = $_[2];
+
+ $self->{max_arg_lengtH} = $_[3];
return $self;
}
@@ -327,6 +328,10 @@ sub as_string
$_ = $self->Devel::StackTrace::_ref_as_string($_)
if ref $_;
+ if ($self->{max_arg_length} && length($_) > $self->{max_arg_length}) {
+ substr($_, $self->{max_arg_length}) = '...';
+ }
+
s/'/\\'/g;
# 'quote' arg unless it looks like a number
@@ -454,6 +459,12 @@ prefer to see the overloaded representat
prefer to see the overloaded representation of objects in stack
traces, then set this parameter to true.
+=item * max_arg_length => $integer
+
+By default, Devel::StackTrace will display the full length of
+arguments (default of 0). This parameter can be set to the maximum length to display
+for all arguments.
+
=back
=item * $trace->next_frame
diff -r 299de5a1f25e -r 778dc4a6d56c t/01-basic.t
--- a/t/01-basic.t Fri Feb 22 11:09:55 2008 -0800
+++ b/t/01-basic.t Tue Feb 26 13:48:23 2008 -0800
@@ -4,7 +4,7 @@ use Test::More;
BEGIN
{
- my $tests = 34;
+ my $tests = 35;
eval { require Exception::Class };
$tests++ if ! $@ && $Exception::Class::VERSION >= 1.09;
@@ -256,6 +256,17 @@ if ( $Exception::Class::VERSION && $Exce
}
+{
+ my $trace = max_arg_length('x' x 20);
+
+ my $trace_text = <<"EOF";
+Trace begun at $test_file_name line 1027
+main::max_arg_length('xxxxxxxxxxxxxxxxxxxx') called at t/01-basic.t line 260
+EOF
+
+ is( $trace->as_string, $trace_text, 'trace text' );
+}
+
SKIP:
{
skip "Test only runs on Linux", 1
@@ -296,6 +307,10 @@ sub respect_overloading
Devel::StackTrace->new( respect_overload => 1 );
}
+sub max_arg_length
+{
+ Devel::StackTrace->new( max_arg_length => 10 );
+}
package Test;