summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-09-01 12:08:46 +0200
committerfranck cuny <franck@lumberjaph.net>2010-09-01 12:08:46 +0200
commitf033faed1c59ebeb36605232ce62f4043da22124 (patch)
treed63f9811c6a1ecf9193632c242b4a38740878a6b
downloaddancerdemo-f033faed1c59ebeb36605232ce62f4043da22124.tar.gz
initial import
-rw-r--r--Makefile.PL21
-rw-r--r--config.yml4
-rw-r--r--environments/development.yml4
-rw-r--r--environments/production.yml6
-rw-r--r--lib/mywebapp.pm13
-rw-r--r--lib/mywebapp/project.pm8
-rw-r--r--lib/mywebapp/user.pm8
-rwxr-xr-xmywebapp.pl31
-rw-r--r--public/404.html17
-rw-r--r--public/500.html17
-rw-r--r--public/css/error.css70
-rw-r--r--public/css/style.css34
-rwxr-xr-xpublic/dispatch.cgi3
-rwxr-xr-xpublic/dispatch.fcgi6
-rw-r--r--public/favicon.icobin0 -> 1406 bytes
-rw-r--r--t/001_base.t5
-rw-r--r--t/002_index_route.t12
-rw-r--r--views/index.tt5
-rw-r--r--views/layouts/main.tt17
19 files changed, 281 insertions, 0 deletions
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 <youremail@example.com>},
+    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 @@
+<!DOCTYPE html>
+<html lang="en-US">
+<head>
+<title>Error 404</title>
+<link rel="stylesheet" href="/css/error.css" />
+<meta charset=UTF-8" />
+</head>
+<body>
+<h1>Error 404</h1>
+<div id="content">
+<h2>Page Not Found</h2><p>Sorry, this is the void.</p>
+</div>
+<footer>
+Powered by <a href="http://perldancer.org/">Dancer</a> 1.1808
+</footer>
+</body>
+</html>
\ 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 @@
+<!DOCTYPE html>
+<html lang="en-US">
+<head>
+<title>Error 500</title>
+<link rel="stylesheet" href="/css/error.css" />
+<meta charset=UTF-8" />
+</head>
+<body>
+<h1>Error 500</h1>
+<div id="content">
+<h2>Internal Server Error</h2><p>Wooops, something went wrong</p>
+</div>
+<footer>
+Powered by <a href="http://perldancer.org/">Dancer</a> 1.1808
+</footer>
+</body>
+</html>
\ 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
--- /dev/null
+++ b/public/favicon.ico
Binary files differdiff --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 @@
+<h2>It Works!</h2>
+
+<p>
+I'm in <code>/home/franck/.tmp/mywebapp/views/index.tt</code>
+</p>
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 @@
+<!DOCTYPE html>
+<html lang="en-US">
+<head>
+<title>mywebapp</title>
+<link rel="stylesheet" href="/css/style.css" />
+<meta charset=UTF-8" />
+</head>
+<body>
+<h1>mywebapp</h1>
+<div id="content">
+<% content %>
+</div>
+<footer>
+Powered by <a href="http://perldancer.org/">Dancer</a> 1.1808
+</footer>
+</body>
+</html>
\ No newline at end of file