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_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 $fragments = $self->fragments;
30 my $tt_source = qq{[% VIEW ${name};\n\n}.
33 qq{BLOCK $_; -%]\n}.$fragments->{$_}.qq{\n[% END;};
35 ).qq{\nEND; # End view\ndata.view = ${name};\n %]};
36 $tt_object->process(\$tt_source, $tt_args)
37 || confess "Template processing error: ".$tt_object->error
38 ." processing:\n${tt_source}";
39 confess "View template processed but no view object found"
40 ." after processing:\n${tt_source}"
41 unless $tt_args->{data}{view};
42 return $tt_args->{data}{view};