Make all generators inherit from a common base
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 18 Jan 2014 12:20:38 +0000 (14:20 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 18 Jan 2014 12:27:13 +0000 (14:27 +0200)
17 files changed:
lib/Gruntmaster/Data.pm
lib/Gruntmaster/Page.pm
lib/Gruntmaster/Page/Account.pm
lib/Gruntmaster/Page/Base.pm [new file with mode: 0644]
lib/Gruntmaster/Page/Common.pm [deleted file]
lib/Gruntmaster/Page/Ct.pm
lib/Gruntmaster/Page/Ct/Entry.pm
lib/Gruntmaster/Page/Index.pm
lib/Gruntmaster/Page/Learn.pm
lib/Gruntmaster/Page/Log.pm
lib/Gruntmaster/Page/Log/Entry.pm
lib/Gruntmaster/Page/Pb.pm
lib/Gruntmaster/Page/Pb/Entry.pm
lib/Gruntmaster/Page/St.pm
lib/Gruntmaster/Page/Submit.pm
lib/Gruntmaster/Page/Us.pm
lib/Gruntmaster/Page/Us/Entry.pm

index 94eb507d8b0d59db7b67298bdbfb9e2180230b3e..3855c08e7c181f3d392cede14c5e2510a498c2bd 100644 (file)
@@ -78,7 +78,7 @@ sub clean_job (_){
        HDEL cp . "job.$_[0]", qw/result result_text results daemon/
 }
 
-our @EXPORT_OK = do {
+our @EXPORT = do {
        no strict 'refs';
        grep { $_ =~ /^[a-zA-Z]/ and exists &$_ } keys %{__PACKAGE__ . '::'};
 };
index d90d57c71a2aa3b5fd9603f4ce19f9d15063afdd..c7f92bbf5a599c8ba57625a7d0012b7e937d71c2 100644 (file)
@@ -27,8 +27,7 @@ sub declaregen{
        my ($generator, $regex) = @_;
        $generator = "Gruntmaster::Page::$generator";
        eval "require $generator";
-       my $gensub = $generator->can('generate') or die "No such generator: $generator";
-       push @generators, [$regex,  $gensub];
+       push @generators, [$regex,  $generator];
 }
 
 {
@@ -63,7 +62,7 @@ sub _generate{
                my ($regex, $generator) = @$gen;
                next unless $path_noext =~ $regex;
                for my $lang (@{LANGUAGES()}) {
-                       my $page = $generator->($path, $lang);
+                       my $page = $generator->generate($path, $lang);
                        write_file "$path_noext.$lang.$ext.new", $page;
                        say $typemap "URI: $basename.$lang.$ext\nContent-Language: $lang\nContent-Type: " . CONTENT_TYPES->{$ext} . "\n";
                        gzip \$page => "$path_noext.$lang.gz.$ext.new", Minimal => 1;
index 20acc6ab30e6731f6f0786acd3d18edb8915426c..be27aff59ecd3d702c127ab55faea8f13c695893 100644 (file)
@@ -3,15 +3,12 @@ package Gruntmaster::Page::Account;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base account => 'Account';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use HTML::Template::Compiled;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-
-my %orig_templates = (
-  en => <<'HTML',
+use constant TEMPLATES => {
+       en => <<'HTML',
 <div id="result"></div>
 
 <h1>Register</h1>
@@ -44,13 +41,6 @@ Confirm new password:<br>
 <input type="submit" value="Change password">
 </form>
 HTML
-);
-
-my %templates = cook_templates %orig_templates, account => 'Account';
-
-sub generate{
-  %templates = cook_templates %orig_templates, account => 'Account' if reload_templates;
-  HTML::Template::Compiled->new(scalarref => \$templates{$_[1]})->output
-}
+};
 
 1
diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm
new file mode 100644 (file)
index 0000000..7fa1497
--- /dev/null
@@ -0,0 +1,115 @@
+package Gruntmaster::Page::Base;
+
+use 5.014000;
+use strict;
+use warnings;
+
+use File::Slurp qw/read_file/;
+use HTML::Template::Compiled;
+
+##################################################
+
+use POSIX ();
+use Gruntmaster::Data ();
+use List::Util ();
+
+sub import {
+       my $caller = caller;
+       my ($self, $name, $title) = @_;
+
+       Gruntmaster::Data->export_to_level(1, $caller);
+       List::Util->export_to_level(1, $caller, qw/sum/);
+
+       no strict 'refs';
+       *{"${caller}::strftime"} = \&POSIX::strftime;
+       *{"${caller}::NAME"} = sub () { $name };
+       *{"${caller}::TITLE"} = sub () { $title };
+}
+
+##################################################
+
+my %orig_header_templates = (
+  en => <<'HTML',
+<!DOCTYPE html>
+<title>TITLE_GOES_HERE</title>
+<link rel="stylesheet" href="/gm.css">
+<script src="/zepto.var" defer></script>
+<script src="/view.js" defer></script>
+<script src="/form.js" defer></script>
+<meta charset="utf-8">
+
+<span id="admin"></span>
+<div id="title"><span class="i">i</span><span class="Eval">Eval</span></div>
+<div id="subtitle">TITLE_GOES_HERE</div>
+
+<nav><ul><li><a href="/learn.var">Learn</a><li><a href="/pb/">Practice</a><li><a href="/ct/">Compete</a><li><a href="/log/">Job log</a></ul></nav>
+
+HTML
+);
+
+my %orig_footer_templates = (
+  en => <<'HTML',
+
+<footer>
+Dilmom: Why don't you call your product the Gruntmaster 6000?
+Dilbert: What kind of product do you see when you imagine a Gruntmaster 6000?
+Dilmom: Well, it's a stripped-down version of the Gruntmaster 9000, of course. But it's software-upgradeable.
+</footer>
+HTML
+);
+
+sub patch_templates {
+       my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT} or return;
+       my ($templates, $name) = @_;
+       my %out = %$templates;
+       for (<$root/$name*>) {
+               m/\.(.+)$/;
+               $out{$1} = read_file $_
+       }
+
+       %out
+}
+
+sub reload_templates (){ $ENV{GRUNTMASTER_RELOAD_TEMPLATES} }
+
+my %header_templates = patch_templates \%orig_header_templates, 'header';
+my %footer_templates = patch_templates \%orig_footer_templates, 'footer';
+
+sub header{
+  my ($language, $title) = @_;
+  %header_templates = patch_templates \%orig_header_templates, 'header' if reload_templates;
+  $header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger;
+}
+
+sub footer{
+  %footer_templates = patch_templates \%orig_footer_templates, 'footer' if reload_templates;
+  $footer_templates{$_[0]};
+}
+
+sub cook_templates {
+       my ($templates, $name, $title) = @_;
+
+       my %out = patch_templates $templates, $name;
+       $out{$_}  = header ($_, $title) . $out{$_} for keys %out;
+       $out{$_} .= footer  $_  for keys %out;
+
+       %out
+}
+
+##################################################
+
+my %templates;
+
+sub generate{
+       my ($self, $path, $lang) = @_;
+
+       $templates{$self} = { cook_templates $self->TEMPLATES, $self->NAME => $self->TITLE } if !exists $templates{$self} or reload_templates;
+
+       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$self}{$lang}, default_escape => 'HTML',);
+       $self->_generate($htc, $path, $lang);
+       $htc->output
+}
+
+sub _generate {}
+
+1
diff --git a/lib/Gruntmaster/Page/Common.pm b/lib/Gruntmaster/Page/Common.pm
deleted file mode 100644 (file)
index 37cdf71..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-package Gruntmaster::Page::Common;
-
-use 5.014000;
-use strict;
-use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/header footer cook_templates reload_templates/;
-
-use File::Slurp qw/read_file/;
-
-my %orig_header_templates = (
-  en => <<'HTML',
-<!DOCTYPE html>
-<title>TITLE_GOES_HERE</title>
-<link rel="stylesheet" href="/gm.css">
-<script src="/zepto.var" defer></script>
-<script src="/view.js" defer></script>
-<script src="/form.js" defer></script>
-<meta charset="utf-8">
-
-<span id="admin"></span>
-<div id="title"><span class="i">i</span><span class="Eval">Eval</span></div>
-<div id="subtitle">TITLE_GOES_HERE</div>
-
-<nav><ul><li><a href="/learn.var">Learn</a><li><a href="/pb/">Practice</a><li><a href="/ct/">Compete</a><li><a href="/log/">Job log</a></ul></nav>
-
-HTML
-);
-
-my %orig_footer_templates = (
-  en => <<'HTML',
-
-<footer>
-Dilmom: Why don't you call your product the Gruntmaster 6000?
-Dilbert: What kind of product do you see when you imagine a Gruntmaster 6000?
-Dilmom: Well, it's a stripped-down version of the Gruntmaster 9000, of course. But it's software-upgradeable.
-</footer>
-HTML
-);
-
-sub patch_templates {
-       my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT} or return;
-       my ($templates, $name) = @_;
-       my %out = %$templates;
-       for (<$root/$name*>) {
-               m/\.(.+)$/;
-               $out{$1} = read_file $_
-       }
-
-       %out
-}
-
-my %header_templates = patch_templates \%orig_header_templates, 'header';
-my %footer_templates = patch_templates \%orig_footer_templates, 'footer';
-
-sub reload_templates () { $ENV{GRUNTMASTER_RELOAD_TEMPLATES} }
-
-sub header{
-  my ($language, $title) = @_;
-  %header_templates = patch_templates \%orig_header_templates, 'header' if reload_templates;
-  $header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger;
-}
-
-sub footer{
-  %footer_templates = patch_templates \%orig_footer_templates, 'footer' if reload_templates;
-  $footer_templates{$_[0]};
-}
-
-sub cook_templates (\%@) {
-       my ($templates, $name, $title) = @_;
-
-       my %out = patch_templates $templates, $name;
-       $out{$_}  = header ($_, $title) . $out{$_} for keys %out;
-       $out{$_} .= footer  $_  for keys %out;
-
-       %out
-}
-
-1;
index 1c108fddf5162f534ede875c41128c6e89c3d69d..f5c6c1f0d2cc9ed6ee53f83137f3b6bb1a5314c4 100644 (file)
@@ -3,16 +3,11 @@ package Gruntmaster::Page::Ct;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base ct => 'Contests';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use HTML::Template::Compiled;
-use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-use Gruntmaster::Data qw/contests contest_name contest_start contest_end contest_owner/;
-
-my %orig_templates = (
+use constant TEMPLATES => {
        en => <<'HTML',
 <tmpl_if running>
 <h1>Running contests</h1>
@@ -56,13 +51,10 @@ my %orig_templates = (
 </table>
 </tmpl_if>
 HTML
-);
-
-my %templates = cook_templates %orig_templates, ct => 'Contests';
+};
 
-sub generate{
-       %templates = cook_templates %orig_templates, ct => 'Contests' if reload_templates;
-       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
        my (@running, @pending, @finished);
        for (contests) {
@@ -81,7 +73,6 @@ sub generate{
        $htc->param(running => \@running);
        $htc->param(pending => \@pending);
        $htc->param(finished => \@finished);
-       $htc->output
 }
 
 1
index bba2991c6e8a13d5fbeebbd473cbd440cb2806a4..6266661e39c288d4112c2a5c475ec87224968857 100644 (file)
@@ -3,16 +3,11 @@ package Gruntmaster::Page::Ct::Entry;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base ct_entry => '<tmpl_var name>';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use HTML::Template::Compiled;
-use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-use Gruntmaster::Data qw/contest_name contest_start contest_end/;
-
-my %orig_templates = (
+use constant TEMPLATES => {
        en => <<'HTML',
 Contest start time: <tmpl_var start><br>
 Contest end time: <tmpl_var end><p>
@@ -21,23 +16,18 @@ Contest end time: <tmpl_var end><p>
 <a href="log/">Job log</a><br>
 <a href="log/st.var">Standings</a></tmpl_if>
 HTML
-);
+};
 
-my %templates = cook_templates %orig_templates, ct_entry => '<tmpl_var name>';
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
-sub generate{
-       %templates = cook_templates %orig_templates, ct_entry => '<tmpl_var name>' if reload_templates;
-       my ($path, $lang) = @_;
        $path = ($path =~ m,ct/(.*)/index,)[0];
-       my $template = $templates{$lang};
-       my $htc = HTML::Template::Compiled->new(scalarref => \$template);
 
        $htc->param(id => $path);
        $htc->param(name => contest_name $path);
        $htc->param(start => strftime '%c', contest_start);
        $htc->param(end => strftime '%c', contest_end);
        $htc->param(started => time >= contest_start);
-       $htc->output
 }
 
 1
index 0214ea6b5c906de88d294e36270f0f131d05dc07..a413e6a9cba5e42a46b98aaeba36519a84bff2e9 100644 (file)
@@ -3,23 +3,13 @@ package Gruntmaster::Page::Index;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base index => 'Gruntmaster 6000';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use HTML::Template::Compiled;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-
-my %orig_templates = (
-  en => <<'HTML',
+use constant TEMPLATES => {
+       en => <<'HTML',
 HTML
-);
-
-my %templates = cook_templates %orig_templates, index => 'Gruntmaster 6000';
-
-sub generate{
-  %templates = cook_templates %orig_templates, index => 'Gruntmaster 6000' if reload_templates;
-  HTML::Template::Compiled->new(scalarref => \$templates{$_[1]})->output
-}
+};
 
 1
index 171a184ae5eeb6e211784239d3833fc5f88eb72d..95c61821e028f26f49a9ddc034aa4f8690b5597f 100644 (file)
@@ -3,25 +3,15 @@ package Gruntmaster::Page::Learn;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base learn => 'Learn';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use HTML::Template::Compiled;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-
-my %orig_templates = (
-  en => <<'HTML',
+use constant TEMPLATES => {
+       en => <<'HTML',
 Install interactive-perl-tutorial from your nearest CPAN mirror. Run <code>cpan App::InteractivePerlTutorial</code>.
 <p>You can also get the source from <a href="http://git.ieval.ro/?p=app-interactiveperltutorial.git">git.ieval.ro</a>
 HTML
-);
-
-my %templates = cook_templates %orig_templates, learn => 'Learn';
-
-sub generate{
-  %templates = cook_templates %orig_templates, learn => 'Learn' if reload_templates;
-  HTML::Template::Compiled->new(scalarref => \$templates{$_[1]})->output;
-}
+};
 
 1
index 47c8a2e9288770b3df5d7062831aca3e3d1abe72..fce36cbe8fe1a4f5d91b3082c528a9cb18060bcb 100644 (file)
@@ -3,8 +3,8 @@ package Gruntmaster::Page::Log;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base log => 'Job log';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
 use constant PAGE_SIZE => 10;
@@ -13,12 +13,7 @@ use constant FORMAT_EXTENSION => {
   CPP => 'cpp',
 };
 
-use HTML::Template::Compiled;
-use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-use Gruntmaster::Data qw/jobcard job_date job_extension job_filesize problem_name job_private job_problem job_result job_result_text job_user/;
-
-my %orig_templates = (
+use constant TEMPLATES => {
        en => <<'HTML',
 <table border>
 <thead>
@@ -32,18 +27,16 @@ my %orig_templates = (
 </tmpl_loop>
 </table>
 HTML
-);
+};
 
-my %templates = cook_templates %orig_templates, log => 'Job log';
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
-sub generate{
-       %templates = cook_templates %orig_templates, log => 'Job log' if reload_templates;
-       $_[0] =~ m,^(?:ct/([^/]+)/)?log/(\w+)\.html$,;
+       $path =~ m,^(?:ct/([^/]+)/)?log/(\w+)\.html$,;
        local $Gruntmaster::Data::contest = $1;
        my $pages = jobcard / PAGE_SIZE;
        my $page = $2 eq 'index' ? $pages : $2;
 
-       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
        my @log = sort { $b->{id} <=> $a->{id} } map +{
                id => $_,
                (job_private() ? (private => job_private) : ()),
@@ -56,7 +49,6 @@ sub generate{
                size => sprintf ("%.2f KiB", job_filesize() / 1024),
                user => job_user}, ($page - 1) * PAGE_SIZE + 1 .. $page == $pages ? jobcard : $page * PAGE_SIZE;
        $htc->param(log => \@log);
-       $htc->output
 }
 
 1
index 8fed9a19fb6aa3b28730a900c07d088ef511eb19..e20c891307960a6fc5c1fd71679ef370c04134fc 100644 (file)
@@ -3,16 +3,11 @@ package Gruntmaster::Page::Log::Entry;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base log_entry => 'Job <tmpl_var id>';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use HTML::Template::Compiled;
-use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-use Gruntmaster::Data qw/job_results/;
-
-my %orig_templates = (
+use constant TEMPLATES => {
        en => <<'HTML',
 <table border>
 <thead>
@@ -22,18 +17,15 @@ my %orig_templates = (
 </tmpl_loop>
 </table>
 HTML
-);
+};
 
-my %templates = cook_templates %orig_templates, log_entry => 'Job <tmpl_var id>';
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
-sub generate{
-       %templates = cook_templates %orig_templates, log_entry => 'Job <tmpl_var id>' if reload_templates;
-       $_[0] =~ m,^(?:ct/([^/]+)/)?log/job/([^/]+)\.html$,;
+       $path =~ m,^(?:ct/([^/]+)/)?log/job/([^/]+)\.html$,;
        local $Gruntmaster::Data::contest = $1;
        my $id = $2;
 
-       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
-
        my @tests = map {
                $_->{time} = sprintf "%.4fs", $_->{time};
                $_
@@ -41,7 +33,6 @@ sub generate{
 
        $htc->param(id => $id);
        $htc->param(tests => \@tests);
-       $htc->output
 }
 
 1
index 18b47bf894710cb8449ba68910592c7a1a266004..8e4a40886e26d329c6a113d84e97ed209ecd6f19 100644 (file)
@@ -3,19 +3,12 @@ package Gruntmaster::Page::Pb;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base pb => 'Problems';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use Fcntl qw/:flock/;
-use HTML::Template::Compiled;
-use IO::File;
-use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-use Gruntmaster::Data qw/problem_name problem_level problems/;
-
-my %orig_templates = (
-  en => <<'HTML',
+use constant TEMPLATES => {
+       en => <<'HTML',
 <tmpl_if levels>
 <h2>Beginner</h2>
 <ul>
@@ -43,26 +36,24 @@ my %orig_templates = (
 </tmpl_loop></ul>
 </tmpl_if>
 HTML
-);
+};
 
-my %templates = cook_templates %orig_templates, pb => 'Problems';
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
-sub generate{
-       %templates = cook_templates %orig_templates, pb => 'Problems' if reload_templates;
-       $_[0] =~ m,^(?:ct/([^/]+)/)?pb/index.html$,;
+       $path =~ m,^(?:ct/([^/]+)/)?pb/index.html$,;
        local $Gruntmaster::Data::contest = $1;
 
-       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
        my @problems = sort { $b->{name} cmp $a->{name} } map +{
                id    => $_,
                name  => problem_name,
                level => problem_level}, problems;
+
        for my $d (qw/beginner easy medium advanced hard/) {
                $htc->param($d => [grep {$_->{level} and $_->{level} eq $d} @problems]);
        }
        $htc->param(levels => grep { $_->{level} } @problems);
        $htc->param(problems => \@problems);
-       $htc->output
 }
 
 1
index dbfbe18ca42b86c6c2f0b7fd3a6b21de6518b503..5232592789670503d3c85b54e15e394b7250087f 100644 (file)
@@ -3,18 +3,13 @@ package Gruntmaster::Page::Pb::Entry;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base pb_entry => '<tmpl_var name>';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use HTML::Template::Compiled;
-use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-use Gruntmaster::Data qw/contest_start contest_end problem_name problem_statement/;
-
 use constant FORMATS => [qw/CPP/];
 
-my %orig_templates = (
+use constant TEMPLATES => {
        en => <<'HTML',
 <tmpl_var statement>
 
@@ -33,16 +28,14 @@ my %orig_templates = (
 </form>
 </tmpl_if>
 HTML
-);
+};
 
-my %templates = cook_templates %orig_templates, pb_entry => '<tmpl_var name>';
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
-sub generate{
-       %templates = cook_templates %orig_templates, pb_entry => '<tmpl_var name>' if reload_templates;
-       $_[0] =~ m,(?:ct/([^/])+/)?pb/(\w+)\.html$,;
+       $path =~ m,(?:ct/([^/])+/)?pb/(\w+)\.html$,;
 
        my ($contest, $id) = ($1, $2);
-       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
 
        $htc->param(cansubmit => 1);
        if (defined $contest) {
@@ -54,7 +47,6 @@ sub generate{
        local $Gruntmaster::Data::contest = $contest if $contest;
        $htc->param(name => problem_name $id);
        $htc->param(statement => problem_statement $id);
-       $htc->output
 }
 
 1
index e3873ba51b418de037516ca24a52b7470f898757..dafd5df249e21b1604441d1ba0033e12b4a3080c 100644 (file)
@@ -3,17 +3,11 @@ package Gruntmaster::Page::St;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base st => 'Standings';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use HTML::Template::Compiled;
-use List::Util qw/sum/;
-use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-use Gruntmaster::Data qw/problems jobcard job_result_text job_result job_problem job_user/;
-
-my %orig_templates = (
+use constant => TEMPLATES => {
        en => <<'HTML',
 <table border>
 <thead>
@@ -25,14 +19,12 @@ my %orig_templates = (
 </tmpl_loop>
 </table>
 HTML
-);
+};
 
-my %templates = cook_templates %orig_templates, st => 'Standings';
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
-sub generate{
-       %templates = cook_templates %orig_templates, st => 'Standings' if reload_templates;
-       local $Gruntmaster::Data::contest = ($_[0] =~ m,^ct/([^/]+)/,)[0];
-       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
+       local $Gruntmaster::Data::contest = ($path =~ m,^ct/([^/]+)/,)[0];
 
        my @problems = sort problems;
        my %scores;
@@ -54,7 +46,6 @@ sub generate{
        } keys %scores;
        $htc->param(problems => \@problems);
        $htc->param(st => \@st);
-       $htc->output
 }
 
 1
index 7e4d1634d27ca6ef328cc530b4e095db02c4a976..cdb4f7d5fc396b6547ef7a71c4925ad7b5ff54c4 100644 (file)
@@ -3,17 +3,13 @@ package Gruntmaster::Page::Submit;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base submit => 'Submit job';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
 use constant FORMATS => [qw/CPP/];
 
-use HTML::Template::Compiled;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-use Gruntmaster::Data qw/problem_name problems/;
-
-my %orig_templates = (
+use constant TEMPLATES => {
        en => <<'HTML',
 <form action="https://gm.ieval.ro/action/submit" method="POST" enctype="multipart/form-data">
 <label>Problem:<br>
@@ -31,18 +27,14 @@ my %orig_templates = (
 
 <input type="submit" value="Submit job">
 HTML
-);
-
-my %templates = cook_templates %orig_templates, submit => 'Submit job';
+};
 
-sub generate{
-       %templates = cook_templates %orig_templates, submit => 'Submit job' if reload_templates;
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
-       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
        my @problems = map +{ id => $_, name => problem_name }, problems;
        $htc->param(problems => \@problems);
        $htc->param(formats => FORMATS);
-       $htc->output
 }
 
 1
index 2c87916aa7075f99ec4c4596f1edd9861ef457ac..2095fd55aaf0963b1511b60bdaa0b394d4712b26 100644 (file)
@@ -3,29 +3,21 @@ package Gruntmaster::Page::Us;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base us => 'Users';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use HTML::Template::Compiled;
-use Gruntmaster::Data qw/users user_name/;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-
-my %orig_templates = (
+use constant TEMPLATES => {
        en => <<'HTML',
 <ul><tmpl_loop users><li><a href="<tmpl_var id>.var"><tmpl_var name></a>
 </tmpl_loop></ul>
 HTML
-);
-
-my %templates = cook_templates %orig_templates, us => 'Users';
+};
 
-sub generate{
-       %templates = cook_templates %orig_templates, us => 'Users' if reload_templates;
-       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
        $htc->param(users => [ map { {id => $_, name => user_name} } users ]);
-       $htc->output;
 }
 
 1
index 5d493ba9fb02518ba51e1e1831f2821eb9ac1c96..cfd9b36bfb22d9c2f0924041e38c65dfd021eb05 100644 (file)
@@ -3,36 +3,29 @@ package Gruntmaster::Page::Us::Entry;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base us_entry => '<tmpl_var name>';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use HTML::Template::Compiled;
-use Gruntmaster::Data qw/users user_name user_town user_university user_level/;
-use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-
-my %orig_templates = (
+use constant TEMPLATES => {
        en => <<'HTML',
 <h1><tmpl_var name></h1>
 Town: <tmpl_var town><br>
 University: <tmpl_var university><br>
 Level: <tmpl_var level>
 HTML
-);
+};
 
-my %templates = cook_templates %orig_templates, us_entry => '<tmpl_var name>';
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
-sub generate{
-       %templates = cook_templates %orig_templates, us_entry => '<tmpl_var name>' if reload_templates;
-       $_[0] =~ m,^us/([^/]+)\.html$,;
+       $path =~ m,^us/([^/]+)\.html$,;
        local $_ = $1;
-       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
 
        $htc->param(name => user_name);
        $htc->param(town => user_town);
        $htc->param(university => user_university);
        $htc->param(level => user_level);
-       $htc->output;
 }
 
 1
This page took 0.031957 seconds and 4 git commands to generate.