Created
June 25, 2011 12:52
-
-
Save kraih/1046452 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
use Mojolicious::Lite; | |
BEGIN { plugin 'Evil' } | |
get '/' => sub { | |
render text => 'Hello World!'; | |
}; | |
app->start; |
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 Evil; | |
use Mojo::Base 'Mojolicious::Plugin'; | |
# Singleton controller | |
our $CONTROLLER; | |
sub register { | |
my ($self, $app) = @_; | |
# Localize singleton controller | |
$app->on_process( | |
sub { | |
my ($self, $c) = @_; | |
local $CONTROLLER = $c; | |
$self->dispatch($c); | |
} | |
); | |
# "render" helper | |
$app->helper(render => sub { shift->render(@_) }); | |
# Export helpers | |
no strict 'refs'; | |
my $caller = caller(3); | |
for my $helper (keys %{$app->renderer->helpers}) { | |
*{"${caller}::$helper"} = sub { $CONTROLLER->$helper(@_) } | |
unless defined *{"${caller}::$helper"}; | |
} | |
} | |
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
use Mojolicious::Lite; | |
BEGIN { plugin 'Evil' } | |
get '/' => sub { | |
layout 'green'; | |
title 'Welcome!'; | |
render 'login', message => 'Hi there!'; | |
}; | |
app->start; | |
__DATA__ | |
@@ layouts/green.html.ep | |
<!DOCTYPE html><html> | |
<head><title><%= title %></title></head> | |
<body><%= content %></body> | |
</html> | |
@@ login.html.ep | |
Message: <%= $message %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment