]> iEval git - plack-app-gruntmaster.git/blame_incremental - lib/Gruntmaster/Page/Submit.pm
Make Gruntmaster::Page::Base::variants not need overriding
[plack-app-gruntmaster.git] / lib / Gruntmaster / Page / Submit.pm
... / ...
CommitLineData
1package Gruntmaster::Page::Submit;
2
3use 5.014000;
4use strict;
5use warnings;
6use Gruntmaster::Page::Base;
7our @ISA = qw/Gruntmaster::Page::Base/;
8our $VERSION = '0.001';
9
10use Apache2::Authen::Passphrase qw/pwcheck pwset USER_REGEX/;
11use File::Slurp qw/read_file/;
12use Plack::Request;
13
14use constant FORMAT_EXTENSION => {
15 C => 'c',
16 CPP => 'cpp',
17 MONO => 'cs',
18 JAVA => 'java',
19 PASCAL => 'pas',
20 PERL => 'pl',
21 PYTHON => 'py',
22};
23
24sub generate{
25 my ($self, $frm, $env) = @_;
26 my $r = Plack::Request->new($env);
27 my ($problem, $format, $contest, $private, $prog) = map {scalar $r->param($_)} 'problem', 'prog_format', 'contest', 'private', 'source_code';
28 my $upload = $r->upload('prog');
29 if (defined $upload) {
30 my $temp = read_file $upload->path;
31 $prog = $temp if $temp
32 }
33 die if defined $contest && $contest !~ /^\w+$/ ;
34 die if defined $contest && (time > contest_end $contest);
35 return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog;
36
37 local $Gruntmaster::Data::contest = $contest if $contest;
38
39 my $job = push_job (
40 date => time,
41 problem => $problem,
42 user => $r->user,
43 defined $private ? (private => $private) : (),
44 defined $contest ? (contest => $contest, private => 1) : (),
45 filesize => length $prog,
46 extension => FORMAT_EXTENSION->{$format},
47 );
48
49 set_job_inmeta $job, {
50 files => {
51 prog => {
52 format => $format,
53 name => 'prog.' . FORMAT_EXTENSION->{$format},
54 content => $prog,
55 }
56 }
57 };
58
59 $contest //= '';
60 PUBLISH 'jobs', "$contest.$job";
61 [303, [Location => $r->path =~ s,/pb/\w+/submit$,/log/,r], ['']]
62}
63
641
This page took 0.021158 seconds and 4 git commands to generate.