]>
iEval git - plack-app-gruntmaster.git/blob - Page.pm
eedbec54e17d2e865b8ec4cfe6ddc96224d2ed03
1 package Gruntmaster
::Page
;
8 use File
::Basename qw
/fileparse/;
9 use File
::Path qw
/make_path/;
10 use File
::Slurp qw
/write_file/;
11 use IO
::Compress
::Gzip qw
/gzip/;
13 use Gruntmaster
::Data
;
15 our $VERSION = '0.001';
18 use constant LANGUAGES
=> [ 'en' ];
19 use constant CONTENT_TYPES
=> {
20 html
=> 'text/html; charset=UTF-8',
21 txt
=> 'text/plain; charset=UTF-8',
25 my ($generator, $regex) = @_;
26 $generator = "Gruntmaster::Page::$generator";
27 eval "require $generator";
28 push @generators, [$regex, $generator];
32 my $component = qr
'[^/]+';
33 my $contest = qr
,(?
:ct
/$component/)?
,;
34 declaregen Index
=> qr
,^index$,;
35 declaregen Learn
=> qr
,^learn
$,;
36 declaregen Account
=> qr
,^account
$,;
37 declaregen Us
=> qr
,^us
/index$,;
38 declaregen
'Us::Entry' => qr
,^us
/$component$,;
39 declaregen Ct
=> qr
,^ct
/index$,;
40 declaregen
'Ct::Entry' => qr
,^ct
/$component/index
$,;
41 declaregen St
=> qr
,^ct
/$component/log/st
$,;
42 declaregen Log
=> qr
,^${contest
}log/(?
:\d
+|index)$,;
43 declaregen
'Log::Entry' => qr
,^${contest
}log/job/$component$,;
44 declaregen Submit
=> qr
,^${contest
}submit
$,;
45 declaregen Pb
=> qr
,^${contest
}pb
/index$,;
46 declaregen
'Pb::Entry' => qr
,^${contest
}pb
/$component$,;
51 my ($path_noext, $ext) = $path =~ m/^(.*)\.(.*)$/;
52 my ($basename, $directories) = fileparse
$path_noext;
53 make_path
$directories;
55 IO
::File
->new(">$path_noext.var")->close unless -f
"$path_noext.var";
56 flock my $lockfh = IO
::File
->new("<$path_noext.var"), LOCK_EX
;
57 open my $typemap, ">$path_noext.var.new";
58 say $typemap "URI: $basename\n";
59 for my $gen (@generators) {
60 my ($regex, $generator) = @
$gen;
61 next unless $path_noext =~ $regex;
62 for my $lang (@
{LANGUAGES
()}) {
63 my $page = $generator->generate($path, $lang);
64 write_file
"$path_noext.$lang.$ext.new", $page;
65 say $typemap "URI: $basename.$lang.$ext\nContent-Language: $lang\nContent-Type: " . CONTENT_TYPES
->{$ext} . "\n";
66 gzip \
$page => "$path_noext.$lang.gz.$ext.new", Minimal
=> 1;
67 say $typemap "URI: $basename.$lang.gz.$ext\nContent-Language: $lang\nContent-Encoding: gzip\nContent-Type: " . CONTENT_TYPES
->{$ext} . "\n";
72 for my $lang (@
{LANGUAGES
()}) {
73 rename "$path_noext.$lang.$ext.new", "$path_noext.$lang.$ext";
74 rename "$path_noext.$lang.gz.$ext.new", "$path_noext.$lang.gz.$ext";
76 rename "$path_noext.var.new", "$path_noext.var";
82 my $ext = job_extension
$job;
84 write_file
"log/src/$job.$ext", job_inmeta
($job)->{files
}{prog
}{content
};
93 # Below is stub documentation for your module. You'd better edit it!
97 Gruntmaster::Page - Perl extension for blah blah blah
101 use Gruntmaster::Page;
106 Stub documentation for Gruntmaster::Page, created by h2xs. It looks like the
107 author of the extension was negligent enough to leave the stub
120 Mention other useful documentation such as the documentation of
121 related modules or operating system documentation (such as man pages
122 in UNIX), or any relevant external documentation such as RFCs or
125 If you have a mailing list set up for your module, mention it here.
127 If you have a web site set up for your module, mention it here.
131 Marius Gavrilescu, E<lt>marius@E<gt>
133 =head1 COPYRIGHT AND LICENSE
135 Copyright (C) 2013 by Marius Gavrilescu
137 This library is free software; you can redistribute it and/or modify
138 it under the same terms as Perl itself, either Perl version 5.18.1 or,
139 at your option, any later version of Perl 5 you may have available.
This page took 0.054521 seconds and 3 git commands to generate.