[Catalyst-commits] r10814 - in Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst: . Exception

rafl at dev.catalyst.perl.org rafl at dev.catalyst.perl.org
Tue Jul 7 14:33:40 GMT 2009


Author: rafl
Date: 2009-07-07 14:33:39 +0000 (Tue, 07 Jul 2009)
New Revision: 10814

Added:
   Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Basic.pm
   Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Interface.pm
Modified:
   Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception.pm
   Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Detach.pm
   Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Go.pm
Log:
Add Exception::Interface and Exception::Basic. Make ::Base, ::Go and ::Detach use them.

Failing tests due to issues when composing overloading methods from roles.

Added: Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Basic.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Basic.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Basic.pm	2009-07-07 14:33:39 UTC (rev 10814)
@@ -0,0 +1,49 @@
+package Catalyst::Exception::Basic;
+
+use Moose::Role;
+use Carp;
+use namespace::clean -except => 'meta';
+
+with 'Catalyst::Exception::Interface';
+
+has message => (
+    is      => 'ro',
+    isa     => 'Str',
+    default => sub { $! || '' },
+);
+
+use overload
+    q{""}    => \&as_string,
+    fallback => 1;
+
+sub as_string {
+    my ($self) = @_;
+    return $self->message;
+}
+
+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};
+
+    return $args;
+};
+
+sub throw {
+    my $class = shift;
+    my $error = $class->new(@_);
+    local $Carp::CarpLevel = 1;
+    croak $error;
+}
+
+sub rethrow {
+    my ($self) = @_;
+    croak $self;
+}
+
+1;

Modified: Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Detach.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Detach.pm	2009-07-07 14:31:53 UTC (rev 10813)
+++ Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Detach.pm	2009-07-07 14:33:39 UTC (rev 10814)
@@ -3,7 +3,7 @@
 use Moose;
 use namespace::clean -except => 'meta';
 
-extends 'Catalyst::Exception';
+with 'Catalyst::Exception::Basic';
 
 has '+message' => (
     default => "catalyst_detach\n",

Modified: Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Go.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Go.pm	2009-07-07 14:31:53 UTC (rev 10813)
+++ Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Go.pm	2009-07-07 14:33:39 UTC (rev 10814)
@@ -3,7 +3,7 @@
 use Moose;
 use namespace::clean -except => 'meta';
 
-extends 'Catalyst::Exception';
+with 'Catalyst::Exception::Basic';
 
 has '+message' => (
     default => "catalyst_go\n",

Added: Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Interface.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Interface.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception/Interface.pm	2009-07-07 14:33:39 UTC (rev 10814)
@@ -0,0 +1,8 @@
+package Catalyst::Exception::Interface;
+
+use Moose::Role;
+use namespace::autoclean;
+
+requires qw/as_string throw rethrow/;
+
+1;

Modified: Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception.pm	2009-07-07 14:31:53 UTC (rev 10813)
+++ Catalyst-Runtime/5.80/branches/exception_interface/lib/Catalyst/Exception.pm	2009-07-07 14:33:39 UTC (rev 10814)
@@ -2,12 +2,6 @@
 
 # XXX: See bottom of file for Exception implementation
 
-package Catalyst::Exception::Base;
-
-use Moose;
-use Carp;
-use namespace::clean -except => 'meta';
-
 =head1 NAME
 
 Catalyst::Exception - Catalyst Exception Class
@@ -32,48 +26,6 @@
 
 Throws a fatal exception.
 
-=cut
-
-has message => (
-    is      => 'ro',
-    isa     => 'Str',
-    default => sub { $! || '' },
-);
-
-use overload
-    q{""}    => \&as_string,
-    fallback => 1;
-
-sub as_string {
-    my ($self) = @_;
-    return $self->message;
-}
-
-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};
-
-    return $args;
-};
-
-sub throw {
-    my $class = shift;
-    my $error = $class->new(@_);
-    local $Carp::CarpLevel = 1;
-    croak $error;
-}
-
-sub rethrow {
-    my ($self) = @_;
-    croak $self;
-}
-
 =head2 meta
 
 Provided by Moose
@@ -89,19 +41,30 @@
 
 =cut
 
-Catalyst::Exception::Base->meta->make_immutable;
+{
+    package Catalyst::Exception::Base;
 
-package Catalyst::Exception;
+    use Moose;
+    use namespace::clean -except => 'meta';
 
-use Moose;
-use namespace::clean -except => 'meta';
+    with 'Catalyst::Exception::Basic';
 
-use vars qw[$CATALYST_EXCEPTION_CLASS];
-
-BEGIN {
-    extends($CATALYST_EXCEPTION_CLASS || 'Catalyst::Exception::Base');
+    __PACKAGE__->meta->make_immutable;
 }
 
-__PACKAGE__->meta->make_immutable;
+{
+    package Catalyst::Exception;
 
+    use Moose;
+    use namespace::clean -except => 'meta';
+
+    use vars qw[$CATALYST_EXCEPTION_CLASS];
+
+    BEGIN {
+        extends($CATALYST_EXCEPTION_CLASS || 'Catalyst::Exception::Base');
+    }
+
+    __PACKAGE__->meta->make_immutable;
+}
+
 1;




More information about the Catalyst-commits mailing list