Make Gruntmaster::Page::Base also act as strict/warnings/feature/etc
[gruntmaster-page.git] / lib / Gruntmaster / Page / Submit.pm
CommitLineData
42546e6c
MG
1package Gruntmaster::Page::Submit;
2
8d29b3b1 3use Gruntmaster::Page::Base;
42546e6c 4
8d29b3b1
MG
5use constant FORMAT_EXTENSION => {
6 C => 'c',
7 CPP => 'cpp',
8 MONO => 'cs',
9 JAVA => 'java',
10 PASCAL => 'pas',
11 PERL => 'pl',
12 PYTHON => 'py',
13};
42546e6c 14
8d29b3b1
MG
15sub generate{
16 my ($self, $frm, $env) = @_;
17 my $r = Plack::Request->new($env);
18 my ($problem, $format, $contest, $private, $prog) = map {scalar $r->param($_)} 'problem', 'prog_format', 'contest', 'private', 'source_code';
19 my $upload = $r->upload('prog');
20 if (defined $upload) {
95a9ad1b 21 my $temp = read_file $upload->path;
8d29b3b1
MG
22 $prog = $temp if $temp
23 }
24 die if defined $contest && $contest !~ /^\w+$/ ;
25 die if defined $contest && (time > contest_end $contest);
26 return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog;
42546e6c 27
3c53f795 28 local $Gruntmaster::Data::contest = $contest if $contest;
42546e6c 29
8d29b3b1
MG
30 my $job = push_job (
31 date => time,
32 problem => $problem,
33 user => $r->user,
34 defined $private ? (private => $private) : (),
35 defined $contest ? (contest => $contest, private => 1) : (),
36 filesize => length $prog,
37 extension => FORMAT_EXTENSION->{$format},
38 );
42546e6c 39
8d29b3b1
MG
40 set_job_inmeta $job, {
41 files => {
42 prog => {
43 format => $format,
44 name => 'prog.' . FORMAT_EXTENSION->{$format},
45 content => $prog,
46 }
47 }
48 };
2b0036ac 49
8d29b3b1
MG
50 $contest //= '';
51 PUBLISH 'jobs', "$contest.$job";
52 [303, [Location => $r->path =~ s,/pb/\w+/submit$,/log/,r], ['']]
42546e6c
MG
53}
54
551
This page took 0.017978 seconds and 4 git commands to generate.