From: Brandon L. Black Date: Thu, 27 Jul 2006 01:48:37 +0000 (+0000) Subject: allow exception_action to suppress things, clean up docs X-Git-Tag: v0.08010~43^2~39^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=db5dc23362a8bdd86013192d0561399407abf06c;p=dbsrgits%2FDBIx-Class.git allow exception_action to suppress things, clean up docs --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 36f411c..9357566 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -680,9 +680,14 @@ sub populate { =back -If this accessor is set to a subroutine reference, it will be executed -to handle exceptions where possible. Can be set at either the class or -object level. +If C is set for this class/object, L +will prefer to call this code reference with the exception as an argument, +rather than its normal action. + +Your subroutine should probably just wrap the error in the exception +object/class of your choosing and rethrow. If, against all sage advice, +you'd like your C to suppress a particular exception +completely, simply have it return true. Example: @@ -692,10 +697,13 @@ Example: __PACKAGE__->exception_action(sub { My::ExceptionClass->throw(@_) }); __PACKAGE__->load_classes; - # or + # or: my $schema_obj = My::Schema->connect( .... ); $schema_obj->exception_action(sub { My::ExceptionClass->throw(@_) }); + # suppress all exceptions, like a moron: + $schema_obj->exception_action(sub { 1 }); + =head2 throw_exception =over 4 @@ -705,15 +713,14 @@ Example: =back Throws an exception. Defaults to using L to report errors from -user's perspective. If C is set for this schema class or -object, the error will be thrown via that subref instead. +user's perspective. See L for details on overriding +this method's behavior. =cut sub throw_exception { my $self = shift; - $self->exception_action->(@_) if $self->exception_action; - croak @_; + croak @_ if !$self->exception_action || !$self->exception_action->(@_); } =head2 deploy (EXPERIMENTAL)