X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FBase.pm;h=99ca432732cfc9d8a9a27ba21e79752a01d2f726;hb=a46fb222e6ce50102b7c61a95af435afc74f5e33;hp=89f8478e6c62ce5cfa9c01cd7dd542ed0a66e911;hpb=9da2f4958089ae517865b808be61bb12d43b61de;p=gruntmaster-page.git diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index 89f8478..99ca432 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -3,6 +3,7 @@ package Gruntmaster::Page::Base; use 5.014000; use strict; use warnings; +our $VERSION = '5999.000_001'; use File::Slurp qw/read_file/; use HTML::Template::Compiled; @@ -31,26 +32,34 @@ sub footer{ ################################################## use POSIX (); -use Gruntmaster::Data (); use List::Util (); use LWP::UserAgent; +use Plack::Request (); +use feature (); my $ua = LWP::UserAgent->new; my %templates; -sub import { - my $caller = caller; - my ($self, $name, $title) = @_; +use Carp qw/cluck/; + +sub import_to { + my ($self, $caller, $name, $title) = @_; - Gruntmaster::Data->export_to_level(1, $caller); + strict->import; + feature->import(':5.14'); + warnings->import; + File::Slurp->export_to_level(1, $caller, qw/read_file/); List::Util->export_to_level(1, $caller, qw/sum/); no strict 'refs'; + *{"${caller}::ISA"} = [__PACKAGE__]; + *{"${caller}::VERSION"} = $VERSION; *{"${caller}::strftime"} = \&POSIX::strftime; *{"${caller}::debug"} = sub { local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]}) }; + *{"${caller}::db"} = sub { $_[0]->{'gruntmaster.dbic'} }; *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain', 'Cache-Control' => 'no-cache'], [ @_ ] ] }; *{"${caller}::purge"} = sub { return unless $ENV{PURGE_HOST}; @@ -65,23 +74,33 @@ sub import { } } +sub import { + return unless $_[0] eq __PACKAGE__; + splice @_, 1, 0, scalar caller; + goto &import_to +} + ################################################## sub generate{ my ($self, $lang, @args) = @_; - my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$self}{$lang}, default_escape => 'HTML',); + my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$self}{$lang}, default_escape => 'HTML', use_perl => 1); $self->_generate($htc, $lang, @args); my $out = $htc->output; - utf8::downgrade($out); - [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1, 'Cache-Control' => 'max-age=' . $self->max_age], [ $out ] ] + utf8::encode($out); + my $vary = 'Accept-Language, ' . $self->vary; + [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => $vary, 'X-Forever' => 1, 'Cache-Control' => 'max-age=' . $self->max_age], [ $out ] ] } sub _generate {} +sub vary { '' } + sub max_age { 60 } sub variants { + return [] unless exists $templates{$_[0]}; [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $templates{$_[0]} ] }