[Catalyst-commits] r10677 - Catalyst-Runtime/5.80/trunk/lib/Catalyst
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Fri Jun 26 15:28:24 GMT 2009
Author: rafl
Date: 2009-06-26 15:28:24 +0000 (Fri, 26 Jun 2009)
New Revision: 10677
Modified:
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception.pm
Log:
Make Exception initialisation saner.
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception.pm 2009-06-26 15:28:14 UTC (rev 10676)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception.pm 2009-06-26 15:28:24 UTC (rev 10677)
@@ -35,8 +35,9 @@
=cut
has message => (
- is => 'ro',
- isa => 'Str',
+ is => 'ro',
+ isa => 'Str',
+ default => sub { $! || '' },
);
use overload
@@ -48,15 +49,23 @@
return $self->message;
}
-sub throw {
- my $class = shift;
- my %params = @_ == 1 ? ( error => $_[0] ) : @_;
+around BUILDARGS => sub {
+ my ($next, $class, @args) = @_;
+ if (@args == 1 && !ref $args[0]) {
+ @args = (message => $args[0]);
+ }
- $params{message} = $params{message} || $params{error} || $! || '';
- my $error = $class->new(%params);
+ my $args = $class->$next(@args);
+ $args->{message} ||= $args->{error}
+ if exists $args->{error};
+ return $args;
+};
+
+sub throw {
+ my $class = shift;
+ my $error = $class->new(@_);
local $Carp::CarpLevel = 1;
-
croak $error;
}
More information about the Catalyst-commits
mailing list