+sub mangle_request {
+ my $app = $_[0];
+ sub {
+ local *__ANON__ = 'mangle_request_middleware';
+ my $env = $_[0];
+ my ($number, $word) = (qr,(\d+),a, qr,(\w+),a);
+ for ($env->{PATH_INFO}) {
+ $env->{'gruntmaster.page'} = $1 if s,/page/$number$,/,;
+ $env->{'gruntmaster.contest'} = $1 if s,^/ct/$word/,/,;
+ $env->{'gruntmaster.problem'} = $1 if s,^/pb/$word/,/,;
+ $env->{'gruntmaster.user'} = $1 if s,^/us/$word/,/,;
+ $env->{'gruntmaster.page'} //= -1 if m,^/log/$,;
+ }
+ $app->($env);
+ }
+}
+