37e793105b1de231c1b04ce024e01baebb833318
1 package Gruntmaster
::Page
::Generic
;
8 use Gruntmaster
::Page
::Base
;
9 use JSON qw
/decode_json/;
10 our @ISA = qw
/Gruntmaster::Page::Base/;
11 our $VERSION = '0.001';
15 my $cp = $Gruntmaster::Data
::contest ?
"contest.$Gruntmaster::Data::contest." : '';
16 map { { id
=> $_, HGETALL
"$cp$hash.$_" } } SMEMBERS
"$cp$hash"
20 my ($key, $value) = @_;
26 my ($pkg, $id, $title) = @_;
27 my $fn = $pkg =~ s
,::,/,gr
;
28 return if $INC{"$fn.pm"};
30 Gruntmaster
::Page
::Base
->import_to($pkg, $id, $title);
31 putsym
"${pkg}::ISA", ['Gruntmaster::Page::Base'];
37 my ($self, $htc, $lang, $env, $ct) = @_;
38 undef $ct unless $thing{contest
};
39 debug
$env => "Contest is $ct";
40 local $Gruntmaster::Data
::contest
= $ct if $ct;
41 my @thing = hgetall
$thing{hash
};
42 @thing = map { $thing{mangle
}->(); $_ } @thing if exists $thing{mangle
};
43 @thing = grep { $thing{choose
}->() } @thing if exists $thing{choose
};
44 @thing = sort { $thing{sortby
}->() } @thing if exists $thing{sortby
};
46 $thing{group
} //= sub { $thing{id
} };
48 my $group = $thing{group
}->();
49 $params{$group} //= [];
50 push $params{$group}, $_
56 sub make_entry_generate
{
59 my ($self, $htc, $lang, $env, $id, $ct) = @_;
60 ($id, $ct) = ($ct, $id) if $thing{contest
};
61 local $Gruntmaster::Data
::contest
= $ct if $ct;
62 debug
$env => "Hash is $thing{hash} and id is $id";
63 my %params = HGETALL
"$thing{hash}.$id";
64 $thing{mangle
}->(local $_ = \
%params) if exists $thing{mangle
};
65 %params = (%params, $thing{hook
}->(local $_ = \
%params)) if exists $thing{hook
};
72 my $ucid = ucfirst $thing{id
};
73 my $pkg = "Gruntmaster::Page::$ucid";
75 putsym
"${pkg}::_generate", make_generate
%thing if makepkg
$pkg, @thing{qw
/id title/};
76 putsym
"${pkg}::Entry::_generate", make_entry_generate
%thing if makepkg
"${pkg}::Entry", "$thing{id}_entry", '<tmpl_var name>';
90 local *{"params"} = sub { @thing{qw
/id hash title/} = @_ };
91 local *{"choose"} = sub { $thing{choose
} = shift };
92 local *{"sortby"} = sub { $thing{sortby
} = shift };
93 local *{"mangle"} = sub { $thing{mangle
} = shift };
94 local *{"group"} = sub { $thing{group
} = shift };
95 local *{"contest"} = sub { $thing{contest
} = 1 };
96 local *{"hook"} = sub { $thing{hook
} = shift };
103 ##################################################
106 params qw
/us user Users/;
107 choose
{ $_->{name
} =~ /\w/ };
108 sortby
{ lc $a->{name
} cmp lc $b->{name
} };
112 params qw
/pb problem Problems/;
114 sortby
{ $a->{name
} cmp $b->{name
} };
115 group
{ $_->{level
} };
119 params qw
/ct contest Contests/;
121 $_->{start
} = strftime
'%c', localtime $_->{start
};
122 $_->{end
} = strftime
'%c', localtime $_->{end
};
124 sortby
{ $a->{start
} <=> $b->{start
} };
125 group
{ time < $_->{start
} ?
'pending' : time > $_->{end
} ?
'finished' : 'running' };
126 hook
{ started
=> time >= $_->{start
} };
130 params qw
/log job/, 'Job log';
133 $_->{results
} &&= decode_json
$_->{results
};
134 $_->{time} = sprintf "%.4fs", $_->{time} for values ($_->{results
} // [])
This page took 0.03191 seconds and 3 git commands to generate.