From aea450b633dfbf12ac7b38836bbd56ad6f824ef8 Mon Sep 17 00:00:00 2001 From: Dave Menninger Date: Fri, 31 Oct 2014 14:41:38 -0400 Subject: [PATCH] initial commit --- Procfile | 1 + cpanfile | 2 ++ lib/.Lrrr.pm.swp | Bin 0 -> 12288 bytes lib/Lrrr.pm | 44 ++++++++++++++++++++++++++++++ lib/Lrrr/Example.pm | 12 ++++++++ public/index.html | 11 ++++++++ script/lrrr | 11 ++++++++ t/basic.t | 9 ++++++ templates/example/welcome.html.ep | 7 +++++ templates/layouts/default.html.ep | 5 ++++ 10 files changed, 102 insertions(+) create mode 100755 Procfile create mode 100644 cpanfile create mode 100644 lib/.Lrrr.pm.swp create mode 100644 lib/Lrrr.pm create mode 100644 lib/Lrrr/Example.pm create mode 100644 public/index.html create mode 100755 script/lrrr create mode 100644 t/basic.t create mode 100644 templates/example/welcome.html.ep create mode 100644 templates/layouts/default.html.ep 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 0000000000000000000000000000000000000000..f0e76c7ca3e7239c832ccf5d4cf98223a25c4f87 GIT binary patch literal 12288 zcmeI2&x;gC6vxYWOQME&OD@ly!I}kk$BlwN7Do*t1hPhS6UZslbl2=u?Cu(?t9Mq` zF_+{|$RXfa$v@yde}IBNKq3D_4qm#JL-%yOdj0BC)rV%ffBd_z z*67soNrm=_Qv07@U%#jxbV8|AYBnujepAbBQMh8mhGpmXioL@LySe|-ce4;eH*@{& z*Em@o<$Dd2J~1E$-id(&>ckf-$2nDN;Rqf6^xJomRg#DSF(3xSfEW-1Vn7Ut0Wt7? z7>J{N>L--?!L;0C)8oE>9j8C#AO^&M7!U(uKn#chF(3xSfEW-1Vn7VMhXzcFcmI!+ zdIb3Y|JnQh%R@>%15d$y@EiCA{0zPaXTWLD1s{T!2bKC0`~mKRd*D|P!F6x~{B=O7 z7vM2?0Pcb3E5Ci`&11qaaO%zc(EcG^Q?C7puTQ9SM8H@CwZC(~RCUnZvB@4?LXC^{A}+v|U&D#--qCOqvC7jpf;*U<&PO?%KTK z>0-}3XkI*B|3U@&GFDK{`uM14^VeLV=C$12CUwAU@=XA5f!%=VKHBEJ*fdtk<;|<$ zKJNLiq|BT2HG)hP{an`y-*mdoM_IMuiVh)YXp86)6P+)(ezx1HuX9E7;ri+~m#$gt z_+Y2|wMCbFQsLwH*d*u&Kjx+4$0E=|cVt7B`eb4Dq|H~)t64@9Vl~2jTeLoOCFM2_ zeM)1O;hC)p@K(;SN3Pmera&3`8;!p^HqtRH!{f$vtfz9ykAv+ E1FbJ^K>z>% literal 0 HcmV?d00001 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 %> +