[Catalyst-commits] r11879 - in Catalyst-Runtime/5.80/trunk: . lib/Catalyst lib/Catalyst/Exception t

rafl at dev.catalyst.perl.org rafl at dev.catalyst.perl.org
Tue Nov 17 23:00:32 GMT 2009


Author: rafl
Date: 2009-11-17 23:00:32 +0000 (Tue, 17 Nov 2009)
New Revision: 11879

Added:
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Basic.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Interface.pm
Modified:
   Catalyst-Runtime/5.80/trunk/Makefile.PL
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Detach.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Go.pm
   Catalyst-Runtime/5.80/trunk/t/custom_exception_class_simple.t
Log:
Merge branch 'exception_interface'

* exception_interface:
  Use MooseX::Role::WithOverloading.
  Add Exception::Interface and Exception::Basic. Make ::Base, ::Go and ::Detach use them.
  Create branch exception_interface

Modified: Catalyst-Runtime/5.80/trunk/Makefile.PL
===================================================================
--- Catalyst-Runtime/5.80/trunk/Makefile.PL	2009-11-17 22:38:55 UTC (rev 11878)
+++ Catalyst-Runtime/5.80/trunk/Makefile.PL	2009-11-17 23:00:32 UTC (rev 11879)
@@ -23,6 +23,7 @@
 requires 'Class::MOP' => '0.83';
 requires 'Moose' => '0.90';
 requires 'MooseX::MethodAttributes::Inheritable' => '0.17';
+requires 'MooseX::Role::WithOverloading';
 requires 'Carp';
 requires 'Class::C3::Adopt::NEXT' => '0.07';
 requires 'CGI::Simple::Cookie';

Added: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Basic.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Basic.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Basic.pm	2009-11-17 23:00:32 UTC (rev 11879)
@@ -0,0 +1,45 @@
+package Catalyst::Exception::Basic;
+
+use MooseX::Role::WithOverloading;
+use Carp;
+use namespace::clean -except => 'meta';
+
+with 'Catalyst::Exception::Interface';
+
+has message => (
+    is      => 'ro',
+    isa     => 'Str',
+    default => sub { $! || '' },
+);
+
+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/trunk/lib/Catalyst/Exception/Detach.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Detach.pm	2009-11-17 22:38:55 UTC (rev 11878)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Detach.pm	2009-11-17 23:00:32 UTC (rev 11879)
@@ -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/trunk/lib/Catalyst/Exception/Go.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Go.pm	2009-11-17 22:38:55 UTC (rev 11878)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Go.pm	2009-11-17 23:00:32 UTC (rev 11879)
@@ -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/trunk/lib/Catalyst/Exception/Interface.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Interface.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception/Interface.pm	2009-11-17 23:00:32 UTC (rev 11879)
@@ -0,0 +1,12 @@
+package Catalyst::Exception::Interface;
+
+use MooseX::Role::WithOverloading;
+use namespace::clean -except => 'meta';
+
+use overload
+    q{""}    => sub { $_[0]->as_string },
+    fallback => 1;
+
+requires qw/as_string throw rethrow/;
+
+1;

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception.pm	2009-11-17 22:38:55 UTC (rev 11878)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Exception.pm	2009-11-17 23:00:32 UTC (rev 11879)
@@ -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;

Modified: Catalyst-Runtime/5.80/trunk/t/custom_exception_class_simple.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/custom_exception_class_simple.t	2009-11-17 22:38:55 UTC (rev 11878)
+++ Catalyst-Runtime/5.80/trunk/t/custom_exception_class_simple.t	2009-11-17 23:00:32 UTC (rev 11879)
@@ -7,12 +7,6 @@
 use Test::More tests => 1;
 use Test::Exception;
 
-TODO: {
-    local $TODO = 'Does not work yet';
-
 lives_ok {
     require TestAppClassExceptionSimpleTest;
 } 'Can load application';
-
-}
-




More information about the Catalyst-commits mailing list