]>
iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page.pm
12e732958878d9fd6a7fc855b97194ec7b5816e0
1 package Gruntmaster
::Page
;
6 use parent qw
/Exporter/;
7 our @EXPORT_OK = qw
/generate/;
9 use File
::Basename qw
/fileparse/;
10 use File
::Slurp qw
/write_file/;
11 use IO
::Compress
::Gzip qw
/gzip/;
13 our $VERSION = '0.001';
16 use constant LANGUAGES
=> [ 'en' ];
17 use constant CONTENT_TYPES
=> {
18 html
=> 'text/html; charset=UTF-8',
19 txt
=> 'text/plain; charset=UTF-8',
23 my ($generator, $regex) = @_;
24 $generator = "Gruntmaster::Page::$generator";
25 eval "require $generator";
26 my $gensub = $generator->can('generate') or die "No such generator: $generator";
27 push @generators, [$regex, $gensub];
31 my $component = qr
'[^/]+';
32 my $contest = qr
,(?
:ct
/$component/)?
,;
33 declaregen Index
=> qr
,^index$,;
34 declaregen Ct
=> qr
,^ct
/index$,;
35 declaregen
'Ct::Entry' => qr
,^ct
/$component/index
$,;
36 #declaregen St => qr,^ct/$component/st/index$,;
37 declaregen Log
=> qr
,^${contest
}log/index$,;
38 declaregen
'Log::Entry' => qr
,^${contest
}log/$component/index
$,;
39 declaregen Submit
=> qr
,^${contest
}submit
$,;
40 declaregen Pb
=> qr
,^${contest
}pb
/index$,;
41 declaregen
'Pb::Entry' => qr
,^${contest
}pb
/$component/index
$,;
46 my ($path_noext, $ext) = $path =~ m/^(.*)\.(.*)$/;
47 my $basename = fileparse
$path_noext;
49 open my $typemap, ">$path_noext.var";
50 say $typemap "URI: $basename\n";
51 for my $gen(@generators) {
52 my ($regex, $generator) = @
$gen;
53 next unless $path_noext =~ $regex;
54 for my $lang (@
{LANGUAGES
()}) {
55 my $page = $generator->($path, $lang);
56 write_file
"$path_noext.$lang.$ext", $page;
57 say $typemap "URI: $basename.$lang.$ext\nContent-Language: $lang\nContent-Type: " . CONTENT_TYPES
->{$ext} . "\n";
58 gzip \
$page => "$path_noext.$lang.gz.$ext", Minimal
=> 1;
59 say $typemap "URI: $basename.$lang.gz.$ext\nContent-Language: $lang\nContent-Encoding: gzip\nContent-Type: " . CONTENT_TYPES
->{$ext} . "\n";
67 # Below is stub documentation for your module. You'd better edit it!
71 Gruntmaster::Page - Perl extension for blah blah blah
75 use Gruntmaster::Page;
80 Stub documentation for Gruntmaster::Page, created by h2xs. It looks like the
81 author of the extension was negligent enough to leave the stub
94 Mention other useful documentation such as the documentation of
95 related modules or operating system documentation (such as man pages
96 in UNIX), or any relevant external documentation such as RFCs or
99 If you have a mailing list set up for your module, mention it here.
101 If you have a web site set up for your module, mention it here.
105 Marius Gavrilescu, E<lt>marius@E<gt>
107 =head1 COPYRIGHT AND LICENSE
109 Copyright (C) 2013 by Marius Gavrilescu
111 This library is free software; you can redistribute it and/or modify
112 it under the same terms as Perl itself, either Perl version 5.18.1 or,
113 at your option, any later version of Perl 5 you may have available.
This page took 0.056224 seconds and 3 git commands to generate.