[Catalyst-commits] r11888 - in Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned: lib lib/Catalyst t/aggregate

zby at dev.catalyst.perl.org zby at dev.catalyst.perl.org
Wed Nov 18 18:05:02 GMT 2009


Author: zby
Date: 2009-11-18 18:05:01 +0000 (Wed, 18 Nov 2009)
New Revision: 11888

Modified:
   Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst.pm
   Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst/Context.pm
   Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/t/aggregate/unit_core_action_for.t
Log:
controller method on application, this one is identical to that one in Context - so it can be proxied there

Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst/Context.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst/Context.pm	2009-11-18 09:55:12 UTC (rev 11887)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst/Context.pm	2009-11-18 18:05:01 UTC (rev 11888)
@@ -35,6 +35,7 @@
     handles   => [
         qw/
         controllers 
+        controller
         models 
         views 
         component 
@@ -345,18 +346,6 @@
 
 =cut
 
-sub controller {
-    my ( $c, $name, @args ) = @_;
-
-    if( $name ) {
-        my @result = $c->_comp_search_prefixes( $name, qw/Controller C/ );
-        return map { $c->_filter_component( $_, @args ) } @result if ref $name;
-        return $c->_filter_component( $result[ 0 ], @args );
-    }
-
-    return $c->component( $c->action->class );
-}
-
 =head2 $c->model($name)
 
 Gets a L<Catalyst::Model> instance by name.

Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst.pm	2009-11-18 09:55:12 UTC (rev 11887)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst.pm	2009-11-18 18:05:01 UTC (rev 11888)
@@ -262,6 +262,35 @@
 
 =cut
 
+=head2 $c->controller($name)
+
+Gets a L<Catalyst::Controller> instance by name.
+
+    $c->controller('Foo')->do_stuff;
+
+If the name is omitted, will return the controller for the dispatched
+action.
+
+If you want to search for controllers, pass in a regexp as the argument.
+
+    # find all controllers that start with Foo
+    my @foo_controllers = $c->controller(qr{^Foo});
+
+
+=cut
+
+sub controller {
+    my ( $c, $name, @args ) = @_;
+
+    if( $name ) {
+        my @result = $c->_comp_search_prefixes( $name, qw/Controller C/ );
+        return map { $c->_filter_component( $_, @args ) } @result if ref $name;
+        return $c->_filter_component( $result[ 0 ], @args );
+    }
+
+    return $c->component( $c->action->class );
+}
+
 sub _comp_search_prefixes {
     my $c = shift;
     return map $c->components->{ $_ }, $c->_comp_names_search_prefixes(@_);

Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/t/aggregate/unit_core_action_for.t
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/t/aggregate/unit_core_action_for.t	2009-11-18 09:55:12 UTC (rev 11887)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/t/aggregate/unit_core_action_for.t	2009-11-18 18:05:01 UTC (rev 11888)
@@ -8,7 +8,7 @@
 
 use Test::More;
 
-plan tests => 4;
+plan tests => 6;
 
 use_ok('TestApp');
 
@@ -21,3 +21,12 @@
    is(TestApp->controller('Args')->action_for('args').'',
       'args/args',
       'action stringifies');
+
+my $controller = Catalyst::Context->new( application => TestApp->new )->controller('Args');
+is($controller->action_for('args')->code,
+    TestApp::Controller::Args->can('args'),
+    'action_for on controller ok');
+is($controller->action_for('args').'',
+    'args/args',
+    'action stringifies');
+




More information about the Catalyst-commits mailing list