From f033faed1c59ebeb36605232ce62f4043da22124 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Wed, 1 Sep 2010 12:08:46 +0200 Subject: initial import --- Makefile.PL | 21 +++++++++++++ config.yml | 4 +++ environments/development.yml | 4 +++ environments/production.yml | 6 ++++ lib/mywebapp.pm | 13 ++++++++ lib/mywebapp/project.pm | 8 +++++ lib/mywebapp/user.pm | 8 +++++ mywebapp.pl | 31 +++++++++++++++++++ public/404.html | 17 +++++++++++ public/500.html | 17 +++++++++++ public/css/error.css | 70 +++++++++++++++++++++++++++++++++++++++++++ public/css/style.css | 34 +++++++++++++++++++++ public/dispatch.cgi | 3 ++ public/dispatch.fcgi | 6 ++++ public/favicon.ico | Bin 0 -> 1406 bytes t/001_base.t | 5 ++++ t/002_index_route.t | 12 ++++++++ views/index.tt | 5 ++++ views/layouts/main.tt | 17 +++++++++++ 19 files changed, 281 insertions(+) create mode 100644 Makefile.PL create mode 100644 config.yml create mode 100644 environments/development.yml create mode 100644 environments/production.yml create mode 100644 lib/mywebapp.pm create mode 100644 lib/mywebapp/project.pm create mode 100644 lib/mywebapp/user.pm create mode 100755 mywebapp.pl create mode 100644 public/404.html create mode 100644 public/500.html create mode 100644 public/css/error.css create mode 100644 public/css/style.css create mode 100755 public/dispatch.cgi create mode 100755 public/dispatch.fcgi create mode 100644 public/favicon.ico create mode 100644 t/001_base.t create mode 100644 t/002_index_route.t create mode 100644 views/index.tt create mode 100644 views/layouts/main.tt diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..477f391 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,21 @@ +use strict; +use warnings; +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'mywebapp', + AUTHOR => q{YOUR NAME }, + VERSION_FROM => 'lib/mywebapp.pm', + ABSTRACT => 'YOUR APPLICATION ABSTRACT', + ($ExtUtils::MakeMaker::VERSION >= 6.3002 + ? ('LICENSE'=> 'perl') + : ()), + PL_FILES => {}, + PREREQ_PM => { + 'Test::More' => 0, + 'YAML' => 0, + 'Dancer' => 1.1808, + }, + dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, + clean => { FILES => 'mywebapp-*' }, +); diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..cbe8a0e --- /dev/null +++ b/config.yml @@ -0,0 +1,4 @@ +layout: "main" +logger: "file" +appname: "mywebapp" +serializer: "mutable" diff --git a/environments/development.yml b/environments/development.yml new file mode 100644 index 0000000..97d3b59 --- /dev/null +++ b/environments/development.yml @@ -0,0 +1,4 @@ +log: "debug" +warnings: 1 +show_errors: 1 +auto_reload: 1 diff --git a/environments/production.yml b/environments/production.yml new file mode 100644 index 0000000..1a69035 --- /dev/null +++ b/environments/production.yml @@ -0,0 +1,6 @@ +log: "warning" +warnings: 0 +show_errors: 0 +route_cache: 1 +auto_reload: 0 + diff --git a/lib/mywebapp.pm b/lib/mywebapp.pm new file mode 100644 index 0000000..c756952 --- /dev/null +++ b/lib/mywebapp.pm @@ -0,0 +1,13 @@ +package mywebapp; +use Dancer ':syntax'; + +our $VERSION = '0.1'; + +load_app 'mywebapp::user', prefix => '/user'; +load_app 'mywebapp::project', prefix => '/project'; + +get '/' => sub { + template 'index'; +}; + +true; diff --git a/lib/mywebapp/project.pm b/lib/mywebapp/project.pm new file mode 100644 index 0000000..abb53ab --- /dev/null +++ b/lib/mywebapp/project.pm @@ -0,0 +1,8 @@ +package mywebapp::project; + +use Dancer ':syntax'; + +get '/' => sub { +}; + +1; \ No newline at end of file diff --git a/lib/mywebapp/user.pm b/lib/mywebapp/user.pm new file mode 100644 index 0000000..874c691 --- /dev/null +++ b/lib/mywebapp/user.pm @@ -0,0 +1,8 @@ +package mywebapp::user; + +use Dancer ':syntax'; + +get '/' => sub { + {users => [{name => 'franck', 'role' => 'developer'}, {name => 'alexis', + 'role' => 'developer'}, {name => 'cmaussan', role => 'tester'}]}; +}; \ No newline at end of file diff --git a/mywebapp.pl b/mywebapp.pl new file mode 100755 index 0000000..9af1372 --- /dev/null +++ b/mywebapp.pl @@ -0,0 +1,31 @@ +#!/usr/bin/env perl +use Dancer; +use lib ('lib'); +load_app 'mywebapp'; + +use Plack::Builder; +use Log::Dispatch::Config; +use Log::Dispatch::File; + +my $logger = Log::Dispatch->new; +$logger->add( + Log::Dispatch::File->new( + min_level => 'info', + filename => 'logs/mywebapp.log', + mode => 'append', + newline => 1, + ) +); + +my $app = sub { + my $env = shift; + my $request = Dancer::Request->new($env); + Dancer->dance($request); +}; + +builder { + enable "Transaction"; + enable "APIRateLimit", requests_per_hour => 2; + enable "LogDispatch", logger => $logger; + $app; +}; diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..8f38fab --- /dev/null +++ b/public/404.html @@ -0,0 +1,17 @@ + + + +Error 404 + + + + +

Error 404

+
+

Page Not Found

Sorry, this is the void.

+
+ + + \ No newline at end of file diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000..5f4b174 --- /dev/null +++ b/public/500.html @@ -0,0 +1,17 @@ + + + +Error 500 + + + + +

Error 500

+
+

Internal Server Error

Wooops, something went wrong

+
+ + + \ No newline at end of file diff --git a/public/css/error.css b/public/css/error.css new file mode 100644 index 0000000..003ee2a --- /dev/null +++ b/public/css/error.css @@ -0,0 +1,70 @@ +body { + font-family: Lucida,sans-serif; +} + +h1 { + color: #AA0000; + border-bottom: 1px solid #444; +} + +h2 { color: #444; } + +pre { + font-family: "lucida console","monaco","andale mono","bitstream vera sans mono","consolas",monospace; + font-size: 12px; + border-left: 2px solid #777; + padding-left: 1em; +} + +footer { + font-size: 10px; +} + +span.key { + color: #449; + font-weight: bold; + width: 120px; + display: inline; +} + +span.value { + color: #494; +} + +/* these are for the message boxes */ + +pre.content { + background-color: #eee; + color: #000; + padding: 1em; + margin: 0; + border: 1px solid #aaa; + border-top: 0; + margin-bottom: 1em; +} + +div.title { + font-family: "lucida console","monaco","andale mono","bitstream vera sans mono","consolas",monospace; + font-size: 12px; + background-color: #aaa; + color: #444; + font-weight: bold; + padding: 3px; + padding-left: 10px; +} + +pre.content span.nu { + color: #889; + margin-right: 10px; +} + +pre.error { + background: #334; + color: #ccd; + padding: 1em; + border-top: 1px solid #000; + border-left: 1px solid #000; + border-right: 1px solid #eee; + border-bottom: 1px solid #eee; +} + diff --git a/public/css/style.css b/public/css/style.css new file mode 100644 index 0000000..b4ae038 --- /dev/null +++ b/public/css/style.css @@ -0,0 +1,34 @@ +body { + font-family: Lucida,sans-serif; + color: #eee; + background-color: #1f1b1a; +} + +#content { + color: #000; + background-color: #eee; + padding: 1em; + margin: 1em; + padding-top: 0.5em; +} + +a { + color: #a5ec02; +} + +h1 { + color: #a5ec02; +} + +footer { + border-top: 1px solid #aba29c; + margin-top: 2em; + padding-top: 1em; + font-size: 10px; + color: #ddd; +} + +pre { + font-family: \"lucida console\",\"monaco\",\"andale mono\",\"bitstream vera sans mono\",\"consolas\",monospace; +} + diff --git a/public/dispatch.cgi b/public/dispatch.cgi new file mode 100755 index 0000000..6b9ffa6 --- /dev/null +++ b/public/dispatch.cgi @@ -0,0 +1,3 @@ +#!/usr/bin/env perl +use Plack::Runner; +Plack::Runner->run('/home/franck/.tmp/mywebapp/mywebapp.pl'); diff --git a/public/dispatch.fcgi b/public/dispatch.fcgi new file mode 100755 index 0000000..6268cad --- /dev/null +++ b/public/dispatch.fcgi @@ -0,0 +1,6 @@ +#!/usr/bin/env perl +use Plack::Handler::FCGI; + +my $app = do('/home/franck/.tmp/mywebapp/mywebapp.pl'); +my $server = Plack::Handler::FCGI->new(nproc => 5, detach => 1); +$server->run($app); diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..957f4b4 Binary files /dev/null and b/public/favicon.ico differ diff --git a/t/001_base.t b/t/001_base.t new file mode 100644 index 0000000..cb10866 --- /dev/null +++ b/t/001_base.t @@ -0,0 +1,5 @@ +use Test::More tests => 1; +use strict; +use warnings; + +use_ok 'mywebapp'; diff --git a/t/002_index_route.t b/t/002_index_route.t new file mode 100644 index 0000000..9f3494b --- /dev/null +++ b/t/002_index_route.t @@ -0,0 +1,12 @@ +use Test::More tests => 3; +use strict; +use warnings; + +# the order is important +use mywebapp; +use Dancer::Test; + +route_exists [GET => '/'], 'a route handler is defined for /'; +response_status_is ['GET' => '/'], 200, 'response status is 200 for /'; +response_content_like [GET => '/'], qr/It Works.*I'm in.*index.tt/s, + 'content looks OK for /'; diff --git a/views/index.tt b/views/index.tt new file mode 100644 index 0000000..f89df94 --- /dev/null +++ b/views/index.tt @@ -0,0 +1,5 @@ +

It Works!

+ +

+I'm in /home/franck/.tmp/mywebapp/views/index.tt +

diff --git a/views/layouts/main.tt b/views/layouts/main.tt new file mode 100644 index 0000000..aca1dd0 --- /dev/null +++ b/views/layouts/main.tt @@ -0,0 +1,17 @@ + + + +mywebapp + + + + +

mywebapp

+
+<% content %> +
+ + + \ No newline at end of file -- cgit 1.4.1