do not include .git directory
[catagits/Reaction.git] / lib / Reaction / UI / LayoutSet / TT.pm
1 package Reaction::UI::LayoutSet::TT;
2
3 use Reaction::Class;
4 use aliased 'Reaction::UI::LayoutSet';
5 use aliased 'Template::View';
6
7 use namespace::clean -except => [ qw(meta) ];
8 extends LayoutSet;
9
10
11
12 has 'tt_view' => (is => 'rw', isa => View, lazy_fail => 1);
13 sub BUILD {
14   my ($self, $args) = @_;
15
16   # Do this at build time rather than on demand so any exception if it
17   # goes wrong gets thrown sometime sensible
18
19   $self->tt_view($self->_build_tt_view($args));
20 };
21 sub _build_tt_view {
22   my ($self, $args) = @_;
23   my $tt_object = $args->{tt_object}
24     || confess "tt_object not provided to new()";
25   my $tt_args = { data => {} };
26   my $name = $self->name;
27   $name =~ s/\//__/g; #slashes are not happy here...
28   my $layouts = $self->layouts;
29
30   my $tt_source = join("\n", "[%- VIEW ${name};",
31     (map {("BLOCK $_; -%]" . $layouts->{$_} ."[%- END;") } keys %$layouts),
32       "END; # End view\ndata.view = ${name}; -%]" );
33
34   $tt_object->process(\$tt_source, $tt_args)
35     || confess "Template processing error: ".$tt_object->error
36               ." processing:\n${tt_source}";
37   confess "View template processed but no view object found"
38          ." after processing:\n${tt_source}"
39     unless $tt_args->{data}{view};
40   return $tt_args->{data}{view};
41 };
42
43 __PACKAGE__->meta->make_immutable;
44
45
46 1;