1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
package SingleFileTestApp;
use Mojo::Base 'Mojolicious';
sub startup {
my $self = shift;
# Only log errors to STDERR
$self->log->level('fatal');
# Plugins
$self->plugin('PluginWithEmbeddedApp');
$self->plugin('MojoliciousTest::Plugin::Test::SomePlugin2');
$self->plugin('Config');
# DATA classes
push @{$self->renderer->classes}, 'SingleFileTestApp::Foo';
push @{$self->static->classes}, 'SingleFileTestApp::Foo';
# Allow redispatching controller
push @{$self->routes->base_classes}, 'Mojo::Base';
# Helper route
$self->routes->route('/helper')->to(
cb => sub {
my $c = shift;
$c->render(text => $c->some_plugin);
}
);
# The default route
$self->routes->route('/:controller/:action')->to(action => 'index');
}
package SingleFileTestApp::Redispatch;
use Mojo::Base -base;
sub handler {
my ($self, $c) = @_;
return secret($c) if $c->param('rly');
return render($c) if $c->stash('action') eq 'render';
$c->render(text => 'Redispatch!');
}
sub render {
my $c = shift;
$c->render(text => 'Render!');
}
sub secret {
my $c = shift;
$c->render(text => 'Secret!');
}
package SingleFileTestApp::Foo;
use Mojo::Base 'Mojolicious::Controller';
sub conf {
my $self = shift;
$self->render(text => $self->config->{single_file});
}
sub data_template { shift->render('index') }
sub data_template2 { shift->stash(template => 'too') }
sub data_static { shift->reply->static('singlefiletestapp/foo.txt') }
sub index {
shift->stash(template => 'WithGreenLayout', msg => 'works great!');
}
sub routes {
my $self = shift;
$self->res->headers->header('X-Bender' => 'Bite my shiny metal ass!');
$self->render(text => $self->url_for);
}
1;
__DATA__
@@ index.html.epl
<%= 20 + 3 %> works!
@@ too.html.epl
This one works too!
@@ singlefiletestapp/foo.txt
And this one... ALL GLORY TO THE HYPNOTOAD!
|