fixed non-moosey action classes and documented isa option
Robert 'phaylon' Sedlacek [Thu, 20 Aug 2009 22:43:11 +0000 (00:43 +0200)]
Changes
lib/CatalystX/Declare/Controller/DetermineActionClass.pm
lib/CatalystX/Declare/Keyword/Action.pm
t/510_render_view.t [new file with mode: 0644]
t/lib/RenderViewTestApp.pm [new file with mode: 0644]
t/lib/RenderViewTestApp/Controller/Root.pm [new file with mode: 0644]
t/lib/RenderViewTestApp/View/Test.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
index e2a73d0..77a7b61 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,4 +1,7 @@
 [0.009] ...
+    - action classes are now moosified after loading, this means that
+      RenderView should now work with isa. (thanks to all reporters!)
+    - documented 'isa' action class option (experimental!)
 
 [0.008] Tue Aug 18 19:59:57 CEST 2009
     - default_inner now ignores arguments
index 189a9ee..c608271 100644 (file)
@@ -1,5 +1,6 @@
 use MooseX::Declare;
 use Class::MOP;
+use Moose::Meta::Class;
 
 role CatalystX::Declare::Controller::DetermineActionClass
     with CatalystX::Declare::Controller::QualifyClassNames {
@@ -11,6 +12,7 @@ role CatalystX::Declare::Controller::DetermineActionClass
 
         my $fq_class = $self->_qualify_class_name('Action', $action_class);
         Class::MOP::load_class($fq_class);
+        Moose::Meta::Class->initialize($fq_class);
 
         $args{attributes}{ActionClass} ||= [$fq_class];
 
index 0e883c3..2b52c9d 100644 (file)
@@ -606,6 +606,25 @@ consume the C<RichBase> role declared above:
         }
     }
 
+=head2 Action Classes
+
+B<This option is even more experimental>
+
+You might want to create an action with a different class than the usual
+L<Catalyst::Action>. A usual suspect here is L<Catalyst::Action::RenderView>.
+You can use the C<isa> option (did I mention it's experimental?) to specify
+what class to use:
+
+    controller MyApp::Web::Controller::Root {
+
+        $CLASS->config(namespace => '');
+
+        action end isa RenderView;
+    }
+
+The loaded class will be L<Moose>ified, so we are able to apply essential
+roles.
+
 =head1 ROLES
 
 =over
diff --git a/t/510_render_view.t b/t/510_render_view.t
new file mode 100644 (file)
index 0000000..cbc26f0
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More; 
+
+eval { require Catalyst::Action::RenderView };
+plan skip_all => 'Catalyst::Action::RenderView required' 
+    if $@;
+
+use Catalyst::Test 'RenderViewTestApp';
+
+is get('/foo'), 'RenderViewTestApp::View::Test', 'view was reached via RenderView';
+
+done_testing;
diff --git a/t/lib/RenderViewTestApp.pm b/t/lib/RenderViewTestApp.pm
new file mode 100644 (file)
index 0000000..9d4ece5
--- /dev/null
@@ -0,0 +1,8 @@
+use CatalystX::Declare;
+
+application RenderViewTestApp with CatalystX::Declare::TestPlugin {
+
+    $CLASS->config(name => 'RenderView TestApp');
+}
+
+
diff --git a/t/lib/RenderViewTestApp/Controller/Root.pm b/t/lib/RenderViewTestApp/Controller/Root.pm
new file mode 100644 (file)
index 0000000..6cf8b87
--- /dev/null
@@ -0,0 +1,15 @@
+use CatalystX::Declare;
+
+controller RenderViewTestApp::Controller::Root {
+
+    $CLASS->config(namespace => '');
+
+
+    action base as '' under '/';
+
+    final action foo under base {
+        $ctx->stash(current_view => 'Test');
+    }
+
+    action end isa RenderView;
+}
diff --git a/t/lib/RenderViewTestApp/View/Test.pm b/t/lib/RenderViewTestApp/View/Test.pm
new file mode 100644 (file)
index 0000000..e6eae99
--- /dev/null
@@ -0,0 +1,8 @@
+use CatalystX::Declare;
+
+view RenderViewTestApp::View::Test {
+
+    method process (Catalyst $ctx) {
+        $ctx->response->body( $CLASS );
+    }
+}