X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FException.pm;h=c8d55479618b1083df0839789465f58bad03ce7f;hb=67e9673e2729bf40b87a20b2afa350be19cd7f5e;hp=4959e4209e047c3127ade536d31cd0b3e9d9f9bb;hpb=0af1b40c4ce16ae21702b9989357d76ebcec2153;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Exception.pm b/lib/Catalyst/Exception.pm index 4959e42..c8d5547 100644 --- a/lib/Catalyst/Exception.pm +++ b/lib/Catalyst/Exception.pm @@ -35,26 +35,43 @@ Throws a fatal exception. =cut has message => ( - is => 'ro', - isa => 'Str', + is => 'ro', + isa => 'Str', + default => sub { $! || '' }, ); -use overload q{""} => \&as_string; +use overload + q{""} => \&as_string, + fallback => 1; sub as_string { my ($self) = @_; 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]); + } + + my $args = $class->$next(@args); + $args->{message} ||= $args->{error} + if exists $args->{error}; - my $message = $params{message} || $params{error} || $! || ''; + return $args; +}; +sub throw { + my $class = shift; + my $error = $class->new(@_); local $Carp::CarpLevel = 1; + croak $error; +} - croak($message); +sub rethrow { + my ($self) = @_; + croak $self; } =head2 meta