From: Robert 'phaylon' Sedlacek Date: Thu, 20 Aug 2009 22:43:11 +0000 (+0200) Subject: fixed non-moosey action classes and documented isa option X-Git-Tag: 0.009~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalystX-Declare.git;a=commitdiff_plain;h=2bb54af3cebcf6ca3b2a4df31e7b8bd623a5e698 fixed non-moosey action classes and documented isa option --- diff --git a/Changes b/Changes index e2a73d0..77a7b61 100644 --- 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 diff --git a/lib/CatalystX/Declare/Controller/DetermineActionClass.pm b/lib/CatalystX/Declare/Controller/DetermineActionClass.pm index 189a9ee..c608271 100644 --- a/lib/CatalystX/Declare/Controller/DetermineActionClass.pm +++ b/lib/CatalystX/Declare/Controller/DetermineActionClass.pm @@ -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]; diff --git a/lib/CatalystX/Declare/Keyword/Action.pm b/lib/CatalystX/Declare/Keyword/Action.pm index 0e883c3..2b52c9d 100644 --- a/lib/CatalystX/Declare/Keyword/Action.pm +++ b/lib/CatalystX/Declare/Keyword/Action.pm @@ -606,6 +606,25 @@ consume the C role declared above: } } +=head2 Action Classes + +B + +You might want to create an action with a different class than the usual +L. A usual suspect here is L. +You can use the C 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 Lified, 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 index 0000000..cbc26f0 --- /dev/null +++ b/t/510_render_view.t @@ -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 index 0000000..9d4ece5 --- /dev/null +++ b/t/lib/RenderViewTestApp.pm @@ -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 index 0000000..6cf8b87 --- /dev/null +++ b/t/lib/RenderViewTestApp/Controller/Root.pm @@ -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 index 0000000..e6eae99 --- /dev/null +++ b/t/lib/RenderViewTestApp/View/Test.pm @@ -0,0 +1,8 @@ +use CatalystX::Declare; + +view RenderViewTestApp::View::Test { + + method process (Catalyst $ctx) { + $ctx->response->body( $CLASS ); + } +}