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 86 87 88 89 90 91 92 93 94
|
# Copyright (C) 2008-2010, Sebastian Riedel.
package MojoliciousTest;
use strict;
use warnings;
use base 'Mojolicious';
sub development_mode {
my $self = shift;
# Static root for development
$self->static->root($self->home->rel_dir('public_dev'));
}
# Let's face it, comedy's a dead art form. Tragedy, now that's funny.
sub startup {
my $self = shift;
# Only log errors to STDERR
$self->log->level('fatal');
# Templateless renderer
$self->renderer->add_handler(
test => sub {
my ($self, $c, $output) = @_;
$$output = 'Hello Mojo from a templateless renderer!';
}
);
# Renderer for a different file extension
$self->renderer->add_handler(xpl => $self->renderer->handler->{epl});
# Default handler
$self->renderer->default_handler('epl');
# Session domain
$self->session->cookie_domain('.example.com');
# Routes
my $r = $self->routes;
# /stash_config
$r->route('/stash_config')
->to(controller => 'foo', action => 'config', config => {test => 123});
# /test4 - named route for url_for
$r->route('/test4/:something')->to('foo#something', something => 23)
->name('something');
# /somethingtest - refer to another route with url_for
$r->route('/somethingtest')->to('foo#something');
# /something_missing - refer to a non existing route with url_for
$r->route('/something_missing')->to('foo#url_for_missing');
# /test3 - no class, just a namespace
$r->route('/test3')
->to(namespace => 'MojoliciousTestController', method => 'index');
# /test2 - different namespace test
$r->route('/test2')->to(
namespace => 'MojoliciousTest2',
class => 'Foo',
method => 'test'
);
# /withblock - template with blocks
$r->route('/withblock')->to('foo#withblock');
# /staged - authentication with bridges
my $b =
$r->bridge('/staged')->to(controller => 'foo', action => 'stage1');
$b->route->to(action => 'stage2');
# /shortcut/act
# /shortcut/ctrl
# /shortcut/ctrl-act - shortcuts to controller#action
$r->route('/shortcut/ctrl-act')
->to('foo#config', config => {test => 'ctrl-act'});
$r->route('/shortcut/ctrl')
->to('foo#', action => 'config', config => {test => 'ctrl'});
$r->route('/shortcut/act')
->to('#config', controller => 'foo', config => {test => 'act'});
# /foo/session - session cookie with domain
$r->route('/foo/session')->to('foo#session_domain');
# /*/* - the default route
$r->route('/(controller)/(action)')->to(action => 'index');
}
1;
|