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 file_extension => as { 'tt' };
13 implements 'BUILD' => as {
14 my ($self, $args) = @_;
16 # Do this at build time rather than on demand so any exception if it
17 # goes wrong gets thrown sometime sensible
19 $self->tt_view($self->_build_tt_view($args));
22 implements '_build_tt_view' => as {
23 my ($self, $args) = @_;
24 my $tt_object = $args->{tt_object}
25 || confess "tt_object not provided to new()";
26 my $tt_args = { data => {} };
27 my $name = $self->name;
28 $name =~ s/\//__/g; #slashes are not happy here...
29 my $layouts = $self->layouts;
31 my $tt_source = join("\n", "[%- VIEW ${name};",
32 (map {("BLOCK $_; -%]" . $layouts->{$_} ."[%- END;") } keys %$layouts),
33 "END; # End view\ndata.view = ${name}; -%]" );
35 $tt_object->process(\$tt_source, $tt_args)
36 || confess "Template processing error: ".$tt_object->error
37 ." processing:\n${tt_source}";
38 confess "View template processed but no view object found"
39 ." after processing:\n${tt_source}"
40 unless $tt_args->{data}{view};
41 return $tt_args->{data}{view};