-
-
Save anonymous/1d54960537a228f8de8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojolicious.pm b/lib/Mojolicious.pm | |
index c37f185..76768dc 100644 | |
--- a/lib/Mojolicious.pm | |
+++ b/lib/Mojolicious.pm | |
@@ -154,8 +154,8 @@ sub new { | |
push @{$self->renderer->paths}, $home->rel_dir('templates'); | |
push @{$self->static->paths}, $home->rel_dir('public'); | |
- # Default to application namespace | |
- my $r = $self->routes->namespaces([ref $self]); | |
+ # Default to application and controller namespace | |
+ my $r = $self->routes->namespaces([ref $self . '::Controller', ref $self]); | |
# Hide controller attributes/methods and "handler" | |
$r->hide(qw(app continue cookie finish flash handler match on param)); | |
@@ -220,7 +220,7 @@ Mojolicious - Real-time web framework | |
} | |
# Controller | |
- package MyApp::Foo; | |
+ package MyApp::Controller::Foo; | |
use Mojo::Base 'Mojolicious::Controller'; | |
# Action | |
@@ -457,7 +457,7 @@ startup method to define the url endpoints for your applicat | |
$r->post('/baz')->to('test#baz'); | |
# Add another namespace to load controllers from | |
- push @{$app->routes->namespaces}, 'MyApp::Controller'; | |
+ push @{$app->routes->namespaces}, 'MyApp::C'; | |
=head2 secrets | |
diff --git a/lib/Mojolicious/Command/generate/app.pm b/lib/Mojolicious/Command/g | |
index e700bd2..c7abac7 100644 | |
--- a/lib/Mojolicious/Command/generate/app.pm | |
+++ b/lib/Mojolicious/Command/generate/app.pm | |
@@ -26,7 +26,7 @@ EOF | |
$self->render_to_rel_file('appclass', "$name/lib/$app", $class); | |
# Controller | |
- my $controller = "${class}::Example"; | |
+ my $controller = "${class}::Controller::Example"; | |
my $path = class_to_path $controller; | |
$self->render_to_rel_file('controller', "$name/lib/$path", $controller); | |
diff --git a/lib/Mojolicious/Guides/Growing.pod b/lib/Mojolicious/Guides/Growing | |
index b100e6d..e42203c 100644 | |
--- a/lib/Mojolicious/Guides/Growing.pod | |
+++ b/lib/Mojolicious/Guides/Growing.pod | |
@@ -578,14 +578,14 @@ allow running tests again. | |
Hybrid routes are a nice intermediate step, but to maximize maintainability it | |
makes sense to split our action code from its routing information. | |
- $ mkdir lib/MyApp | |
- $ touch lib/MyApp/Login.pm | |
+ $ mkdir -p lib/MyApp/Controller | |
+ $ touch lib/MyApp/Controller/Login.pm | |
$ chmod 644 lib/MyApp/Login.pm | |
Once again the actual action code does not need to change, we just rename | |
C<$c> to C<$self> since the controller is now the invocant. | |
- package MyApp::Login; | |
+ package MyApp::Controller::Login; | |
use Mojo::Base 'Mojolicious::Controller'; | |
sub index { | |
diff --git a/lib/Mojolicious/Guides/Routing.pod b/lib/Mojolicious/Guides/Routing | |
index 57faf4c..6e803fa 100644 | |
--- a/lib/Mojolicious/Guides/Routing.pod | |
+++ b/lib/Mojolicious/Guides/Routing.pod | |
@@ -169,11 +169,11 @@ defined. | |
1; | |
-The minimal route above will load and instantiate the class C<MyApp::Foo> and | |
-call its C<welcome> method. | |
+The minimal route above will load and instantiate the class | |
+C<MyApp::Controller::Foo> and call its C<welcome> method. | |
# Controller | |
- package MyApp::Foo; | |
+ package MyApp::Controller::Foo; | |
use Mojo::Base 'Mojolicious::Controller'; | |
# Action | |
@@ -259,9 +259,9 @@ old ones. | |
When the dispatcher sees C<controller> and C<action> values in the stash it | |
will always try to turn them into a class and method to dispatch to. The | |
C<controller> value gets camelized using L<Mojo::Util/"camelize"> and | |
-prefixed with a C<namespace> (defaulting to the applications class). While the | |
-action value is not changed at all, because of this both values are case | |
-sensitive. | |
+prefixed with a C<namespace> (defaulting to the applications class followed by | |
+C<::Controller>). While the action value is not changed at all, because of | |
+this both values are case sensitive. | |
# Application | |
package MyApp; | |
@@ -277,7 +277,7 @@ sensitive. | |
1; | |
# Controller | |
- package MyApp::Foo; | |
+ package MyApp::Controller::Foo; | |
use Mojo::Base 'Mojolicious::Controller'; | |
# Action | |
@@ -533,7 +533,7 @@ additional information. | |
$r->websocket('/echo')->to(controller => 'foo', action => 'echo'); | |
# Controller | |
- package MyApp::Foo; | |
+ package MyApp::Controller::Foo; | |
use Mojo::Base 'Mojolicious::Controller'; | |
# Action |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment