Skip to content

Instantly share code, notes, and snippets.

Created August 19, 2014 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0245bd4bfed5963c7261 to your computer and use it in GitHub Desktop.
Save anonymous/0245bd4bfed5963c7261 to your computer and use it in GitHub Desktop.
package Narf::Controller::Example;
use Mojo::Base 'Mojolicious::Controller';
use Data::Dumper;
sub welcome {
my $self = shift;
$self->session(foo => 123);
print Dumper $self->session;
print Dumper $self->app->session;
$self->render(msg => 'Welcome to the Mojolicious real-time web framework!');
}
1;
% perl script/narf get /
[Tue Aug 19 11:14:31 2014] [debug] Your secret passphrase needs to be changed!!!
[Tue Aug 19 11:14:31 2014] [debug] GET "/".
[Tue Aug 19 11:14:31 2014] [debug] Routing to controller "Narf::Controller::Example" and action "welcome".
$VAR1 = {
'foo' => 123
};
$VAR1 = {};
[Tue Aug 19 11:14:31 2014] [debug] Rendering template "example/welcome.html.ep".
[Tue Aug 19 11:14:31 2014] [debug] Rendering template "layouts/default.html.ep".
[Tue Aug 19 11:14:31 2014] [debug] 200 OK (0.024639s, 40.586/s).
<!DOCTYPE html>
<html>
<head><title>Welcome</title></head>
<body><h2>Welcome to the Mojolicious real-time web framework!</h2>
This page was generated from the template "templates/example/welcome.html.ep"
and the layout "templates/layouts/default.html.ep",
<a href="/">click here</a> to reload the page or
<a href="/index.html">here</a> to move forward to a static page.
</body>
</html>
package Narf;
use Mojo::Base 'Mojolicious';
# This method will run once at server start
sub startup {
my $self = shift;
# Documentation browser under "/perldoc"
$self->plugin('PODRenderer');
# Router
my $r = $self->routes;
# Normal route to controller
$r->get('/')->to('example#welcome');
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment