| 1 | use utf8; |
| 2 | package Gruntmaster::Data; |
| 3 | |
| 4 | # Created by DBIx::Class::Schema::Loader |
| 5 | # DO NOT MODIFY THE FIRST PART OF THIS FILE |
| 6 | |
| 7 | use strict; |
| 8 | use warnings; |
| 9 | |
| 10 | use base 'DBIx::Class::Schema'; |
| 11 | |
| 12 | __PACKAGE__->load_namespaces; |
| 13 | |
| 14 | |
| 15 | # Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-05 13:11:39 |
| 16 | # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dAEmtAexvUaNXLgYz2rNEg |
| 17 | |
| 18 | our $VERSION = '5999.000_004'; |
| 19 | |
| 20 | use Lingua::EN::Inflect qw/PL_N/; |
| 21 | use Sub::Name qw/subname/; |
| 22 | |
| 23 | sub dynsub{ |
| 24 | our ($name, $sub) = @_; |
| 25 | no strict 'refs'; |
| 26 | *$name = subname $name => $sub |
| 27 | } |
| 28 | |
| 29 | BEGIN { |
| 30 | for my $rs (qw/contest contest_problem job open problem user/) { |
| 31 | my $rsname = ucfirst $rs; |
| 32 | $rsname =~ s/_([a-z])/\u$1/g; |
| 33 | dynsub PL_N($rs) => sub { $_[0]->resultset($rsname) }; |
| 34 | dynsub $rs => sub { $_[0]->resultset($rsname)->find($_[1]) }; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | 1; |
| 39 | |
| 40 | __END__ |
| 41 | |
| 42 | =encoding utf-8 |
| 43 | |
| 44 | =head1 NAME |
| 45 | |
| 46 | Gruntmaster::Data - Gruntmaster 6000 Online Judge -- database interface and tools |
| 47 | |
| 48 | =head1 SYNOPSIS |
| 49 | |
| 50 | my $db = Gruntmaster::Data->connect('dbi:Pg:'); |
| 51 | |
| 52 | my $problem = $db->problem('my_problem'); |
| 53 | $problem->update({timeout => 2.5}); # Set time limit to 2.5 seconds |
| 54 | $problem->rerun; # And rerun all jobs for this problem |
| 55 | |
| 56 | # ... |
| 57 | |
| 58 | my $contest = $db->contests->create({ # Create a new contest |
| 59 | id => 'my_contest', |
| 60 | name => 'My Awesome Contest', |
| 61 | start => time + 100, |
| 62 | end => time + 1900, |
| 63 | }); |
| 64 | $db->contest_problems->create({ # Add a problem to the contest |
| 65 | contest => 'my_contest', |
| 66 | problem => 'my_problem', |
| 67 | }); |
| 68 | |
| 69 | say 'The contest has not started yet' if $contest->is_pending; |
| 70 | |
| 71 | # ... |
| 72 | |
| 73 | my @jobs = $db->jobs->search({contest => 'my_contest', owner => 'MGV'})->all; |
| 74 | $_->rerun for @jobs; # Rerun all jobs sent by MGV in my_contest |
| 75 | |
| 76 | =head1 DESCRIPTION |
| 77 | |
| 78 | Gruntmaster::Data is the interface to the Gruntmaster 6000 database. Read the L<DBIx::Class> documentation for usage information. |
| 79 | |
| 80 | In addition to the typical DBIx::Class::Schema methods, this module contains several convenience methods: |
| 81 | |
| 82 | =over |
| 83 | |
| 84 | =item contests |
| 85 | |
| 86 | Equivalent to C<< $schema->resultset('Contest') >> |
| 87 | |
| 88 | =item contest_problems |
| 89 | |
| 90 | Equivalent to C<< $schema->resultset('ContestProblem') >> |
| 91 | |
| 92 | =item jobs |
| 93 | |
| 94 | Equivalent to C<< $schema->resultset('Job') >> |
| 95 | |
| 96 | =item problems |
| 97 | |
| 98 | Equivalent to C<< $schema->resultset('Problem') >> |
| 99 | |
| 100 | =item users |
| 101 | |
| 102 | Equivalent to C<< $schema->resultset('User') >> |
| 103 | |
| 104 | =item contest($id) |
| 105 | |
| 106 | Equivalent to C<< $schema->resultset('Contest')->find($id) >> |
| 107 | |
| 108 | =item job($id) |
| 109 | |
| 110 | Equivalent to C<< $schema->resultset('Job')->find($id) >> |
| 111 | |
| 112 | =item problem($id) |
| 113 | |
| 114 | Equivalent to C<< $schema->resultset('Problem')->find($id) >> |
| 115 | |
| 116 | =item user($id) |
| 117 | |
| 118 | Equivalent to C<< $schema->resultset('User')->find($id) >> |
| 119 | |
| 120 | =back |
| 121 | |
| 122 | =head1 AUTHOR |
| 123 | |
| 124 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> |
| 125 | |
| 126 | =head1 COPYRIGHT AND LICENSE |
| 127 | |
| 128 | Copyright (C) 2014 by Marius Gavrilescu |
| 129 | |
| 130 | This library is free software; you can redistribute it and/or modify |
| 131 | it under the same terms as Perl itself, either Perl version 5.18.1 or, |
| 132 | at your option, any later version of Perl 5 you may have available. |
| 133 | |
| 134 | |
| 135 | =cut |