]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Base.pm
Make Gruntmaster::Page::Base also act as strict/warnings/feature/etc
[gruntmaster-page.git] / lib / Gruntmaster / Page / Base.pm
index 89f8478e6c62ce5cfa9c01cd7dd542ed0a66e911..cffb656564e21c835ede46c38866335c3e21e52f 100644 (file)
@@ -3,6 +3,7 @@ package Gruntmaster::Page::Base;
 use 5.014000;
 use strict;
 use warnings;
+our $VERSION = '0.001';
 
 use File::Slurp qw/read_file/;
 use HTML::Template::Compiled;
@@ -34,18 +35,27 @@ 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) = @_;
 
+       strict->import;
+       feature->import(':5.14');
+       warnings->import;
+       File::Slurp->export_to_level(1, $caller, qw/read_file/);
        Gruntmaster::Data->export_to_level(1, $caller);
        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;
@@ -65,6 +75,12 @@ sub import {
        }
 }
 
+sub import {
+       return unless $_[0] eq __PACKAGE__;
+       splice @_, 1, 0, scalar caller;
+       goto &import_to
+}
+
 ##################################################
 
 sub generate{
@@ -74,14 +90,18 @@ sub generate{
        $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 ] ]
+       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]} ]
 }
 
This page took 0.023166 seconds and 4 git commands to generate.