Permalink
Browse files

improved router and renderer to allow camel case controllers

  • Loading branch information...
1 parent d429e82 commit 135814622c3e25d7a899166a1d14cbb138a672db @kraih committed Oct 10, 2012
View
@@ -1,7 +1,6 @@
3.46 2012-10-11
- - Improved to method in Mojolicious::Routes::Route to allow controller
- classes containing "::" in shortcuts.
+ - Improved router and renderer to allow camel case controllers.
3.45 2012-10-10
- Added multi_accept attribute to Mojo::IOLoop.
@@ -166,7 +166,8 @@ sub render {
my $controller = $args->{controller} || $stash->{controller};
my $action = $args->{action} || $stash->{action};
if ($controller && $action) {
- $stash->{template} = join '/', split(/-/, $controller), $action;
+ $stash->{template} = join '/',
+ split(/-/, Mojo::Util::decamelize($controller)), $action;
}
# Try the route name if we don't have controller and action
View
@@ -7,7 +7,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}
-use Test::More tests => 344;
+use Test::More tests => 349;
use FindBin;
use lib "$FindBin::Bin/lib";
@@ -226,11 +226,17 @@ $t->get_ok('/test6' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_is('/test6');
-# MojoliciousTest::Foo::Bar::test (controller class)
+# MojoliciousTest::Foo::Bar::test (controller class shortcut)
$t->get_ok('/test7' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
- ->content_is('Class works!');
+ ->content_is("Class works!\n");
+
+# MojoliciousTest::Foo::Bar::test (controller class)
+$t->get_ok('/test8' => {'X-Test' => 'Hi there!'})->status_is(200)
+ ->header_is(Server => 'Mojolicious (Perl)')
+ ->header_is('X-Powered-By' => 'Mojolicious (Perl)')
+ ->content_is("Class works!\n");
# 404
$t->get_ok('/' => {'X-Test' => 'Hi there!'})->status_is(404)
@@ -118,9 +118,12 @@ sub startup {
action => 'test'
);
- # /test7 (controller class)
+ # /test7 (controller class shortcut)
$r->route('/test7')->to('Foo::Bar#test');
+ # /test8 (controller class)
+ $r->route('/test8')->to(controller => 'Foo::Bar', action => 'test');
+
# /withblock (template with blocks)
$r->route('/withblock')->to('foo#withblock');
@@ -3,6 +3,6 @@ use Mojolicious::Controller -base;
sub index {1}
-sub test { shift->render(text => 'Class works!') }
+sub test { shift->stash(message => 'works') }
1;
@@ -0,0 +1 @@
+Class <%= $message %>!

0 comments on commit 1358146

Please sign in to comment.