1 package Gruntmaster
::Page
::Generic
;
6 our $VERSION = '0.001';
9 use Gruntmaster
::Page
::Base
;
10 use JSON qw
/encode_json decode_json/;
14 my $cp = $Gruntmaster::Data
::contest ?
"contest.$Gruntmaster::Data::contest." : '';
15 map { { id
=> $_, HGETALL
"$cp$hash.$_" } } SMEMBERS
"$cp$hash"
19 my ($key, $value) = @_;
25 my ($pkg, $id, $title) = @_;
26 my $fn = $pkg =~ s
,::,/,gr
;
27 return if $INC{"$fn.pm"};
29 Gruntmaster
::Page
::Base
->import_to($pkg, $id, $title);
36 my ($self, $htc, $lang, $env, $ct) = @_;
37 undef $ct unless $thing{contest
};
38 debug
$env => "Contest is $ct";
39 local $Gruntmaster::Data
::contest
= $ct if $ct;
40 my @thing = hgetall
$thing{hash
};
41 @thing = map { $thing{mangle
}->(); $_ } @thing if exists $thing{mangle
};
42 @thing = grep { $thing{choose
}->() } @thing if exists $thing{choose
};
43 @thing = sort { $thing{sortby
}->() } @thing if exists $thing{sortby
};
45 $thing{group
} //= sub { $thing{id
} };
47 my $group = $thing{group
}->();
48 $params{$group} //= [];
49 push $params{$group}, $_
55 sub make_entry_generate
{
58 my ($self, $htc, $lang, $env, $id, $ct) = @_;
59 ($id, $ct) = ($ct, $id) if $thing{contest
};
60 local $Gruntmaster::Data
::contest
= $ct if $ct;
61 debug
$env => "Hash is $thing{hash} and id is $id";
62 my %params = HGETALL
"$thing{hash}.$id";
63 $thing{mangle
}->(local $_ = \
%params) if exists $thing{mangle
};
64 %params = (%params, $thing{hook
}->(local $_ = \
%params)) if exists $thing{hook
};
71 my $ucid = ucfirst $thing{id
};
72 my $pkg = "Gruntmaster::Page::$ucid";
74 putsym
"${pkg}::_generate", make_generate
%thing if makepkg
$pkg, @thing{qw
/id title/};
75 putsym
"${pkg}::Entry::_generate", make_entry_generate
%thing if makepkg
"${pkg}::Entry", "$thing{id}_entry", '<tmpl_var name>';
89 local *{"params"} = sub { @thing{qw
/id hash title/} = @_ };
90 local *{"choose"} = sub { $thing{choose
} = shift };
91 local *{"sortby"} = sub { $thing{sortby
} = shift };
92 local *{"mangle"} = sub { $thing{mangle
} = shift };
93 local *{"group"} = sub { $thing{group
} = shift };
94 local *{"contest"} = sub { $thing{contest
} = 1 };
95 local *{"hook"} = sub { $thing{hook
} = shift };
102 ##################################################
105 params qw
/us user Users/;
106 choose
{ $_->{name
} =~ /\w/ };
107 sortby
{ lc $a->{name
} cmp lc $b->{name
} };
111 params qw
/pb problem Problems/;
113 sortby
{ $a->{name
} cmp $b->{name
} };
114 group
{ $_->{level
} };
118 params qw
/ct contest Contests/;
120 $_->{start
} = strftime
'%c', localtime $_->{start
};
121 $_->{end
} = strftime
'%c', localtime $_->{end
};
123 sortby
{ $a->{start
} <=> $b->{start
} };
124 group
{ time < $_->{start
} ?
'pending' : time > $_->{end
} ?
'finished' : 'running' };
125 hook
{ started
=> time >= $_->{start
} };
129 params qw
/log job/, 'Job log';
132 $_->{results
} &&= decode_json
$_->{results
};
133 $_->{time} = sprintf "%.4fs", $_->{time} for values ($_->{results
} // [])
This page took 0.029447 seconds and 4 git commands to generate.