[Catalyst-commits] r10927 - in Catalyst-Runtime/5.80/branches/pass_component_names: . t/aggregate t/lib/TestApp/Action t/lib/TestApp/Controller

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Sat Jul 18 11:10:35 GMT 2009


Author: t0m
Date: 2009-07-18 11:10:35 +0000 (Sat, 18 Jul 2009)
New Revision: 10927

Added:
   Catalyst-Runtime/5.80/branches/pass_component_names/t/aggregate/live_component_controller_anon.t
   Catalyst-Runtime/5.80/branches/pass_component_names/t/lib/TestApp/Controller/Anon.pm
Modified:
   Catalyst-Runtime/5.80/branches/pass_component_names/Makefile.PL
   Catalyst-Runtime/5.80/branches/pass_component_names/t/lib/TestApp/Action/TestMyAction.pm
Log:
Add tests that _component_name works as expected, and that anon classes in controllers applying roles which wrap action with custom action classes works, that action classes know the right component name

Modified: Catalyst-Runtime/5.80/branches/pass_component_names/Makefile.PL
===================================================================
--- Catalyst-Runtime/5.80/branches/pass_component_names/Makefile.PL	2009-07-18 10:12:51 UTC (rev 10926)
+++ Catalyst-Runtime/5.80/branches/pass_component_names/Makefile.PL	2009-07-18 11:10:35 UTC (rev 10927)
@@ -11,7 +11,7 @@
 requires 'MooseX::Emulate::Class::Accessor::Fast' => '0.00801';
 requires 'Class::MOP' => '0.83';
 requires 'Moose' => '0.78';
-requires 'MooseX::MethodAttributes::Inheritable' => '0.12';
+requires 'MooseX::MethodAttributes::Inheritable' => '0.14';
 requires 'Carp';
 requires 'Class::C3::Adopt::NEXT' => '0.07';
 requires 'CGI::Simple::Cookie';

Added: Catalyst-Runtime/5.80/branches/pass_component_names/t/aggregate/live_component_controller_anon.t
===================================================================
--- Catalyst-Runtime/5.80/branches/pass_component_names/t/aggregate/live_component_controller_anon.t	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/pass_component_names/t/aggregate/live_component_controller_anon.t	2009-07-18 11:10:35 UTC (rev 10927)
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+use Test::More tests => 6;
+use Catalyst::Test 'TestApp';
+
+{
+    my $response = request('http://localhost/anon/test');
+    ok($response->is_success);
+    is($response->header('X-Component-Name-Action'),
+        'TestApp::Controller::Anon', 'Action can see correct _component_name');
+    isnt($response->header('X-Component-Instance-Name-Action'),
+        'TestApp::Controller::Anon', 'ref($controller) ne _component_name');
+    is($response->header('X-Component-Name-Controller'),
+        'TestApp::Controller::Anon', 'Controller can see correct _component_name');
+    is($response->header('X-Class-In-Action'),
+        'TestApp::Controller::Anon', '$action->class is _component_name');
+    is($response->header('X-Anon-Trait-Applied'),
+        '1', 'Anon controller class has trait applied correctly');
+}
+

Modified: Catalyst-Runtime/5.80/branches/pass_component_names/t/lib/TestApp/Action/TestMyAction.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/pass_component_names/t/lib/TestApp/Action/TestMyAction.pm	2009-07-18 10:12:51 UTC (rev 10926)
+++ Catalyst-Runtime/5.80/branches/pass_component_names/t/lib/TestApp/Action/TestMyAction.pm	2009-07-18 11:10:35 UTC (rev 10927)
@@ -9,6 +9,9 @@
     my $self = shift;
     my ( $controller, $c, $test ) = @_;
     $c->res->header( 'X-TestAppActionTestMyAction', 'MyAction works' );
+    $c->res->header( 'X-Component-Name-Action', $controller->_component_name);
+    $c->res->header( 'X-Component-Instance-Name-Action', ref($controller));
+    $c->res->header( 'X-Class-In-Action', $self->class);
     $self->next::method(@_);
 }
 

Added: Catalyst-Runtime/5.80/branches/pass_component_names/t/lib/TestApp/Controller/Anon.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/pass_component_names/t/lib/TestApp/Controller/Anon.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/pass_component_names/t/lib/TestApp/Controller/Anon.pm	2009-07-18 11:10:35 UTC (rev 10927)
@@ -0,0 +1,40 @@
+package Anon::Trait;
+use Moose::Role -traits => 'MethodAttributes'; # Needed for role composition to work correctly with anon classes.
+
+after test => sub {
+    my ($self, $c) = @_;
+    $c->res->header('X-Anon-Trait-Applied', 1);
+};
+
+no Moose::Role;
+
+package TestApp::Controller::Anon;
+use Moose;
+use Moose::Util qw/find_meta/;
+use namespace::clean -except => 'meta';
+BEGIN { extends 'Catalyst::Controller' };
+
+sub COMPONENT { # Don't do this yourself, use CatalystX::Component::Traits!
+    my ($class, $app, $args) = @_;
+
+    my $meta = $class->meta->create_anon_class(
+            superclasses => [ $class->meta->name ],
+            roles        => ['Anon::Trait'],
+            cache        => 1,
+    );
+    # Special move as the methodattributes trait has changed our metaclass..
+    $meta = find_meta($meta->name);
+
+    $meta->add_method('meta' => sub { $meta });
+    $class = $meta->name;
+    $class->new($app, $args);
+}
+
+sub test : Local ActionClass('+TestApp::Action::TestMyAction') {
+    my ($self, $c) = @_;
+    $c->res->header('X-Component-Name-Controller', $self->_component_name);
+    $c->res->body('It works');
+}
+
+__PACKAGE__->meta->make_immutable;
+




More information about the Catalyst-commits mailing list