parameterized roles now available
Robert 'phaylon' Sedlacek [Thu, 17 Sep 2009 21:38:04 +0000 (23:38 +0200)]
Changes
Makefile.PL
lib/CatalystX/Declare/Keyword/Role.pm
t/022_parameterized_roles.t
t/lib/TestApp/Controller/Parameterized.pm
t/lib/TestApp/ControllerRole/Parameterized.pm

diff --git a/Changes b/Changes
index 2ce7d55..e209a38 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 [0.011] ...
-    - Fixed broken isa RenderView test case
+    - fixed broken isa RenderView test case
+    - parameterized roles now available in general
 
 [0.010] Sun Sep 13 15:52:01 CEST 2009
     - Fix Compat with MooseX::Method::Signatures >=0.22 ( KENTNL )
index 129c3f5..621eb6c 100644 (file)
@@ -28,7 +28,8 @@ requires        'Devel::Declare',                   '0.005011';
 requires        'Moose',                            '0.89';
 requires        'MooseX::AttributeHelpers',         '0.21';
 requires        'MooseX::Declare',                  '0.30';
-requires        'MooseX::MethodAttributes',         '0.15';
+requires        'MooseX::MethodAttributes',         '0.16';
+requires        'MooseX::Parameterized',            '0.13';
 requires        'MooseX::Types',                    '0.20';
 requires        'MooseX::Method::Signatures',       '0.26';
 requires        'FindBin';
index 6220562..cd31eac 100644 (file)
@@ -67,6 +67,13 @@ CatalystX::Declare::Keyword::Role - Declare Catalyst Controller Roles
         around bar_action (Object $ctx) { ... }
     }
 
+    controller_role MyApp::Web::ControllerRole::WithParam (Str :$msg!) {
+
+        final action message under base {
+            $ctx->stash(message => $msg);
+        }
+    }
+
 =head1 DESCRIPTION
 
 This handler provides the C<controller_role> keyword. It is an extension of the
@@ -76,6 +83,17 @@ on the syntax for action declarations have a look at
 L<CatalystX::Declare::Keyword::Action>, which also documents the effects of
 method modifiers on actions.
 
+=head2 Parameters
+
+You can use a parameter signature containing named parameters for a role. To
+apply the controller role in the L</SYNOPSIS>, you'd use code like this:
+
+    controller MyApp::Web::Controller::Hello {
+        with 'MyApp::Web::ControllerRole::WithParam' => { msg => 'Hello!' };
+
+        action base under '/' as '';
+    }
+
 =head1 SUPERCLASSES
 
 =over
index 11a125b..5ddab0a 100644 (file)
@@ -8,9 +8,6 @@ use lib "$FindBin::Bin/lib";
 use Test::More; 
 use Catalyst::Test 'TestApp';
 
-TODO: {
-    local $TODO = 'MooseX::MethodAttributes needs to allow this';
-    is get('/param/greet'), 'foo:foo', 'parameterized role was consumed correctly';
-}
+is get('/param/greet'), 'foo:foo', 'parameterized role was consumed correctly';
 
 done_testing;
index e8f7901..9a52956 100644 (file)
@@ -1,6 +1,6 @@
 use CatalystX::Declare;
 
-controller TestApp::Controller::Parameterized is mutable {
+controller TestApp::Controller::Parameterized {
     with 'TestApp::ControllerRole::Parameterized' => { message => 'foo' };
 
     action base under '/' as 'param';
index 9e047db..6248da2 100644 (file)
@@ -5,7 +5,6 @@ controller_role TestApp::ControllerRole::Parameterized (Str :$message) {
     method get_message { $message }
 
     final action greet under base {
-        no warnings 'uninitialized'; # remove if TODO is fixed
         $ctx->response->body( join ':', $self->get_message, $message );
     }
 }