do not include .git directory
[catagits/Reaction.git] / lib / Reaction / UI / LayoutSet / TT.pm
CommitLineData
7adfd53f 1package Reaction::UI::LayoutSet::TT;
2
3use Reaction::Class;
4use aliased 'Reaction::UI::LayoutSet';
5use aliased 'Template::View';
6
81393881 7use namespace::clean -except => [ qw(meta) ];
8extends LayoutSet;
7adfd53f 9
7adfd53f 10
7adfd53f 11
81393881 12has 'tt_view' => (is => 'rw', isa => View, lazy_fail => 1);
13sub BUILD {
14 my ($self, $args) = @_;
7adfd53f 15
81393881 16 # Do this at build time rather than on demand so any exception if it
17 # goes wrong gets thrown sometime sensible
7adfd53f 18
81393881 19 $self->tt_view($self->_build_tt_view($args));
20};
21sub _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};
cb92a3a3 42
81393881 43__PACKAGE__->meta->make_immutable;
7adfd53f 44
7adfd53f 45
461;