Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davemenninger committed Oct 31, 2014
0 parents commit aea450b
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: ./script/lrrr daemon --listen http://*:$PORT
2 changes: 2 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requires 'Mojolicious'
requires 'Mojolicious::Plugin::Authentication'
Binary file added lib/.Lrrr.pm.swp
Binary file not shown.
44 changes: 44 additions & 0 deletions lib/Lrrr.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package Lrrr;
use Mojo::Base 'Mojolicious';

# This method will run once at server start
sub startup {
my $self = shift;

# Documentation browser under "/perldoc"
$self->plugin('PODRenderer');

# auth
$self->plugin( authentication => {
autoload_user => 1,
load_user => sub {
my $self = shift;
my $uid = shift;

return {
'username' => 'foo',
'password' => 'bar',
'name' => 'Foo'
} if($uid eq 'userid' || $uid eq 'useridwithextradata');
return undef;
},
validate_user => sub {
my $self = shift;
my $username = shift || '';
my $password = shift || '';
my $extradata = shift || {};

return 'useridwithextradata' if($username eq 'foo' && $password eq 'bar' && ( $extradata->{'ohnoes'} || '' ) eq 'itsameme');
return 'userid' if($username eq 'foo' && $password eq 'bar');
return undef;
},
});

# Router
my $r = $self->routes;

# Normal route to controller
$r->get('/')->to('example#welcome');
}

1;
12 changes: 12 additions & 0 deletions lib/Lrrr/Example.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package Lrrr::Example;
use Mojo::Base 'Mojolicious::Controller';

# This action will render a template
sub welcome {
my $self = shift;

# Render template "example/welcome.html.ep" with message
$self->render(msg => 'Welcome to the Mojolicious real-time web framework!');
}

1;
11 changes: 11 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Welcome to the Mojolicious real-time web framework!</title>
</head>
<body>
<h2>Welcome to the Mojolicious real-time web framework!</h2>
This is the static document "public/index.html",
<a href="/">click here</a> to get back to the start.
</body>
</html>
11 changes: 11 additions & 0 deletions script/lrrr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env perl

use strict;
use warnings;

use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../lib" }

# Start command line interface for application
require Mojolicious::Commands;
Mojolicious::Commands->start_app('Lrrr');
9 changes: 9 additions & 0 deletions t/basic.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use Mojo::Base -strict;

use Test::More;
use Test::Mojo;

my $t = Test::Mojo->new('Lrrr');
$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i);

done_testing();
7 changes: 7 additions & 0 deletions templates/example/welcome.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
% layout 'default';
% title 'Welcome';
<h2><%= $msg %></h2>
This page was generated from the template "templates/example/welcome.html.ep"
and the layout "templates/layouts/default.html.ep",
<a href="<%== url_for %>">click here</a> to reload the page or
<a href="/index.html">here</a> to move forward to a static page.
5 changes: 5 additions & 0 deletions templates/layouts/default.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>

0 comments on commit aea450b

Please sign in to comment.