[prev in list] [next in list] [prev in thread] [next in thread]
List: mason-cvs
Subject: [Mason-checkins] [3830] Change errors_are_exceptions to
From: autarch () urth ! org
Date: 2007-05-12 15:51:49
Message-ID: E1Hmtsr-0001N8-Q3 () urth ! org
[Download RAW message or body]
Revision: 3830
Author: autarch
Date: 2007-05-12 10:51:49 -0500 (Sat, 12 May 2007)
ViewCVS: https://svn.urth.org/listing.php?repname=Mason&rev=3830
Log Message:
-----------
Change errors_are_exceptions to component_error_handler, and make the
parameter accept a subroutine reference or false value, as opposed to
just a boolean.
Modified Paths:
--------------
trunk/lib/HTML/Mason/Request.pm
trunk/lib/HTML/Mason.pm
trunk/t/13-errors.t
Modified: trunk/lib/HTML/Mason/Request.pm
===================================================================
--- trunk/lib/HTML/Mason/Request.pm 2007-05-09 20:18:05 UTC (rev 3829)
+++ trunk/lib/HTML/Mason/Request.pm 2007-05-12 15:51:49 UTC (rev 3830)
@@ -112,9 +112,9 @@
regex => qr/^(?:output|fatal)$/,
descr => "How error conditions are manifest (output or fatal)" },
- errors_are_exceptions =>
- { parse => 'boolean', type => BOOLEAN, default => 1,
- descr => "Whether errors thrown by components should always be upgraded \
to exception objects" }, + component_error_handler =>
+ { parse => 'code', type => CODEREF|SCALAR, default => \&rethrow_exception,
+ descr => "A subroutine reference called on component compilation or \
runtime errors" },
max_recurse =>
{ parse => 'string', default => 32, type => SCALAR,
@@ -149,12 +149,12 @@
my @read_write_params;
BEGIN { @read_write_params = qw(
autoflush
+ component_error_handler
data_cache_api
data_cache_defaults
dhandler_name
error_format
error_mode
- errors_are_exceptions
max_recurse
out_method
); }
@@ -224,8 +224,8 @@
sub _initialize {
my ($self) = @_;
- local $SIG{'__DIE__'} = \&rethrow_exception
- if $self->errors_are_exceptions;
+ local $SIG{'__DIE__'} = $self->component_error_handler
+ if $self->component_error_handler;
eval {
# Check the static_source touch file, if it exists, before the
@@ -380,9 +380,8 @@
# at the bottom of _initialize(); just return.
return unless $self->initialized();
- # All errors returned from this routine will be in exception form.
- local $SIG{'__DIE__'} = \&rethrow_exception
- if $self->errors_are_exceptions;
+ local $SIG{'__DIE__'} = $self->component_error_handler
+ if $self->component_error_handler;
# Cheap way to prevent users from executing the same request twice.
#
@@ -1674,16 +1673,18 @@
displayed in the browser. The default for standalone mode is
I<fatal>.
-=item errors_are_exceptions
+=item component_error_handler
-Indicates whether or not to turn non-exception object errors in
-components into exceptions by use of a C<$SIG{__DIE__}>
-handler. Turning exceptions into objects can be expensive, since this
-will cause the generation of a stack trace for each error. If you are
-using strings or unblessed references as exceptions in your code, you
-may want to turn this off as a performance boost.
+A code reference used to handle errors thrown during component
+compilation or runtime. By default, this is a subroutine that turns
+non-exception object errors in components into exceptions. If this
+parameter is set to a false value, these errors are simply rethrown
+as-is.
-The default value for this option is true.
+Turning exceptions into objects can be expensive, since this will
+cause the generation of a stack trace for each error. If you are using
+strings or unblessed references as exceptions in your code, you may
+want to turn this off as a performance boost.
=item max_recurse
Modified: trunk/lib/HTML/Mason.pm
===================================================================
--- trunk/lib/HTML/Mason.pm 2007-05-09 20:18:05 UTC (rev 3829)
+++ trunk/lib/HTML/Mason.pm 2007-05-12 15:51:49 UTC (rev 3830)
@@ -5,7 +5,7 @@
use 5.006;
-$HTML::Mason::VERSION = '1.35';
+$HTML::Mason::VERSION = '1.36';
use HTML::Mason::Interp;
Modified: trunk/t/13-errors.t
===================================================================
--- trunk/t/13-errors.t 2007-05-09 20:18:05 UTC (rev 3829)
+++ trunk/t/13-errors.t 2007-05-12 15:51:49 UTC (rev 3830)
@@ -349,9 +349,9 @@
#------------------------------------------------------------
- $group->add_test( name => 'errors_are_exceptions_false',
- description => 'Test error-handling with errors_are_exceptions \
set to false',
- interp_params => { errors_are_exceptions => 0 },
+ $group->add_test( name => 'component_error_handler_false',
+ description => 'Test error-handling with \
component_error_handler set to false', + interp_params => { \
component_error_handler => 0 }, component => <<'EOF',
% die 'a string error';
EOF
@@ -360,9 +360,9 @@
#------------------------------------------------------------
- $group->add_test( name => 'errors_are_exceptions_no_upgrade',
- description => 'Test that errors do not become object with \
errors_are_exceptions set to false',
- interp_params => { errors_are_exceptions => 0 },
+ $group->add_test( name => 'component_error_Handler_no_upgrade',
+ description => 'Test that errors do not become object with \
component_error_handler set to false', + interp_params => { \
component_error_handler => 0 }, component => <<'EOF',
% eval { die 'a string error' };
exception: <% ref $@ ? ref $@ : 'not a ref' %>
@@ -374,9 +374,9 @@
#------------------------------------------------------------
- $group->add_test( name => 'errors_are_exceptions_false_fatal_mode',
- description => 'Test error-handling with errors_are_exceptions \
set to false and error_mode set to fatal',
- interp_params => { errors_are_exceptions => 0,
+ $group->add_test( name => 'component_error_handler_false_fatal_mode',
+ description => 'Test error-handling with \
component_error_handler set to false and error_mode set to fatal', + \
interp_params => { component_error_handler => 0, error_mode => 'fatal',
},
component => <<'EOF',
@@ -387,6 +387,17 @@
#------------------------------------------------------------
+ $group->add_test( name => 'component_error_handler_uc_message',
+ description => 'Test error-handling with \
component_error_handler set to a subroutine that upper-cases all text', + \
interp_params => { component_error_handler => sub { die map { uc } @_ } }, + \
component => <<'EOF', +% die 'a string error';
+EOF
+ expect_error => qr/A STRING ERROR/,
+ );
+
+#------------------------------------------------------------
+
return $group;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Mason-checkins mailing list
Mason-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-checkins
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic