]>
iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/Base.pm
1 package Gruntmaster
::Page
::Base
;
6 our $VERSION = '0.001';
8 use File
::Slurp qw
/read_file/;
9 use HTML
::Template
::Compiled
;
11 ##################################################
17 map { m/\.(.+)$/; $1 => scalar read_file
$_ } <tmpl
/$name.*>;
20 my %header_templates = read_templates
'header';
21 my %footer_templates = read_templates
'footer';
24 my ($language, $title) = @_;
25 $header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger;
29 $footer_templates{$_[0]};
32 ##################################################
35 use Gruntmaster
::Data
();
38 use Plack
::Request
();
41 my $ua = LWP
::UserAgent
->new;
47 my ($self, $caller, $name, $title) = @_;
50 feature
->import(':5.14');
52 File
::Slurp
->export_to_level(1, $caller, qw
/read_file/);
53 Gruntmaster
::Data
->export_to_level(1, $caller);
54 List
::Util
->export_to_level(1, $caller, qw
/sum/);
57 *{"${caller}::ISA"} = [__PACKAGE__
];
58 *{"${caller}::VERSION"} = $VERSION;
59 *{"${caller}::strftime"} = \
&POSIX
::strftime
;
60 *{"${caller}::debug"} = sub {
61 local $Log::Log4perl
::caller_depth
= $Log::Log4perl
::caller_depth
+ 1;
62 $_[0]->{'psgix.logger'}->({qw
/level debug message/ => $_[1]})
64 *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain', 'Cache-Control' => 'no-cache'], [ @_ ] ] };
65 *{"${caller}::purge"} = sub {
66 return unless $ENV{PURGE_HOST
};
67 my $req = HTTP
::Request
->new(PURGE
=> "http://$ENV{PURGE_HOST}$_[0]");
72 $templates{$caller} = { read_templates
$name };
73 $templates{$caller}{$_} = header
($_, $title) . $templates{$caller}{$_} for keys $templates{$caller};
74 $templates{$caller}{$_} .= footer
$_ for keys $templates{$caller};
79 return unless $_[0] eq __PACKAGE__
;
80 splice @_, 1, 0, scalar caller;
84 ##################################################
87 my ($self, $lang, @args) = @_;
89 my $htc = HTML
::Template
::Compiled
->new(scalarref
=> \
$templates{$self}{$lang}, default_escape
=> 'HTML', use_perl
=> 1);
90 $self->_generate($htc, $lang, @args);
91 my $out = $htc->output;
92 utf8
::downgrade
($out);
93 my $vary = 'Accept-Language, ' . $self->vary;
94 [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => $vary, 'X-Forever' => 1, 'Cache-Control' => 'max-age=' . $self->max_age], [ $out ] ]
104 return [] unless exists $templates{$_[0]};
105 [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $templates{$_[0]} ]
This page took 0.067213 seconds and 5 git commands to generate.