Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved router and renderer to allow camel case controllers
  • Loading branch information
kraih committed Oct 10, 2012
1 parent d429e82 commit 1358146
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Changes
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions t/mojolicious/app.t
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion t/mojolicious/lib/MojoliciousTest.pm
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/lib/MojoliciousTest/Foo/Bar.pm
Expand Up @@ -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;
1 change: 1 addition & 0 deletions t/mojolicious/templates/foo/bar/test.html.ep
@@ -0,0 +1 @@
Class <%= $message %>!

0 comments on commit 1358146

Please sign in to comment.