]>
iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/Base.pm
1 package Gruntmaster
::Page
::Base
;
7 use File
::Slurp qw
/read_file/;
8 use HTML
::Template
::Compiled
;
10 ##################################################
16 map { m/\.(.+)$/; $1 => scalar read_file
$_ } <tmpl
/$name.*>;
19 my %header_templates = read_templates
'header';
20 my %footer_templates = read_templates
'footer';
23 my ($language, $title) = @_;
24 $header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger;
28 $footer_templates{$_[0]};
31 ##################################################
34 use Gruntmaster
::Data
();
38 my $ua = LWP
::UserAgent
->new;
44 my ($self, $caller, $name, $title) = @_;
46 Gruntmaster
::Data
->export_to_level(1, $caller);
47 List
::Util
->export_to_level(1, $caller, qw
/sum/);
50 *{"${caller}::strftime"} = \
&POSIX
::strftime
;
51 *{"${caller}::debug"} = sub {
52 local $Log::Log4perl
::caller_depth
= $Log::Log4perl
::caller_depth
+ 1;
53 $_[0]->{'psgix.logger'}->({qw
/level debug message/ => $_[1]})
55 *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain', 'Cache-Control' => 'no-cache'], [ @_ ] ] };
56 *{"${caller}::purge"} = sub {
57 return unless $ENV{PURGE_HOST
};
58 my $req = HTTP
::Request
->new(PURGE
=> "http://$ENV{PURGE_HOST}$_[0]");
63 $templates{$caller} = { read_templates
$name };
64 $templates{$caller}{$_} = header
($_, $title) . $templates{$caller}{$_} for keys $templates{$caller};
65 $templates{$caller}{$_} .= footer
$_ for keys $templates{$caller};
70 return unless $_[0] eq __PACKAGE__
;
71 splice @_, 1, 0, scalar caller;
75 ##################################################
78 my ($self, $lang, @args) = @_;
80 my $htc = HTML
::Template
::Compiled
->new(scalarref
=> \
$templates{$self}{$lang}, default_escape
=> 'HTML',);
81 $self->_generate($htc, $lang, @args);
82 my $out = $htc->output;
83 utf8
::downgrade
($out);
84 my $vary = 'Accept-Language, ' . $self->vary;
85 [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => $vary, 'X-Forever' => 1, 'Cache-Control' => 'max-age=' . $self->max_age], [ $out ] ]
95 [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $templates{$_[0]} ]
This page took 0.068525 seconds and 5 git commands to generate.