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

mo at dev.catalyst.perl.org mo at dev.catalyst.perl.org
Sun Jun 7 12:28:53 GMT 2009


Author: mo
Date: 2009-06-07 12:28:53 +0000 (Sun, 07 Jun 2009)
New Revision: 10468

Modified:
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/Changes
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/TODO
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst.pm
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Controller.pm
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Dispatcher.pm
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Utils.pm
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/t/aggregate/live_component_controller_action_action.t
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/t/lib/TestApp/Controller/Action/Action.pm
Log:
Added support for ~ prefix to plugins and action classes

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/Changes
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/Changes	2009-06-07 11:49:58 UTC (rev 10467)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/Changes	2009-06-07 12:28:53 UTC (rev 10468)
@@ -1,5 +1,8 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Use ~ as prefix for plugins or action classes which are located in MyApp::Plugin / MyApp::Action 
+
+
 5.80005 2009-06-06 14:40:00
 
   Behaviour changes:

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/TODO
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/TODO	2009-06-07 11:49:58 UTC (rev 10467)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/TODO	2009-06-07 12:28:53 UTC (rev 10468)
@@ -1,6 +1,6 @@
 TODO for brach namespace_handling_refactor:
 
-- refactor code in 
+- refactor code in
   * Catalyst::Dispatcher::get_containers           # No Idea
   * Catalyst::Dispatcher::dispatch_type            # DONE
 

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Controller.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Controller.pm	2009-06-07 11:49:58 UTC (rev 10467)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Controller.pm	2009-06-07 12:28:53 UTC (rev 10468)
@@ -390,7 +390,8 @@
 
 sub _parse_ActionClass_attr {
     my ( $self, $c, $name, $value ) = @_;
-    $value = Catalyst::Utils::resolve_namespace($self->_action_class, $value);
+    my $appname = $self->_application;
+    $value = Catalyst::Utils::resolve_namespace($appname . '::Action', $self->_action_class, $value);
     return ( 'ActionClass', $value );
 }
 

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Dispatcher.pm	2009-06-07 11:49:58 UTC (rev 10467)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Dispatcher.pm	2009-06-07 12:28:53 UTC (rev 10468)
@@ -640,10 +640,10 @@
     my ( $self, @types ) = @_;
 
     my @loaded;
-
     # Preload action types
     for my $type (@types) {
-        my $class = Catalyst::Utils::resolve_namespace('Catalyst::DispatchType', $type);
+        # first param is undef because we cannot get the appclass
+        my $class = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $type);
         
         eval { Class::MOP::load_class($class) };
         Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ )
@@ -666,9 +666,10 @@
 
 sub dispatch_type {
     my ($self, $name) = @_;
+    
+    # first param is undef because we cannot get the appclass
+    $name = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $name);
 
-    $name = Catalyst::Utils::resolve_namespace('Catalyst::DispatchType', $name);
-
     for (@{ $self->_dispatch_types }) {
         return $_ if ref($_) eq $name;
     }

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Utils.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Utils.pm	2009-06-07 11:49:58 UTC (rev 10467)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Utils.pm	2009-06-07 12:28:53 UTC (rev 10468)
@@ -392,10 +392,11 @@
 
 
 sub resolve_namespace {
+    my $appnamespace = shift;
     my $namespace = shift;
     my @classes = @_;
     return String::RewritePrefix->rewrite(
-        { '' => $namespace.'::', '+' => '' }, @classes,
+        { '' => $namespace.'::', '+' => '', '~' => $appnamespace . '::' }, @classes,
       );
 }
 

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst.pm	2009-06-07 11:49:58 UTC (rev 10467)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst.pm	2009-06-07 12:28:53 UTC (rev 10468)
@@ -2502,9 +2502,9 @@
 
         $class->_plugins( {} ) unless $class->_plugins;
         $plugins ||= [];
+                
+        my @plugins = Catalyst::Utils::resolve_namespace($class . '::Plugin', 'Catalyst::Plugin', @$plugins);
         
-        my @plugins = Catalyst::Utils::resolve_namespace('Catalyst::Plugin', @$plugins);
-        
         for my $plugin ( reverse @plugins ) {
             Class::MOP::load_class($plugin);
             my $meta = find_meta($plugin);

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/t/aggregate/live_component_controller_action_action.t
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/t/aggregate/live_component_controller_action_action.t	2009-06-07 11:49:58 UTC (rev 10467)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/t/aggregate/live_component_controller_action_action.t	2009-06-07 12:28:53 UTC (rev 10468)
@@ -10,7 +10,7 @@
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
-use Test::More tests => 28 * $iters;
+use Test::More tests => 42 * $iters;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -106,5 +106,46 @@
             'Content is a serialized Catalyst::Request'
         );
     }
+    
+    {
+        ok( my $response = request('http://localhost/action_action_five'),
+            'Request' );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is( $response->header('X-Catalyst-Action'),
+            'action_action_five', 'Test Action' );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::Action',
+            'Test Class'
+        );
+        is( $response->header('X-Action'), 'works' );
+        like(
+            $response->content,
+            qr/^bless\( .* 'Catalyst::Request' \)$/s,
+            'Content is a serialized Catalyst::Request'
+        );
+    }
+    
 
+    {
+        ok( my $response = request('http://localhost/action_action_six'),
+            'Request' );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is( $response->header('X-Catalyst-Action'),
+            'action_action_six', 'Test Action' );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::Action',
+            'Test Class'
+        );
+        is( $response->header('X-TestAppActionTestMyAction'), 'MyAction works' );
+        like(
+            $response->content,
+            qr/^bless\( .* 'Catalyst::Request' \)$/s,
+            'Content is a serialized Catalyst::Request'
+        );
+    }
+
 }

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/t/lib/TestApp/Controller/Action/Action.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/t/lib/TestApp/Controller/Action/Action.pm	2009-06-07 11:49:58 UTC (rev 10467)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/t/lib/TestApp/Controller/Action/Action.pm	2009-06-07 12:28:53 UTC (rev 10468)
@@ -3,6 +3,8 @@
 use strict;
 use base 'TestApp::Controller::Action';
 
+__PACKAGE__->config( actions => { action_action_five => { ActionClass => '+Catalyst::Action::TestBefore' } } );
+
 sub action_action_one : Global : ActionClass('TestBefore') {
     my ( $self, $c ) = @_;
     $c->res->header( 'X-Action', $c->stash->{test} );
@@ -25,4 +27,15 @@
     $c->forward('TestApp::View::Dump::Request');
 }
 
+sub action_action_five : Global {
+    my ( $self, $c ) = @_;
+    $c->res->header( 'X-Action', $c->stash->{test} );
+    $c->forward('TestApp::View::Dump::Request');
+}
+
+sub action_action_six : Global : ActionClass('~TestMyAction') {
+    my ( $self, $c ) = @_;
+    $c->forward('TestApp::View::Dump::Request');
+}
+
 1;




More information about the Catalyst-commits mailing list