From a9f74287f4eda3af26ee83a6cc748370ce4c8569 Mon Sep 17 00:00:00 2001 From: Al Beano Date: Fri, 14 Jul 2017 18:29:52 +0100 Subject: [PATCH] initial commit --- .dancer | 0 MANIFEST | 24 ++++++ MANIFEST.SKIP | 17 ++++ Makefile.PL | 26 ++++++ bin/app.psgi | 52 ++++++++++++ config.yml | 52 ++++++++++++ cpanfile | 11 +++ environments/development.yml | 23 ++++++ environments/production.yml | 16 ++++ lib/cyberman.pm | 10 +++ public/404.html | 18 +++++ public/500.html | 18 +++++ public/dispatch.cgi | 16 ++++ public/dispatch.fcgi | 18 +++++ t/001_base.t | 5 ++ t/002_index_route.t | 15 ++++ views/index.tt | 148 +++++++++++++++++++++++++++++++++++ views/layouts/main.tt | 22 ++++++ 18 files changed, 491 insertions(+) create mode 100644 .dancer create mode 100644 MANIFEST create mode 100644 MANIFEST.SKIP create mode 100644 Makefile.PL create mode 100755 bin/app.psgi create mode 100644 config.yml create mode 100644 cpanfile create mode 100644 environments/development.yml create mode 100644 environments/production.yml create mode 100644 lib/cyberman.pm create mode 100644 public/404.html create mode 100644 public/500.html create mode 100755 public/dispatch.cgi create mode 100755 public/dispatch.fcgi 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/.dancer b/.dancer new file mode 100644 index 0000000..e69de29 diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..33519d5 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,24 @@ +MANIFEST +.dancer +cpanfile +MANIFEST.SKIP +config.yml +Makefile.PL +t/002_index_route.t +t/001_base.t +bin/app.psgi +lib/cyberman.pm +environments/development.yml +environments/production.yml +public/404.html +public/dispatch.cgi +public/dispatch.fcgi +public/500.html +public/favicon.ico +public/css/error.css +public/css/style.css +public/images/perldancer-bg.jpg +public/images/perldancer.jpg +public/javascripts/jquery.js +views/index.tt +views/layouts/main.tt diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..87110ed --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,17 @@ +^\.git\/ +maint +^tags$ +.last_cover_stats +Makefile$ +^blib +^pm_to_blib +^.*.bak +^.*.old +^t.*sessions +^cover_db +^.*\.log +^.*\.swp$ +MYMETA.* +^.gitignore +^.svn\/ +^cyberman- diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..6024203 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,26 @@ +use strict; +use warnings; +use ExtUtils::MakeMaker; + +# Normalize version strings like 6.30_02 to 6.3002, +# so that we can do numerical comparisons on it. +my $eumm_version = $ExtUtils::MakeMaker::VERSION; +$eumm_version =~ s/_//; + +WriteMakefile( + NAME => 'cyberman', + AUTHOR => q{YOUR NAME }, + VERSION_FROM => 'lib/cyberman.pm', + ABSTRACT => 'YOUR APPLICATION ABSTRACT', + ($eumm_version >= 6.3001 + ? ('LICENSE'=> 'perl') + : ()), + PL_FILES => {}, + PREREQ_PM => { + 'Test::More' => 0, + 'YAML' => 0, + 'Dancer2' => 0.205001, + }, + dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, + clean => { FILES => 'cyberman-*' }, +); diff --git a/bin/app.psgi b/bin/app.psgi new file mode 100755 index 0000000..40e8f3c --- /dev/null +++ b/bin/app.psgi @@ -0,0 +1,52 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; + + +# use this block if you don't need middleware, and only have a single target Dancer app to run here +use cyberman; + +cyberman->to_app; + +use Plack::Builder; + +builder { + enable 'Deflater'; + cyberman->to_app; +} + + + +=begin comment +# use this block if you want to include middleware such as Plack::Middleware::Deflater + +use cyberman; +use Plack::Builder; + +builder { + enable 'Deflater'; + cyberman->to_app; +} + +=end comment + +=cut + +=begin comment +# use this block if you want to include middleware such as Plack::Middleware::Deflater + +use cyberman; +use cyberman_admin; + +builder { + mount '/' => cyberman->to_app; + mount '/admin' => cyberman_admin->to_app; +} + +=end comment + +=cut + diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..6b4523e --- /dev/null +++ b/config.yml @@ -0,0 +1,52 @@ +# This is the main configuration file of your Dancer2 app +# env-related settings should go to environments/$env.yml +# all the settings in this file will be loaded at Dancer's startup. + +# Your application's name +appname: "cyberman" + +# The default layout to use for your application (located in +# views/layouts/main.tt) +layout: "main" + +# when the charset is set to UTF-8 Dancer2 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 engine +# simple: default and very basic template engine +# template_toolkit: TT + +template: "simple" + +# template: "template_toolkit" +# engines: +# template: +# template_toolkit: +# start_tag: '<%' +# end_tag: '%>' + +# session engine +# +# Simple: in-memory session store - Dancer2::Session::Simple +# YAML: session stored in YAML files - Dancer2::Session::YAML +# +# Check out metacpan for other session storage options: +# https://metacpan.org/search?q=Dancer2%3A%3ASession&search_type=modules +# +# Default value for 'cookie_name' is 'dancer.session'. If you run multiple +# Dancer apps on the same host then you will need to make sure 'cookie_name' +# is different for each app. +# +#engines: +# session: +# Simple: +# cookie_name: testapp.session +# +#engines: +# session: +# YAML: +# cookie_name: eshop.session +# is_secure: 1 +# is_http_only: 1 diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..79a41a8 --- /dev/null +++ b/cpanfile @@ -0,0 +1,11 @@ +requires "Dancer2" => "0.205001"; + +recommends "YAML" => "0"; +recommends "URL::Encode::XS" => "0"; +recommends "CGI::Deurl::XS" => "0"; +recommends "HTTP::Parser::XS" => "0"; + +on "test" => sub { + requires "Test::More" => "0"; + requires "HTTP::Request::Common" => "0"; +}; diff --git a/environments/development.yml b/environments/development.yml new file mode 100644 index 0000000..096e561 --- /dev/null +++ b/environments/development.yml @@ -0,0 +1,23 @@ +# 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 environment +# core is the lowest, it shows Dancer2's core log messages as well as yours +# (debug, info, warning and error) +log: "core" + +# should Dancer2 consider warnings as critical errors? +warnings: 1 + +# should Dancer2 show a stacktrace when an 5xx error is caught? +# if set to yes, public/500.html will be ignored and either +# views/500.tt, 'error_template' template, or a default error template will be used. +show_errors: 1 + +# print the banner +startup_info: 1 diff --git a/environments/production.yml b/environments/production.yml new file mode 100644 index 0000000..41b436f --- /dev/null +++ b/environments/production.yml @@ -0,0 +1,16 @@ +# configuration file for production environment + +# only log warning and error messsages +log: "warning" + +# log message to a file in logs/ +logger: "file" + +# don't consider warnings critical +warnings: 0 + +# hide errors +show_errors: 0 + +# disable server tokens in production environments +no_server_tokens: 1 diff --git a/lib/cyberman.pm b/lib/cyberman.pm new file mode 100644 index 0000000..614651c --- /dev/null +++ b/lib/cyberman.pm @@ -0,0 +1,10 @@ +package cyberman; +use Dancer2; + +our $VERSION = '0.1'; + +get '/' => sub { + template 'index' => { 'title' => 'cyberman' }; +}; + +true; diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..c2f4032 --- /dev/null +++ b/public/404.html @@ -0,0 +1,18 @@ + + + + + + Error 404 + + + +

Error 404

+
+

Page Not Found

Sorry, this is the void.

+
+ + + diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000..d84ebbc --- /dev/null +++ b/public/500.html @@ -0,0 +1,18 @@ + + + + + + Error 500 + + + +

Error 500

+
+

Internal Server Error

Wooops, something went wrong

+
+ + + diff --git a/public/dispatch.cgi b/public/dispatch.cgi new file mode 100755 index 0000000..706ba0c --- /dev/null +++ b/public/dispatch.cgi @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +BEGIN { $ENV{DANCER_APPHANDLER} = 'PSGI';} +use Dancer2; +use FindBin '$RealBin'; +use Plack::Runner; + +# For some reason Apache SetEnv directives don't 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.psgi'); +die "Unable to read startup script: $psgi" unless -r $psgi; + +Plack::Runner->run($psgi); diff --git a/public/dispatch.fcgi b/public/dispatch.fcgi new file mode 100755 index 0000000..ad42deb --- /dev/null +++ b/public/dispatch.fcgi @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +BEGIN { $ENV{DANCER_APPHANDLER} = 'PSGI';} +use Dancer2; +use FindBin '$RealBin'; +use Plack::Handler::FCGI; + +# For some reason Apache SetEnv directives don't 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.psgi'); +my $app = do($psgi); +die "Unable to read startup script: $@" if $@; +my $server = Plack::Handler::FCGI->new(nproc => 5, detach => 1); + +$server->run($app); diff --git a/t/001_base.t b/t/001_base.t new file mode 100644 index 0000000..e31d601 --- /dev/null +++ b/t/001_base.t @@ -0,0 +1,5 @@ +use strict; +use warnings; + +use Test::More tests => 1; +use_ok 'cyberman'; diff --git a/t/002_index_route.t b/t/002_index_route.t new file mode 100644 index 0000000..4d35e73 --- /dev/null +++ b/t/002_index_route.t @@ -0,0 +1,15 @@ +use strict; +use warnings; + +use cyberman; +use Test::More tests => 2; +use Plack::Test; +use HTTP::Request::Common; + +my $app = cyberman->to_app; +is( ref $app, 'CODE', 'Got app' ); + +my $test = Plack::Test->create($app); +my $res = $test->request( GET '/' ); + +ok( $res->is_success, '[GET /] successful' ); diff --git a/views/index.tt b/views/index.tt new file mode 100644 index 0000000..8084bfc --- /dev/null +++ b/views/index.tt @@ -0,0 +1,148 @@ + + + +
+ + +
+ + +
+

Getting started

+

Here’s how to get dancing:

+ +

About your application's environment

+ + + + + + +
    +
  1. +

    Tune your application

    + +

    + Your application is configured via a global configuration file, + config.yml and an "environment" configuration file, + environments/development.yml. Edit those files if you + want to change the settings of your application. +

    +
  2. + +
  3. +

    Add your own routes

    + +

    + The default route that displays this page can be removed, + it's just here to help you get started. The template used to + generate this content is located in + views/index.tt. + You can add some routes to lib/cyberman.pm. +

    +
  4. + +
  5. +

    Enjoy web development again

    + +

    + Once you've made your changes, restart your standalone server + (bin/app.psgi) and you're ready + to test your web application. +

    +
  6. + +
+
+
+
diff --git a/views/layouts/main.tt b/views/layouts/main.tt new file mode 100644 index 0000000..ca4577b --- /dev/null +++ b/views/layouts/main.tt @@ -0,0 +1,22 @@ + + + + + + <% title %> + + + + + + + + +<% content %> + + +