From 191f4979def520b8be01554eb954c80ee42df38b Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Wed, 5 Feb 2014 16:12:35 +0200 Subject: [PATCH] Pass PSGI env to generators --- lib/Gruntmaster/Page/Base.pm | 2 +- lib/Gruntmaster/Page/CSS.pm | 4 ++-- lib/Gruntmaster/Page/Ct.pm | 4 ++-- lib/Gruntmaster/Page/Ct/Entry.pm | 4 ++-- lib/Gruntmaster/Page/JS.pm | 4 ++-- lib/Gruntmaster/Page/Log.pm | 4 ++-- lib/Gruntmaster/Page/Log/Entry.pm | 4 ++-- lib/Gruntmaster/Page/Pb.pm | 4 ++-- lib/Gruntmaster/Page/Pb/Entry.pm | 4 ++-- lib/Gruntmaster/Page/Src.pm | 4 ++-- lib/Gruntmaster/Page/St.pm | 4 ++-- lib/Gruntmaster/Page/Us.pm | 4 ++-- lib/Gruntmaster/Page/Us/Entry.pm | 4 ++-- lib/Plack/App/Gruntmaster.pm | 2 +- 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index 91c2764..3a58c18 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -27,7 +27,7 @@ sub import { *{"${caller}::TITLE"} = sub () { $title }; *{"${caller}::debug"} = sub { local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; - $_[0]->({qw/level debug message/ => $_[1]}) + $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]}) }; } diff --git a/lib/Gruntmaster/Page/CSS.pm b/lib/Gruntmaster/Page/CSS.pm index a6f647a..25b6137 100644 --- a/lib/Gruntmaster/Page/CSS.pm +++ b/lib/Gruntmaster/Page/CSS.pm @@ -11,8 +11,8 @@ use File::Slurp qw/read_file/; use CSS::Minifier::XS qw/minify/; sub generate{ - my ($self, $format, $logger, $theme) = @_; - debug $logger => "theme is $theme"; + my ($self, $format, $env, $theme) = @_; + debug $env => "theme is $theme"; return [404, ['Content-Type' => 'text/plain'], [ 'Not found' ]] unless -e "css/themes/$theme.css"; my $css = read_file "css/themes/$theme.css"; $css .= read_file $_ for ; diff --git a/lib/Gruntmaster/Page/Ct.pm b/lib/Gruntmaster/Page/Ct.pm index 4aa3254..ede2562 100644 --- a/lib/Gruntmaster/Page/Ct.pm +++ b/lib/Gruntmaster/Page/Ct.pm @@ -54,8 +54,8 @@ HTML }; sub _generate{ - my ($self, $htc, $lang, $logger) = @_; - debug $logger => "language is '$lang'"; + my ($self, $htc, $lang, $env) = @_; + debug $env => "language is '$lang'"; my (@running, @pending, @finished); for (contests) { diff --git a/lib/Gruntmaster/Page/Ct/Entry.pm b/lib/Gruntmaster/Page/Ct/Entry.pm index 97089b5..83e2705 100644 --- a/lib/Gruntmaster/Page/Ct/Entry.pm +++ b/lib/Gruntmaster/Page/Ct/Entry.pm @@ -19,8 +19,8 @@ HTML }; sub _generate{ - my ($self, $htc, $lang, $logger, $id) = @_; - debug $logger => "language is '$lang' and id is '$id'"; + my ($self, $htc, $lang, $env, $id) = @_; + debug $env => "language is '$lang' and id is '$id'"; $htc->param(id => $id); $htc->param(name => contest_name $id); diff --git a/lib/Gruntmaster/Page/JS.pm b/lib/Gruntmaster/Page/JS.pm index 26b1be0..dca5aff 100644 --- a/lib/Gruntmaster/Page/JS.pm +++ b/lib/Gruntmaster/Page/JS.pm @@ -11,8 +11,8 @@ use File::Slurp qw/read_file/; use JavaScript::Minifier::XS qw/minify/; sub generate{ - my ($self, $format, $logger) = @_; - debug $logger => ""; + my ($self, $format, $env) = @_; + debug $env => ""; my $js; $js .= read_file $_ for ; [200, ['Content-Type' => 'application/javascript', 'Cache-Control' => 'public, max-age=604800'], [$js] ] diff --git a/lib/Gruntmaster/Page/Log.pm b/lib/Gruntmaster/Page/Log.pm index 19862a8..4773fec 100644 --- a/lib/Gruntmaster/Page/Log.pm +++ b/lib/Gruntmaster/Page/Log.pm @@ -31,8 +31,8 @@ HTML }; sub _generate{ - my ($self, $htc, $lang, $logger, $ct, $page) = @_; - debug $logger => "language is '$lang', contest is '$ct' and page is '$page'"; + my ($self, $htc, $lang, $env, $ct, $page) = @_; + debug $env => "language is '$lang', contest is '$ct' and page is '$page'"; local $Gruntmaster::Data::contest = $ct if $ct; my $pages = POSIX::floor (jobcard / PAGE_SIZE); diff --git a/lib/Gruntmaster/Page/Log/Entry.pm b/lib/Gruntmaster/Page/Log/Entry.pm index f3e3236..af9e1db 100644 --- a/lib/Gruntmaster/Page/Log/Entry.pm +++ b/lib/Gruntmaster/Page/Log/Entry.pm @@ -24,8 +24,8 @@ HTML }; sub _generate{ - my ($self, $htc, $lang, $logger, $ct, $id) = @_; - debug $logger => "language is '$lang', contest is '$ct' and id is '$id'"; + my ($self, $htc, $lang, $env, $ct, $id) = @_; + debug $env => "language is '$lang', contest is '$ct' and id is '$id'"; local $Gruntmaster::Data::contest = $ct; my @tests = (); diff --git a/lib/Gruntmaster/Page/Pb.pm b/lib/Gruntmaster/Page/Pb.pm index 7a9a0c2..ffdde60 100644 --- a/lib/Gruntmaster/Page/Pb.pm +++ b/lib/Gruntmaster/Page/Pb.pm @@ -39,8 +39,8 @@ HTML }; sub _generate{ - my ($self, $htc, $lang, $logger, $ct) = @_; - debug $logger => "language is '$lang' and contest is '$ct'"; + my ($self, $htc, $lang, $env, $ct) = @_; + debug $env => "language is '$lang' and contest is '$ct'"; local $Gruntmaster::Data::contest = $ct if $ct; my @problems = sort { $b->{name} cmp $a->{name} } map +{ diff --git a/lib/Gruntmaster/Page/Pb/Entry.pm b/lib/Gruntmaster/Page/Pb/Entry.pm index 78560fd..4eacd4e 100644 --- a/lib/Gruntmaster/Page/Pb/Entry.pm +++ b/lib/Gruntmaster/Page/Pb/Entry.pm @@ -40,8 +40,8 @@ HTML }; sub _generate{ - my ($self, $htc, $lang, $logger, $contest, $id) = @_; - debug $logger => "language is '$lang', contest is '$contest', id is '$id'"; + my ($self, $htc, $lang, $env, $contest, $id) = @_; + debug $env => "language is '$lang', contest is '$contest', id is '$id'"; $htc->param(cansubmit => 1); if ($contest) { diff --git a/lib/Gruntmaster/Page/Src.pm b/lib/Gruntmaster/Page/Src.pm index 77a5cd2..b7b9433 100644 --- a/lib/Gruntmaster/Page/Src.pm +++ b/lib/Gruntmaster/Page/Src.pm @@ -18,8 +18,8 @@ use constant CONTENT_TYPES => +{ }; sub generate{ - my ($self, $format, $logger, $ct, $job, $ext) = @_; - debug $logger => "Contest is $ct, job is $job and extension is $ext"; + my ($self, $format, $env, $ct, $job, $ext) = @_; + debug $env => "Contest is $ct, job is $job and extension is $ext"; local $Gruntmaster::Data::contest = $ct if $ct; [200, ['Content-Type' => CONTENT_TYPES->{$ext}, 'Cache-Control' => 'max-age=604800'], [job_inmeta($job)->{files}{prog}{content}] ] diff --git a/lib/Gruntmaster/Page/St.pm b/lib/Gruntmaster/Page/St.pm index 97d0d06..5803183 100644 --- a/lib/Gruntmaster/Page/St.pm +++ b/lib/Gruntmaster/Page/St.pm @@ -45,8 +45,8 @@ sub calc_score{ } sub _generate{ - my ($self, $htc, $lang, $logger, $ct) = @_; - debug $logger => "language is '$lang' and contest is '$ct'"; + my ($self, $htc, $lang, $env, $ct) = @_; + debug $env => "language is '$lang' and contest is '$ct'"; my ($totaltime, $start); local $Gruntmaster::Data::contest; diff --git a/lib/Gruntmaster/Page/Us.pm b/lib/Gruntmaster/Page/Us.pm index 0ca1e29..b4dcb3f 100644 --- a/lib/Gruntmaster/Page/Us.pm +++ b/lib/Gruntmaster/Page/Us.pm @@ -15,8 +15,8 @@ HTML }; sub _generate{ - my ($self, $htc, $lang, $logger) = @_; - debug $logger => "language is '$lang'"; + my ($self, $htc, $lang, $env) = @_; + debug $env => "language is '$lang'"; $htc->param(users => [ sort { lc $a->{name} cmp lc $b->{name} } map { {id => $_, name => user_name} } diff --git a/lib/Gruntmaster/Page/Us/Entry.pm b/lib/Gruntmaster/Page/Us/Entry.pm index 373193d..e375ab8 100644 --- a/lib/Gruntmaster/Page/Us/Entry.pm +++ b/lib/Gruntmaster/Page/Us/Entry.pm @@ -17,8 +17,8 @@ HTML }; sub _generate{ - my ($self, $htc, $lang, $logger, $us) = @_; - debug $logger => "language is '$lang', user is '$us'"; + my ($self, $htc, $lang, $env, $us) = @_; + debug $env => "language is '$lang', user is '$us'"; local $_ = $us; $htc->param(name => user_name); diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 5343268..2334235 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -22,7 +22,7 @@ sub call { my @args; next unless @args = $r->path =~ m/^$re$/a; my $format = choose $obj->variants, $r->headers; - return $obj->generate($format, $env->{'psgix.logger'}, map { $_ // '' } @args); + return $obj->generate($format, $env, map { $_ // '' } @args); } if ($r->method eq 'GET' || $r->method eq 'HEAD') { -- 2.39.2