]>
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
::Generic
;
19 my $r = Plack
::Request
->new($env);
20 my @handlers = @
{ $handlers{$r->method} // [] };
21 for my $handler (@handlers) {
22 my ($re, $obj) = @
$handler;
24 next unless @args = $r->path =~ m/^$re$/a;
25 my $format = choose
$obj->variants, $r->headers;
26 return $obj->generate($format, $env, map { $_ // '' } @args);
29 if ($r->method eq 'GET' || $r->method eq 'HEAD') {
30 my $article = $r->path eq '/' ?
'/index' : $r->path;
31 $article = substr $article, 1;
33 my @variants = grep { !/\.title$/ } <a
/$article.*>;
35 my $lang = choose
[ map { [$_, 1, 'text/html', undef, undef, $_, undef] } map { /\
.(.+)$/ } @variants ], $r->headers;
36 my $content = read_file
"a/$article.$lang";
37 my $title = read_file
"a/$article.$lang.title";
38 my $html = Gruntmaster
::Page
::Base
::header
($lang, $title) . $content . Gruntmaster
::Page
::Base
::footer
($lang);
39 return [200, ['Content-Type' => 'text/html', 'Content-Language' => $lang, 'Vary' => 'Accept-Language', 'X-Forever' => 1, 'Cache-Control' => 'max-age=300'], [$html] ]
43 [404, ['Content-Type' => 'text/plain'], ['Not found']]
48 eval "require Gruntmaster::Page::$obj" or die $@
;
49 push @
{$handlers{GET
}}, [ $re, "Gruntmaster::Page::$obj" ]
54 eval "require Gruntmaster::Page::$obj" or die $@
;
55 push @
{$handlers{POST
}}, [ $re, "Gruntmaster::Page::$obj" ]
59 my $word = qr
,(\w
+),a
;
60 my $number = qr
,(\d
+),a
;
64 my $pkg = ucfirst $thing;
65 get qr
,/$thing/, => $pkg;
66 get qr
,/$thing/read, => "${pkg}::Read";
67 get qr
,/$thing/$word, => "${pkg}::Entry";
68 # post qr,/$thing/$word/create, => "${pkg}::Entry::Create";
69 get qr
,/$thing/$word/read, => "${pkg}::Entry::Read";
70 # post qr,/$thing/$word/update, => "${pkg}::Entry::Update";
71 # post qr,/$thing/$word/delete, => "${pkg}::Entry::Delete";
75 get qr
,/css/$word\
.css
, => 'CSS';
76 get qr
,/js\
.js
, => 'JS';
78 get qr
,/log/st
, => 'St';
79 generic qw
/us ct pb log/;
81 get qr
,/log/src
/$number\
.$word, => 'Src';
82 post qr
,/submit
, => 'Submit';
84 post qr
,/action/register
, => 'Register';
85 post qr
,/action/passwd
, => 'Passwd';
This page took 0.054738 seconds and 4 git commands to generate.