]>
iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/Base.pm
1 package Gruntmaster
::Page
::Base
;
6 our $VERSION = '5999.000_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 ##################################################
37 use Plack
::Request
();
40 my $ua = LWP
::UserAgent
->new;
46 my ($self, $caller, $name, $title) = @_;
49 feature
->import(':5.14');
51 File
::Slurp
->export_to_level(1, $caller, qw
/read_file/);
52 List
::Util
->export_to_level(1, $caller, qw
/sum/);
55 *{"${caller}::ISA"} = [__PACKAGE__
];
56 *{"${caller}::VERSION"} = $VERSION;
57 *{"${caller}::strftime"} = \
&POSIX
::strftime
;
58 *{"${caller}::debug"} = sub {
59 local $Log::Log4perl
::caller_depth
= $Log::Log4perl
::caller_depth
+ 1;
60 $_[0]->{'psgix.logger'}->({qw
/level debug message/ => $_[1]})
62 *{"${caller}::db"} = sub { $_[0]->{'gruntmaster.dbic'} };
63 *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain', 'Cache-Control' => 'no-cache'], [ @_ ] ] };
64 *{"${caller}::purge"} = sub {
65 return unless $ENV{PURGE_HOST
};
66 my $req = HTTP
::Request
->new(PURGE
=> "http://$ENV{PURGE_HOST}$_[0]");
71 $templates{$caller} = { read_templates
$name };
72 $templates{$caller}{$_} = header
($_, $title) . $templates{$caller}{$_} for keys $templates{$caller};
73 $templates{$caller}{$_} .= footer
$_ for keys $templates{$caller};
78 return unless $_[0] eq __PACKAGE__
;
79 splice @_, 1, 0, scalar caller;
83 ##################################################
86 my ($self, $lang, @args) = @_;
88 my $htc = HTML
::Template
::Compiled
->new(scalarref
=> \
$templates{$self}{$lang}, default_escape
=> 'HTML', use_perl
=> 1);
89 $self->_generate($htc, $lang, @args);
90 my $out = $htc->output;
92 my $vary = 'Accept-Language, ' . $self->vary;
93 [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => $vary, 'X-Forever' => 1, 'Cache-Control' => 'max-age=' . $self->max_age], [ $out ] ]
103 return [] unless exists $templates{$_[0]};
104 [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $templates{$_[0]} ]
This page took 0.06679 seconds and 4 git commands to generate.