our $VERSION = '0.001';
use constant FORMATS => [qw/CPP/];
-use constant TITLE => 'Submit job';
-use Fcntl qw/:flock/;
use HTML::Template::Compiled;
-use IO::File;
-use YAML::Any qw/LoadFile/;
-use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
+use Gruntmaster::Data qw/problem_name problems/;
-my %templates = (
- en => <<'HTML',
+my %orig_templates = (
+ en => <<'HTML',
<form action="https://gm.ieval.ro/action/submit" method="POST" enctype="multipart/form-data">
<label>Problem:<br>
<select name="problem" required>
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, submit => 'Submit job';
sub generate{
- my $template = $templates{$_[1]};
- my $htc = HTML::Template::Compiled->new(scalarref => \$template);
- IO::File->new('>meta.yml')->close unless -f 'meta.yml';
- flock my $metafh = IO::File->new('<meta.yml'), LOCK_SH;
- my @problems = map {
- my $meta = LoadFile $_;
- my $id = (m,^pb/(.*)/meta.yml$,)[0];
- +{ id => $id, name => $meta->{name} } } <pb/*/meta.yml>;
- $htc->param(problems => \@problems);
- $htc->param(formats => FORMATS);
- $htc->output
+ %templates = cook_templates %orig_templates, submit => 'Submit job' if reload_templates;
+
+ 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