slight change for saner behavior when munging names
[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
7class TT is LayoutSet, which {
8
9 has 'tt_view' => (is => 'rw', isa => View, lazy_fail => 1);
10
11 implements 'BUILD' => as {
12 my ($self, $args) = @_;
13
14 # Do this at build time rather than on demand so any exception if it
15 # goes wrong gets thrown sometime sensible
16
17 $self->tt_view($self->_build_tt_view($args));
18 };
19
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 my $fragments = $self->fragments;
27 my $tt_source = qq{[% VIEW ${name};\n\n}.
28 join("\n\n",
29 map {
30 qq{BLOCK $_; -%]\n}.$fragments->{$_}.qq{\n[% END;};
31 } keys %$fragments
32 ).qq{\nEND; # End view\ndata.view = ${name};\n %]};
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};
40 };
41
42};
43
441;