X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FData.pm;h=ce39b5d2c8fd02d855890e27b238c211b6137ec5;hb=db5da8eaf53881f215970b8030827b5f6d844efa;hp=1b2492cc28c6a07dc927edf30d4039ec9fe1e1eb;hpb=014ee8a614839ded741f61979d979cdd4f20044c;p=gruntmaster-data.git diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 1b2492c..ce39b5d 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -4,20 +4,23 @@ use warnings; use parent qw/Exporter/; use JSON qw/encode_json decode_json/; - use Redis; +use Sub::Name qw/subname/; + +our $VERSION = '5999.000_001'; our $contest; my $redis = Redis->new; my $pubsub = Redis->new; sub dynsub{ + our ($name, $sub) = @_; no strict 'refs'; - *{$_[0]} = $_[1]; + *$name = subname $name => $sub } BEGIN { - for my $cmd (qw/multi exec smembers get hget hdel hset sadd srem incr hmset hsetnx publish del/) { + for my $cmd (qw/multi exec smembers get hget hgetall hdel hset sadd srem incr hmset hsetnx publish del/) { dynsub uc $cmd, sub { $redis->$cmd(@_) }; } @@ -28,9 +31,6 @@ BEGIN { sub cp { defined $contest ? "contest.$contest." : '' } -sub multi () { MULTI } -sub rexec () { EXEC } - sub problems () { SMEMBERS cp . 'problem' } sub contests () { SMEMBERS cp . 'contest' } sub users () { SMEMBERS cp . 'user' } @@ -75,10 +75,10 @@ sub defhash{ }; } -defhash problem => qw/name level statement owner author/; +defhash problem => qw/name level difficulty statement owner author private generator runner judge testcnt timeout olimit/; defhash contest => qw/start end name owner/; defhash job => qw/date errors extension filesize private problem result result_text user/; -defhash user => qw/name email town university level/; +defhash user => qw/name email lastjob town university level/; sub clean_job (_){ HDEL cp . "job.$_[0]", qw/result result_text results daemon/ @@ -99,4 +99,372 @@ our @EXPORT = do { grep { $_ =~ /^[a-zA-Z]/ and exists &$_ } keys %{__PACKAGE__ . '::'}; }; -1 +1; +__END__ + +=encoding utf-8 + +=head1 NAME + +Gruntmaster::Data - Gruntmaster 6000 Online Judge -- database interface and tools + +=head1 SYNOPSIS + + for my $problem (problems) { + say "Problem name: " . problem_name $problem; + say "Problem level: " . problem_level $problem; + ... + } + +=head1 DESCRIPTION + +Gruntmaster::Data is the Redis interface used by the Gruntmaster 6000 Online Judge. It exports many functions for talking to the database. All functions are exported by default. + +The current contest is selected by setting the C<< $Gruntmaster::Data::contest >> variable. + + local $Gruntmaster::Data::contest = 'mycontest'; + say 'There are' . jobcard . ' jobs in my contest'; + +=head1 FUNCTIONS + +=head2 Redis + +Gruntmaster::Data exports some functions for talking directly to the Redis server. These functions should not normally be used, except for B, B, B, B and B. + +These functions correspond to Redis commands. The current list is: B<< MULTI EXEC SMEMBERS GET HGET HDEL HSET SADD SREM INCR HMSET HSETNX DEL PUBLISH SUBSCRIBE WAIT_FOR_MESSAGES >>. + +=head2 Problems + +=over + +=item B + +Returns a list of problems in the current contest. + +=item B I<$problem> + +Returns a problem's meta. + +=item B I<$problem>, I<$meta> + +Sets a problem's meta. + +=item B I<$problem> + +Returns a problem's name. + +=item B I<$problem>, I<$name> + +Sets a problem's name. + +=item B I<$problem> + +Returns a problem's level. The levels are beginner, easy, medium, hard. + +=item B I<$problem>, I<$level> + +Sets a problem's level. The levels are beginner, easy, medium, hard. + +=item B I<$problem> + +Returns a problem's statement. + +=item B I<$problem>, I<$statement> + +Sets a problem's statement. + +=item B I<$problem> + +Returns a problem's owner. + +=item B I<$problem>, I<$owner> + +Sets a problem's owner. + +=item B I<$problem> + +Returns a problem's author. + +=item B I<$problem>, I<$author> + +Sets a problem's author. + +=item B I<$problem>, I<$user> + +Returns the time when I<$user> opened I<$problem>. + +=item B I<$problem>, I<$user> + +Sets the time when I<$user> opened I<$problem> to the current time. Does nothing if I<$user> has already opened I<$problem>. + +=item B I<$id>, I<$key> => I<$value>, ... + +Inserts a problem with id I<$id> and the given initial configuration. Does nothing if a problem with id I<$id> already exists. Returns true if the problem was added, false otherwise. + +=item B I<$id>, I<$key> => I<$value>, ... + +Updates the configuration of a problem. The values of the given keys are updated. All other keys/values are left intact. + +=item B I<$id> + +Removes a problem. + +=back + +=head2 Contests + +B<<< WARNING: these functions only work correctly when C<< $Gruntmaster::Data::contest >> is undef >>> + +=over + +=item B + +Returns a list of contests. + +=item B I<$contest> + +Returns a contest's start time. + +=item B I<$contest>, I<$start> + +Sets a contest's start time. + +=item B I<$contest> + +Returns a contest's end time. + +=item B I<$contest>, I<$end> + +Sets a contest's end time. + +=item B I<$contest> + +Returns a contest's name. + +=item B I<$contest>, I<$name> + +Sets a contest's name. + +=item B I<$contest> + +Returns a contest's owner. + +=item B I<$contest>, I<$owner> + +Sets a contest's owner. + +=item B I<$id>, I<$key> => I<$value>, ... + +Inserts a contest with id I<$id> and the given initial configuration. Does nothing if a contest with id I<$id> already exists. Returns true if the contest was added, false otherwise. + +=item B I<$id>, I<$key> => I<$value>, ... + +Updates the configuration of a contest. The values of the given keys are updated. All other keys/values are left intact. + +=item B I<$id> + +Removes a contest. + +=back + +=head2 Jobs + +=over + +=item B + +Returns the number of jobs in the database. + +=item B I<$job> + +Returns an array of job results. Each element corresponds to a test and is a hashref with keys B (test number), B (result code, see L), B (result description) and B