1 package Reaction::UI::LayoutSet::TT;
4 use aliased 'Reaction::UI::LayoutSet';
5 use aliased 'Template::View';
7 class TT is LayoutSet, which {
9 has 'tt_view' => (is => 'rw', isa => View, lazy_fail => 1);
11 implements 'BUILD' => as {
12 my ($self, $args) = @_;
14 # Do this at build time rather than on demand so any exception if it
15 # goes wrong gets thrown sometime sensible
17 $self->tt_view($self->_build_tt_view($args));
20 implements '_build_tt_view' => as {
21 my ($self, $args) = @_;
22 my $tt_object = $args->{tt_object}
23 || confess "tt_object not provided to new()";
24 my $tt_args = { data => {} };
25 my $name = $self->name;
26 $name =~ s/\//__/g; #slashes are not happy here...
27 my $layouts = $self->layouts;
29 my $tt_source = join("\n", "[%- VIEW ${name};",
30 (map {("BLOCK $_; -%]" . $layouts->{$_} ."[%- END;") } keys %$layouts),
31 "END; # End view\ndata.view = ${name}; -%]" );
33 $tt_object->process(\$tt_source, $tt_args)
34 || confess "Template processing error: ".$tt_object->error
35 ." processing:\n${tt_source}";
36 confess "View template processed but no view object found"
37 ." after processing:\n${tt_source}"
38 unless $tt_args->{data}{view};
39 return $tt_args->{data}{view};