From: Brandon L. Black Date: Mon, 11 Jun 2007 17:22:08 +0000 (+0000) Subject: add stacktrace option to modify the default behavior of throw_exception X-Git-Tag: v0.08010~150^2~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=613397e734cc6992618e73c5373c3883071fcde5;p=dbsrgits%2FDBIx-Class.git add stacktrace option to modify the default behavior of throw_exception --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index b1fa17f..0395bd7 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -15,6 +15,7 @@ __PACKAGE__->mk_classdata('source_registrations' => {}); __PACKAGE__->mk_classdata('storage_type' => '::DBI'); __PACKAGE__->mk_classdata('storage'); __PACKAGE__->mk_classdata('exception_action'); +__PACKAGE__->mk_classdata('stacktrace' => 0); =head1 NAME @@ -863,7 +864,7 @@ sub populate { 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. +rather than its normal C or C action. Your subroutine should probably just wrap the error in the exception object/class of your choosing and rethrow. If, against all sage advice, @@ -885,6 +886,18 @@ Example: # suppress all exceptions, like a moron: $schema_obj->exception_action(sub { 1 }); +=head2 stacktrace + +=over4 + +=item Arguments: boolean + +=back + +This alters the behavior of the default L action. It +uses C if C is false, or C if C +is true. The default is false. + =head2 throw_exception =over 4 @@ -895,13 +908,16 @@ Example: Throws an exception. Defaults to using L to report errors from user's perspective. See L for details on overriding -this method's behavior. +this method's behavior. If L is turned on, C +will use C instead of C. =cut sub throw_exception { my $self = shift; - croak @_ if !$self->exception_action || !$self->exception_action->(@_); + if(!$self->exception_action || !$self->exception_action->(@_)) { + $self->stacktrace ? confess @_ : croak @_; + } } =head2 deploy (EXPERIMENTAL)