]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Submit.pm
Move header / footer to a separate module and update MANIFEST
[gruntmaster-page.git] / lib / Gruntmaster / Page / Submit.pm
CommitLineData
42546e6c
MG
1package Gruntmaster::Page::Submit;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7our @EXPORT_OK = qw/generate/;
8our $VERSION = '0.001';
9
10use constant FORMATS => [qw/CPP/];
11use constant TITLE => 'Submit job';
12
13use Fcntl qw/:flock/;
14use HTML::Template::Compiled;
15use IO::File;
16use YAML::Any qw/LoadFile/;
832cb45e 17use Gruntmaster::Page::Common qw/header footer/;
42546e6c
MG
18
19my %templates = (
20 en => <<'HTML',
21<form action="https://gm.ieval.ro/action/submit" method="POST" enctype="multipart/form-data">
22<label>Problem:<br>
23<select name="problem" required>
24<tmpl_loop problems><option value="<tmpl_var id>"><tmpl_var name></option>
25</tmpl_loop></select></label><p>
26
27<label>File:<br>
28<input name="prog" required type="file"></label><p>
29
30<label>File format:<br>
31<select name="prog_format" required>
32<tmpl_loop formats><option value="<tmpl_var _>"><tmpl_var _></option>
33</tmpl_loop></select></label><p>
34
35<input type="submit" value="Submit job">
36HTML
37);
38
39$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
40$templates{$_} .= footer $_ for keys %templates;
41
42sub generate{
43 my $template = $templates{$_[1]};
44 my $htc = HTML::Template::Compiled->new(scalarref => \$template);
45 IO::File->new('>meta.yml')->close unless -f 'meta.yml';
46 flock my $metafh = IO::File->new('<meta.yml'), LOCK_SH;
47 my @problems = map {
48 my $meta = LoadFile $_;
49 my $id = (m,^pb/(.*)/meta.yml$,)[0];
50 +{ id => $id, name => $meta->{name} } } <pb/*/meta.yml>;
51 $htc->param(problems => \@problems);
52 $htc->param(formats => FORMATS);
53 $htc->output
54}
55
561
This page took 0.022116 seconds and 4 git commands to generate.