diff --git a/Procfile b/Procfile new file mode 100755 index 0000000..f4461bd --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: ./script/lrrr daemon --listen http://*:$PORT diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..f6771e2 --- /dev/null +++ b/cpanfile @@ -0,0 +1,2 @@ +requires 'Mojolicious' +requires 'Mojolicious::Plugin::Authentication' diff --git a/lib/.Lrrr.pm.swp b/lib/.Lrrr.pm.swp new file mode 100644 index 0000000..f0e76c7 Binary files /dev/null and b/lib/.Lrrr.pm.swp differ diff --git a/lib/Lrrr.pm b/lib/Lrrr.pm new file mode 100644 index 0000000..35c5406 --- /dev/null +++ b/lib/Lrrr.pm @@ -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; diff --git a/lib/Lrrr/Example.pm b/lib/Lrrr/Example.pm new file mode 100644 index 0000000..a9c1767 --- /dev/null +++ b/lib/Lrrr/Example.pm @@ -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; diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..e74bb5f --- /dev/null +++ b/public/index.html @@ -0,0 +1,11 @@ + + + + Welcome to the Mojolicious real-time web framework! + + +

Welcome to the Mojolicious real-time web framework!

+ This is the static document "public/index.html", + click here to get back to the start. + + diff --git a/script/lrrr b/script/lrrr new file mode 100755 index 0000000..6d1d524 --- /dev/null +++ b/script/lrrr @@ -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'); diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..a879644 --- /dev/null +++ b/t/basic.t @@ -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(); diff --git a/templates/example/welcome.html.ep b/templates/example/welcome.html.ep new file mode 100644 index 0000000..f77e8a2 --- /dev/null +++ b/templates/example/welcome.html.ep @@ -0,0 +1,7 @@ +% layout 'default'; +% title 'Welcome'; +

<%= $msg %>

+This page was generated from the template "templates/example/welcome.html.ep" +and the layout "templates/layouts/default.html.ep", +click here to reload the page or +here to move forward to a static page. diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep new file mode 100644 index 0000000..599c556 --- /dev/null +++ b/templates/layouts/default.html.ep @@ -0,0 +1,5 @@ + + + <%= title %> + <%= content %> +