Subject: | Support Devel::StackTrace max_arg_length feature |
In Devel::StackTrace #33519, I requested a new max_arg_length option to
limit the size of arguments displayed. You added it in 1.18.
Exception::Class needs a way to pass this option to the
Devel::StackTrace objects that it creates. Attached is a patch that
adds the support.
Subject: | Exception-Class-MaxArgLength.patch |
diff -r 9b71c80a0872 -r 0c145db6992e lib/Exception/Class.pm
--- a/lib/Exception/Class.pm Tue Feb 26 13:30:49 2008 -0800
+++ b/lib/Exception/Class.pm Tue Feb 26 14:11:43 2008 -0800
@@ -204,6 +204,8 @@ BEGIN
__PACKAGE__->mk_classdata('RespectOverload');
__PACKAGE__->RespectOverload(0);
+ __PACKAGE__->mk_classdata('MaxArgLength');
+ __PACKAGE__->MaxArgLength(0);
sub Fields { () }
}
@@ -300,6 +302,7 @@ sub _initialize
ignore_package => \@ignore_package,
no_refs => $self->NoRefs,
respect_overload => $self->RespectOverload,
+ max_arg_length => $self->MaxArgLength,
);
if ( my $frame = $self->trace->frame(0) )
@@ -635,6 +638,19 @@ subclasses but setting it in a subclass
subclasses but setting it in a subclass makes it independent
thereafter.
+=item * MaxArgLength($boolean)
+
+When a C<Devel::StackTrace> object stringifies, it can limit the
+length of arguments displayed.
+
+Since C<Exception::Class::Base> uses C<Devel::StackTrace> internally,
+this method provides a way to tell C<Devel::StackTrace> to limit the
+length of arguments.
+
+This method defaults to 0, for full arguments. As with C<Trace()>, it
+is inherited by subclasses but setting it in a subclass makes it
+independent thereafter.
+
=item * Fields
This method returns the extra fields defined for the given class, as
diff -r 9b71c80a0872 -r 0c145db6992e t/basic.t
--- a/t/basic.t Tue Feb 26 13:30:49 2008 -0800
+++ b/t/basic.t Tue Feb 26 14:11:43 2008 -0800
@@ -4,7 +4,7 @@ use strict;
use File::Spec;
-use Test::More tests => 56;
+use Test::More tests => 58;
use_ok('Exception::Class');
@@ -364,6 +364,23 @@ sub FieldsException::full_message
ok( $classes{TestException}, 'TestException should be in the return from Classes()' );
}
+{
+ sub throw { TestException->throw( error => 'dead' ); }
+
+ eval { throw('abcdefghijklmnop') };
+ my $e = $@;
+
+ like( $e->as_string, qr/'abcdefghijklmnop'/, 'arguments are not truncated by default' );
+
+ TestException->MaxArgLength(10);
+
+ eval { throw('abcdefghijklmnop') };
+ $e = $@;
+
+ like( $e->as_string, qr/'abcdefghij\.\.\.'/, 'arguments are now truncated' );
+}
+
+
sub argh
{
Exception::Class::Base->throw( error => 'ARGH' );