Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Port to Dancer

  • Loading branch information...
commit ee93a98d357c5e4ca470b70e31c0e02d15e2c8b2 1 parent 42f9317
@mxey mxey authored
View
19 MANIFEST
@@ -0,0 +1,19 @@
+MANIFEST
+bin/app.pl
+config.yml
+environments/development.yml
+environments/production.yml
+views/index.tt
+views/layouts/main.tt
+MANIFEST.SKIP
+lib/genregenerator.pm
+public/css/style.css
+public/css/error.css
+public/404.html
+public/dispatch.fcgi
+public/javascripts/jquery.js
+public/dispatch.cgi
+public/500.html
+t/002_index_route.t
+t/001_base.t
+Makefile.PL
View
13 MANIFEST.SKIP
@@ -0,0 +1,13 @@
+^\.git\/
+maint
+^tags$
+.last_cover_stats
+Makefile$
+^blib
+^pm_to_blib
+^.*.bak
+^.*.old
+^t.*sessions
+^cover_db
+^.*\.log
+^.*\.swp$
View
21 Makefile.PL
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'genregenerator',
+ AUTHOR => q{YOUR NAME <youremail@example.com>},
+ VERSION_FROM => 'lib/genregenerator.pm',
+ ABSTRACT => 'YOUR APPLICATION ABSTRACT',
+ ($ExtUtils::MakeMaker::VERSION >= 6.3002
+ ? ('LICENSE'=> 'perl')
+ : ()),
+ PL_FILES => {},
+ PREREQ_PM => {
+ 'Test::More' => 0,
+ 'YAML' => 0,
+ 'Dancer' => 1.3060,
+ },
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'genregenerator-*' },
+);
View
67 app.psgi
@@ -1,67 +0,0 @@
-#!/usr/bin/env perl
-# Copyright 2011 Maximilian Gaß <mxey@ghosthacking.net>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-use strict;
-use warnings;
-
-use Data::Random qw(rand_enum);
-use Plack::App::File;
-use Plack::Builder;
-use YAML::XS qw(LoadFile);
-use Template;
-
-chdir ('/srv/www/de.genregenerator');
-my $data = LoadFile('genres.yaml');
-
-my $template = Template->new({
- INCLUDE_PATH => '.',
-});
-
-sub chance {
- my ($percent) = @_;
- return int(rand(100 / $percent)) == 0;
-}
-
-sub generate_genre {
- my @genre;
-
- if (chance(10)) {
- push @genre, rand_enum(set => $data->{cities});
- }
-
- if (chance(70)) {
- push @genre, rand_enum(set => $data->{subgroup});
- }
-
-
- push @genre, rand_enum(set => $data->{subgroup});
- push @genre, rand_enum(set => $data->{group});
-
- return join ' ', @genre;
-}
-
-builder {
- mount '/static' => Plack::App::File->new(root => 'static')->to_app(),
- mount '/' => sub {
- my $genre = generate_genre();
- my $out = '';
- $template->process('index.tt', { genre => $genre }, \$out);
- return [
- 200,
- [ 'Content-Type' => 'text/html' ],
- [ $out ]
- ];
- },
-}
View
5 bin/app.pl
@@ -0,0 +1,5 @@
+#!/usr/bin/env perl
+use Dancer;
+use App::Genregenerator;
+
+dance;
View
9 config.yml
@@ -0,0 +1,9 @@
+# Your application's name
+appname: "genregenerator"
+
+# when the charset is set to UTF-8 Dancer will handle for you
+# all the magic of encoding and decoding. You should not care
+# about unicode within your app when this setting is set (recommended).
+charset: "UTF-8"
+
+template: "simple"
View
27 environments/development.yml
@@ -0,0 +1,27 @@
+# configuration file for development environment
+
+# the logger engine to use
+# console: log messages to STDOUT (your console where you started the
+# application server)
+# file: log message to a file in log/
+logger: "console"
+
+# the log level for this environement
+# core is the lowest, it shows Dancer's core log messages as well as yours
+# (debug, warning and error)
+log: "core"
+
+# should Dancer consider warnings as critical errors?
+warnings: 1
+
+# should Dancer show a stacktrace when an error is caught?
+show_errors: 1
+
+# auto_reload is a development and experimental feature
+# you should enable it by yourself if you want it
+# Module::Refresh is needed
+#
+# Be aware it's unstable and may cause a memory leak.
+# DO NOT EVER USE THAT FEATURE IN PRODUCTION
+# OR TINY KITTENS SHALL DIE WITH LOTS OF SUFFERING
+auto_reload: 0
View
17 environments/production.yml
@@ -0,0 +1,17 @@
+# configuration file for production environment
+
+# only log warning and error messsages
+log: "warning"
+
+# log message to a file in logs/
+logger: "null"
+
+# don't consider warnings critical
+warnings: 0
+
+# hide errors
+show_errors: 0
+
+# cache route resolution for maximum performance
+route_cache: 1
+
View
0  genres.yaml → genres.yml
File renamed without changes
View
28 index.tt
@@ -1,28 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
- <head>
- <title></title>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <link rel="stylesheet" type="text/css" href="static/style.css" />
- </head>
- <body>
-
- <div id="title">
- Listen to
- </div>
-
- <div id="genre">
- <a href="/">[% genre %]</a>
- </div>
-
- <div id="twitter">
- <a href="http://twitter.com/share" class="twitter-share-button" data-text="I listen to [% genre %] #genregenerator" data-count="horizontal">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script><br />
- </div>
-
- <div id="impressum">
- Created by <a href="http://www.thehappy.de/~xeno/">xeno</a> and <a href="http://ghosthacking.net">mxey</a> | <a href="http://ghosthacking.net/git/genregenerator.git">git</a>
- </div>
-
- </body>
-</html>
View
28 lib/App/Genregenerator.pm
@@ -0,0 +1,28 @@
+package App::Genregenerator;
+use Dancer ':syntax';
+use Data::Random qw(rand_enum);
+use YAML::XS qw(LoadFile);
+
+my $data = LoadFile('genres.yml');
+
+sub chance {
+ my ($percent) = @_;
+ return int(rand(100 / $percent)) == 0;
+}
+
+sub generate_genre {
+ my @genre;
+
+ push @genre, rand_enum(set => $data->{cities}) if chance 10;
+ push @genre, rand_enum(set => $data->{subgroup}) if chance 70;
+ push @genre, rand_enum(set => $data->{subgroup});
+ push @genre, rand_enum(set => $data->{group});
+
+ return join ' ', @genre;
+}
+
+get '/' => sub {
+ template 'index', { genre => generate_genre() };
+};
+
+true;
View
18 public/404.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+<head>
+<title>Error 404</title>
+<link rel="stylesheet" href="/css/error.css" />
+<meta http-equiv="Content-type" content="text/html; 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>
+<div id="footer">
+Powered by <a href="http://perldancer.org/">Dancer</a> 1.3060
+</div>
+</body>
+</html>
View
18 public/500.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+<head>
+<title>Error 500</title>
+<link rel="stylesheet" href="/css/error.css" />
+<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
+</head>
+<body>
+<h1>Error 500</h1>
+<div id="content">
+<h2>Internal Server Error</h2><p>Wooops, something went wrong</p>
+</div>
+<div id="footer">
+Powered by <a href="http://perldancer.org/">Dancer</a> 1.3060
+</div>
+</body>
+</html>
View
70 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;
+}
+
View
0  static/style.css → public/css/style.css
File renamed without changes
View
15 public/dispatch.cgi
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+use Dancer ':syntax';
+use FindBin '$RealBin';
+use Plack::Runner;
+
+# For some reason Apache SetEnv directives dont propagate
+# correctly to the dispatchers, so forcing PSGI and env here
+# is safer.
+set apphandler => 'PSGI';
+set environment => 'production';
+
+my $psgi = path($RealBin, '..', 'bin', 'app.pl');
+die "Unable to read startup script: $psgi" unless -r $psgi;
+
+Plack::Runner->run($psgi);
View
17 public/dispatch.fcgi
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+use Dancer ':syntax';
+use FindBin '$RealBin';
+use Plack::Handler::FCGI;
+
+# For some reason Apache SetEnv directives dont propagate
+# correctly to the dispatchers, so forcing PSGI and env here
+# is safer.
+set apphandler => 'PSGI';
+set environment => 'production';
+
+my $psgi = path($RealBin, '..', 'bin', 'app.pl');
+my $app = do($psgi);
+die "Unable to read startup script: $@" if $@;
+my $server = Plack::Handler::FCGI->new(nproc => 5, detach => 1);
+
+$server->run($app);
View
1  public/javascripts/jquery.js
View
5 t/001_base.t
@@ -0,0 +1,5 @@
+use Test::More tests => 1;
+use strict;
+use warnings;
+
+use_ok 'App::Genregenerator';
View
10 t/002_index_route.t
@@ -0,0 +1,10 @@
+use Test::More tests => 2;
+use strict;
+use warnings;
+
+# the order is important
+use App::Genregenerator;
+use Dancer::Test;
+
+route_exists [GET => '/'], 'a route handler is defined for /';
+response_status_is ['GET' => '/'], 200, 'response status is 200 for /';
View
28 views/index.tt
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+ <head>
+ <title></title>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" type="text/css" href="/css/style.css" />
+ </head>
+ <body>
+
+ <div id="title">
+ Listen to
+ </div>
+
+ <div id="genre">
+ <a href="/"><% genre %></a>
+ </div>
+
+ <div id="twitter">
+ <a href="http://twitter.com/share" class="twitter-share-button" data-text="I listen to <% genre %> #genregenerator" data-count="horizontal">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script><br />
+ </div>
+
+ <div id="impressum">
+ Created by <a href="http://www.thehappy.de/~xeno/">xeno</a> and <a href="http://ghosthacking.net">mxey</a> | <a href="http://ghosthacking.net/git/genregenerator.git">git</a>
+ </div>
+
+ </body>
+</html>

0 comments on commit ee93a98

Please sign in to comment.
Something went wrong with that request. Please try again.