Skip to content

Instantly share code, notes, and snippets.

@ovntatar
Forked from kraih/Bar.pm
Created January 22, 2014 20:51
Show Gist options
  • Save ovntatar/8567142 to your computer and use it in GitHub Desktop.
Save ovntatar/8567142 to your computer and use it in GitHub Desktop.
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.
package MyApp::Controller::Foo;
use Mojolicious::Lite;
get '/' => {text => 'Welcome to Mojolyst!'};
1;
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;
#!/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