Skip to content

Commit

Permalink
Delay load MicroTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Nov 17, 2009
1 parent e40d392 commit 13eef7f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/Tatsumaki/Application.pm
Expand Up @@ -3,7 +3,6 @@ use AnyEvent;
use Any::Moose;
use Tatsumaki::Handler;
use Tatsumaki::Request;
use Text::MicroTemplate::File;
use Try::Tiny;

use Plack::Middleware::Static;
Expand All @@ -12,7 +11,7 @@ use Tatsumaki::Middleware::BlockingFallback;
use overload q(&{}) => sub { shift->psgi_app }, fallback => 1;

has _rules => (is => 'rw', isa => 'ArrayRef');
has template => (is => 'rw', isa => 'Text::MicroTemplate::File', lazy_build => 1, handles => [ 'render_file' ]);
has template => (is => 'rw', isa => 'Tatsumaki::Template', lazy_build => 1, handles => [ 'render_file' ]);

has static_path => (is => 'rw', isa => 'Str', default => 'static');
has services => (is => 'rw', isa => 'ArrayRef[Tatsumaki::Service]', default => sub { [] });
Expand Down Expand Up @@ -81,22 +80,17 @@ sub compile_psgi_app {

sub _build_template {
my $self = shift;
Text::MicroTemplate::File->new(
include_path => [ 'templates' ],
use_cache => 0,
tag_start => '<%',
tag_end => '%>',
line_start => '%',
);
require Tatsumaki::Template::Micro;
Tatsumaki::Template::Micro->new;
}

sub template_path {
my $self = shift;
if (@_) {
my $path = ref $_[0] eq 'ARRAY' ? $_[0] : [ $_[0] ];
$self->template->{include_path} = $path;
$self->template->include_path($path);
}
$self->template->{include_path};
$self->template->include_path;
}

sub add_service {
Expand Down
7 changes: 7 additions & 0 deletions lib/Tatsumaki/Template.pm
@@ -0,0 +1,7 @@
package Tatsumaki::Template;
use Moose;

sub render_file;
sub include_path;

1;
29 changes: 29 additions & 0 deletions lib/Tatsumaki/Template/Micro.pm
@@ -0,0 +1,29 @@
package Tatsumaki::Template::Micro;
use Moose;
extends 'Tatsumaki::Template';

use Text::MicroTemplate::File;
has mt => (is => 'rw', isa => 'Text::MicroTemplate::File', handles => [ 'render_file' ]);

sub BUILD {
my $self = shift;

my $mt = Text::MicroTemplate::File->new(
include_path => [ 'templates' ],
use_cache => 0,
tag_start => '<%',
tag_end => '%>',
line_start => '%',
);

$self->mt($mt);
};

sub include_path {
my $self = shift;
$self->mt->{include_path} = shift if @_;
$self->mt->{include_path};
}

1;

0 comments on commit 13eef7f

Please sign in to comment.