From: Marius Gavrilescu Date: Tue, 14 Jan 2014 09:09:17 +0000 (+0200) Subject: Fix some small bugs X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=3da9c3c228106c819530a0b8e4c646981e6f71c9;p=plack-app-gruntmaster.git Fix some small bugs --- diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index f9162af..544a6d0 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -16,8 +16,8 @@ sub dynsub{ } BEGIN { - for my $cmd (qw/multi exec smembers get hget hset sadd incr hmset/) { - dynsub uc $cmd, sub { say $cmd;exit;$redis->$cmd(@_) }; + for my $cmd (qw/multi exec smembers get hget hset sadd srem incr hmset hsetnx/) { + dynsub uc $cmd, sub { say "Arguments to \U$cmd: ", join ', ', @_; $redis->$cmd(@_) }; } } @@ -28,12 +28,16 @@ sub rexec () { EXEC } sub problems () { SMEMBERS cp . 'problem' } sub contests () { SMEMBERS cp . 'contest' } -sub jobcard () { GET cp . 'job' } +sub jobcard () { GET cp . 'job' } -sub job_results (_) { decode_json HGET cp . "job.$_[0]", 'results' } -sub set_job_results ($+) { HSET cp . "job.$_[0]", 'results', encode_json $_[1] } -sub problem_meta (_) { decode_json HGET cp . "pb.$_[0]", 'meta' } -sub set_problem_meta ($+) { HSET cp . "pb.$_[0]", 'meta', encode_json $_[1] } +sub job_results (_) { decode_json HGET cp . "job.$_[0]", 'results' } +sub set_job_results ($+) { HSET cp . "job.$_[0]", 'results', encode_json $_[1] } +sub job_inmeta (_) { decode_json HGET cp . "job.$_[0]", 'inmeta' } +sub set_job_inmeta ($+) { HSET cp . "job.$_[0]", 'inmeta', encode_json $_[1] } +sub problem_meta (_) { decode_json HGET cp . "problem.$_[0]", 'meta' } +sub set_problem_meta ($+) { HSET cp . "problem.$_[0]", 'meta', encode_json $_[1] } +sub job_daemon (_) { HGET cp . "job.$_[0]", 'daemon' } +sub set_job_daemon ($$) { HSETNX cp . "job.$_[0]", 'daemon', $_[1] }; sub defhash{ my ($name, @keys) = @_; @@ -47,6 +51,11 @@ sub defhash{ SADD cp . $name, $key or return; HMSET cp . "$name.$key", %values; }; + dynsub "remove_$name", sub (_) { + my $key = shift; + SREM cp . $name, $key; + }; + dynsub "push_$name", sub { my $nr = INCR cp . $name; HMSET cp . "$name.$nr", @_; @@ -59,7 +68,7 @@ defhash job => qw/date file name private problem result result_text user/; our @EXPORT_OK = do { no strict 'refs'; - grep { $_ =~ /^[a-z]/ and exists &$_ } keys %{__PACKAGE__ . '::'}; + grep { $_ =~ /^[a-zA-Z]/ and exists &$_ } keys %{__PACKAGE__ . '::'}; }; 1 diff --git a/lib/Gruntmaster/Page.pm b/lib/Gruntmaster/Page.pm index 6ca62dd..5a6ed68 100644 --- a/lib/Gruntmaster/Page.pm +++ b/lib/Gruntmaster/Page.pm @@ -41,7 +41,7 @@ sub declaregen{ declaregen 'Log::Entry' => qr,^${contest}log/$component/index$,; declaregen Submit => qr,^${contest}submit$,; declaregen Pb => qr,^${contest}pb/index$,; - declaregen 'Pb::Entry' => qr,^${contest}pb/$component/index$,; + declaregen 'Pb::Entry' => qr,^${contest}pb/$component$,; } sub generate{ @@ -63,6 +63,7 @@ sub generate{ gzip \$page => "$path_noext.$lang.gz.$ext.new", Minimal => 1; say $typemap "URI: $basename.$lang.gz.$ext\nContent-Language: $lang\nContent-Encoding: gzip\nContent-Type: " . CONTENT_TYPES->{$ext} . "\n"; } + last } for my $lang (@{LANGUAGES()}) { diff --git a/lib/Gruntmaster/Page/Log.pm b/lib/Gruntmaster/Page/Log.pm index a86b153..5a2b4c6 100644 --- a/lib/Gruntmaster/Page/Log.pm +++ b/lib/Gruntmaster/Page/Log.pm @@ -10,10 +10,14 @@ our $VERSION = '0.001'; use constant TITLE => 'Job log'; use constant PAGE_SIZE => 10; +use constant FORMAT_EXTENSION => { + CPP => 'cpp', +}; + use HTML::Template::Compiled; use POSIX qw/strftime/; use Gruntmaster::Page::Common qw/header footer/; -use Gruntmaster::Data qw/job_date job_file job_name job_private job_problem job_result job_result_text job_user/; +use Gruntmaster::Data qw/job_date job_file problem_name job_private job_problem job_result job_result_text job_user/; my %templates = ( en => <<'HTML', @@ -22,9 +26,9 @@ my %templates = ( IDProblemDateSizeUserResult - + - + data-private> @@ -44,7 +48,7 @@ sub generate{ id => $_, (job_private() ? (private => job_private) : ()), date => (job_date() ? strftime ('%c' => localtime job_date) : '?'), - name => job_name, + name => problem_name job_problem, problem => job_problem, result => job_result, result_text => job_result_text, diff --git a/lib/Gruntmaster/Page/Pb.pm b/lib/Gruntmaster/Page/Pb.pm index 170f03f..5ada0e2 100644 --- a/lib/Gruntmaster/Page/Pb.pm +++ b/lib/Gruntmaster/Page/Pb.pm @@ -21,27 +21,27 @@ my %templates = (

Beginner

Easy

Medium

Hard

    -
  • +
HTML diff --git a/lib/Gruntmaster/Page/Pb/Entry.pm b/lib/Gruntmaster/Page/Pb/Entry.pm index ebcf56e..c9dfe20 100644 --- a/lib/Gruntmaster/Page/Pb/Entry.pm +++ b/lib/Gruntmaster/Page/Pb/Entry.pm @@ -43,7 +43,7 @@ $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; $templates{$_} .= footer $_ for keys %templates; sub generate{ - $_[0] =~ m,(?:ct/([^/])+/)?log/(\w+)\.html$,; + $_[0] =~ m,(?:ct/([^/])+/)?pb/(\w+)\.html$,; my ($contest, $id) = ($1, $2); my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]}); @@ -55,9 +55,9 @@ sub generate{ } $htc->param(formats => FORMATS); $htc->param(id => $id); - local $Gruntmaster::Data::contest = ($_[0] =~ m,(?:ct/([^/])+/)?,)[0]; + local $Gruntmaster::Data::contest = $contest if $contest; $htc->param(name => problem_name $id); - $htc->param(statement => problem_statement $id, $_[2]); + $htc->param(statement => problem_statement $id); $htc->output }