From c4ca25055d5cf74134c325f9a985392bf54a8195 Mon Sep 17 00:00:00 2001 From: Matthew Connelly Date: Sun, 29 Nov 2015 02:44:15 +0000 Subject: [PATCH] started a rewrite kinda dealio --- .gitignore | 23 +++++++++++++++++++++++ MANIFEST.SKIP | 17 +++++++++++++++++ Makefile.PL | 26 ++++++++++++++++++++++++++ bin/app.psgi | 9 +++++++++ config.yml | 13 +++++++++++++ cpanfile | 11 +++++++++++ environments/development.yml | 23 +++++++++++++++++++++++ environments/production.yml | 16 ++++++++++++++++ lib/App/BlogAlba.pm | 17 +++++++++++++++++ lib/App/BlogAlba/Publisher.pm | 34 ++++++++++++++++++++++++++++++++++ public/dispatch.cgi | 16 ++++++++++++++++ public/dispatch.fcgi | 18 ++++++++++++++++++ t/001_base.t | 5 +++++ t/002_index_route.t | 15 +++++++++++++++ 14 files changed, 243 insertions(+) create mode 100644 .gitignore 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/App/BlogAlba.pm create mode 100644 lib/App/BlogAlba/Publisher.pm 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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3711bb1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +MANIFEST +MANIFEST.bak +Makefile +Makefile.old +Build +Build.bat +META.* +MYMETA.* +.build/ +_build/ +cover_db/ +blib/ +inc/ +.lwpcookies +.last_cover_stats +nytprof.out +pod2htm*.tmp +pm_to_blib +App-BlogAlba-* +*.tar.gz +._.* +.DS_Store +*/.DS_Store \ No newline at end of file diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..e50038a --- /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\/ +^App-BlogAlba- diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..c00dd58 --- /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 => 'App::BlogAlba', + AUTHOR => q{YOUR NAME }, + VERSION_FROM => 'lib/App/BlogAlba.pm', + ABSTRACT => 'YOUR APPLICATION ABSTRACT', + ($eumm_version >= 6.3001 + ? ('LICENSE'=> 'perl') + : ()), + PL_FILES => {}, + PREREQ_PM => { + 'Test::More' => 0, + 'YAML' => 0, + 'Dancer2' => 0.163000, + }, + dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, + clean => { FILES => 'App-BlogAlba-*' }, +); diff --git a/bin/app.psgi b/bin/app.psgi new file mode 100755 index 0000000..d12ba1d --- /dev/null +++ b/bin/app.psgi @@ -0,0 +1,9 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; + +use App::BlogAlba; +App::BlogAlba->to_app; diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..5a56dd2 --- /dev/null +++ b/config.yml @@ -0,0 +1,13 @@ +appname: "App::BlogAlba" +layout: "main" +charset: "UTF-8" +tz: "Europe/London" +locale: "en_GB" + +template: "template_toolkit" +engines: + template: + template_toolkit: + encoding: 'utf8' + start_tag: '[%' + end_tag: '%]' \ No newline at end of file diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..a91ff4a --- /dev/null +++ b/cpanfile @@ -0,0 +1,11 @@ +requires "Dancer2" => "0.163000"; + +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/App/BlogAlba.pm b/lib/App/BlogAlba.pm new file mode 100644 index 0000000..24e17db --- /dev/null +++ b/lib/App/BlogAlba.pm @@ -0,0 +1,17 @@ +package App::BlogAlba; + +use strict; +use warnings; + +use App::BlogAlba::Publisher; + +use Dancer2; +use Dancer2::Plugin::Feed; +use Dancer2::Plugin::Paginator; + +our $VERSION = '0.95'; + + + +1; +__END__ diff --git a/lib/App/BlogAlba/Publisher.pm b/lib/App/BlogAlba/Publisher.pm new file mode 100644 index 0000000..ade8cca --- /dev/null +++ b/lib/App/BlogAlba/Publisher.pm @@ -0,0 +1,34 @@ +package App::BlogAlba::Publisher; + +use strict; +use warnings; + +use Text::Markdown::Hoedown; +use YAML; + +use POSIX qw/strftime/; +use Date::Parse qw/str2time/; + +use Unicode::Normalize; + +use Exporter::Easy ( + EXPORT => [ qw// ], + OK => [ qw// ], +); + +sub FindArticles { + my ($path,$regexp) = @_; + opendir ARTICLES, $path or return undef; + my @articles; + while(readdir ARTICLES) { + push @articles, "$path/$_" if /$regexp/; + } + closedir ARTICLES; + return @articles; +} +sub ParseArticles { + +} + +1; +__END__ diff --git a/public/dispatch.cgi b/public/dispatch.cgi new file mode 100755 index 0000000..32c5d96 --- /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 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.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..e802223 --- /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 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.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..7024618 --- /dev/null +++ b/t/001_base.t @@ -0,0 +1,5 @@ +use strict; +use warnings; + +use Test::More tests => 1; +use_ok 'App::BlogAlba'; diff --git a/t/002_index_route.t b/t/002_index_route.t new file mode 100644 index 0000000..5e129e6 --- /dev/null +++ b/t/002_index_route.t @@ -0,0 +1,15 @@ +use strict; +use warnings; + +use App::BlogAlba; +use Test::More tests => 2; +use Plack::Test; +use HTTP::Request::Common; + +my $app = App::BlogAlba->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' );