Created
March 21, 2012 16:16
-
-
Save kraih/2149176 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
package MyApp::Controller::Bar; | |
use Mojolicious::Lite; | |
get '/test' => sub { | |
my $self = shift; | |
$self->render('test'); | |
}; | |
1; | |
__DATA__ | |
@@ test.html.ep | |
Just some test template. |
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
package MyApp::Controller::Foo; | |
use Mojolicious::Lite; | |
get '/' => {text => 'Welcome to Mojolyst!'}; | |
1; |
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
package Mojolicious::Plugin::Mojolyst; | |
use Mojo::Base 'Mojolicious::Plugin'; | |
use Mojo::Loader; | |
sub register { | |
my ($self, $app, $conf) = @_; | |
# Discover controllers | |
my $loader = Mojo::Loader->new; | |
for my $class (@{$loader->search($conf->{controllers})}) { | |
# Steal children | |
$loader->load($class); | |
$app->routes->add_child($_) for @{$class->new->routes->children}; | |
# Make DATA sections accessible | |
push @{$app->static->classes}, $class; | |
push @{$app->renderer->classes}, $class; | |
} | |
} | |
1; |
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
#!/usr/bin/env perl | |
use lib 'lib'; | |
use Mojolicious::Lite; | |
plugin Mojolyst => {controllers => 'MyApp::Controller'}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ovntatar: The reason why not all routes are being generated as expected is explained in add_child.
Add a child to this route, it will be automatically removed from its current parent if necessary.
Instead do: