]>
iEval git - gruntmaster-page.git/blob - lib/Plack/App/Gruntmaster.pm
1 package Plack
::App
::Gruntmaster
;
6 use parent qw
/Plack::Component/;
7 no if $] >= 5.017011, warnings
=> 'experimental::smartmatch';
8 our $VERSION = '5999.000_001';
10 use File
::Slurp qw
/read_file/;
11 use HTTP
::Negotiate qw
/choose/;
13 use Gruntmaster
::Page
::Log
;
14 use Gruntmaster
::Page
::Pb
::Entry
;
15 use Gruntmaster
::Page
::Generic
;
21 my $r = Plack
::Request
->new($env);
22 my @handlers = @
{ $handlers{$r->method} // [] };
23 for my $handler (@handlers) {
24 my ($re, $obj) = @
$handler;
26 next unless @args = $r->path =~ m/^$re$/a;
27 my $format = choose
$obj->variants, $r->headers;
28 return $obj->generate($format, $env, map { $_ // '' } @args);
31 if ($r->method eq 'GET' || $r->method eq 'HEAD') {
32 my $article = $r->path eq '/' ?
'/index' : $r->path;
33 $article = substr $article, 1;
35 my @variants = grep { !/\.title$/ } <a
/$article.*>;
37 my $lang = choose
[ map { [$_, 1, 'text/html', undef, undef, $_, undef] } map { /\
.(.+)$/ } @variants ], $r->headers;
38 my $content = read_file
"a/$article.$lang";
39 my $title = read_file
"a/$article.$lang.title";
40 my $html = Gruntmaster
::Page
::Base
::header
($lang, $title) . $content . Gruntmaster
::Page
::Base
::footer
($lang);
41 return [200, ['Content-Type' => 'text/html', 'Content-Language' => $lang, 'Vary' => 'Accept-Language', 'X-Forever' => 1, 'Cache-Control' => 'max-age=300'], [$html] ]
45 [404, ['Content-Type' => 'text/plain'], ['Not found']]
50 eval "require Gruntmaster::Page::$obj" or die $@
;
51 push @
{$handlers{GET
}}, [ $re, "Gruntmaster::Page::$obj" ]
56 eval "require Gruntmaster::Page::$obj" or die $@
;
57 push @
{$handlers{POST
}}, [ $re, "Gruntmaster::Page::$obj" ]
61 my $word = qr
,(\w
+),a
;
62 my $ct = qr
,(?
:\
/ct/$word)?
,a
;
65 my ($thing, $ct, $fs) = @_;
66 $ct //= '', $fs //= '';
67 my $pkg = ucfirst $thing;
68 get qr
,$ct/$thing/, => $pkg;
69 get qr
,$ct/$thing/read, => "${pkg}::Read";
70 get qr
,$ct/$thing/$word$fs, => "${pkg}::Entry";
71 # post qr,$ct/$thing/$word/create, => "${pkg}::Entry::Create";
72 get qr
,$ct/$thing/$word/read, => "${pkg}::Entry::Read";
73 # post qr,$ct/$thing/$word/update, => "${pkg}::Entry::Update";
74 # post qr,$ct/$thing/$word/delete, => "${pkg}::Entry::Delete";
77 get qr
,/css/$word\
.css
, => 'CSS';
78 get qr
,/js\
.js
, => 'JS';
81 generic ct
=> '', '/';
85 get qr
,$ct/log/(\d
+)?
, => 'Log';
86 get qr
,$ct/log/st
, => 'St';
87 get qr
,$ct/log/job
/$word, => 'Log::Entry';
88 get qr
,$ct/log/job
/$word/read, => 'Log::Entry::Read';
89 get qr
,$ct/log/src
/$word\
.$word, => 'Src';
90 post qr
,$ct/pb/$word/submit
, => 'Submit';
92 post qr
,/action/register
, => 'Register';
93 post qr
,/action/passwd
, => 'Passwd';
This page took 0.052901 seconds and 4 git commands to generate.