1 package Reaction::UI::RenderingContext::TT;
4 use aliased 'Reaction::UI::RenderingContext';
5 use aliased 'Template::View';
7 class TT is RenderingContext, which {
11 implements 'dispatch' => as {
12 my ($self, $render_tree, $args) = @_;
13 #warn "-- dispatch start\n";
15 my %args_copy = %$args;
16 foreach my $to_render (@$render_tree) {
17 my ($type, @to) = @$to_render;
18 if ($type eq '-layout') {
19 my ($lset, $fname, $next) = @to;
20 local $args_copy{call_next} =
22 ? sub { $self->dispatch($next, $args); }
23 : '' # no point running internal dispatch if nothing -to- dispatch
25 $self->render($lset, $fname, \%args_copy);
26 } elsif ($type eq '-render') {
27 my ($widget, $fname, $over) = @to;
31 local $args_copy{_} = $_[0];
32 $body .= $widget->render($fname, $self, \%args_copy);
35 $body .= $widget->render($fname, $self, \%args_copy);
39 #warn "-- dispatch end, body: ${body}\n-- end body\nbacktrace: ".Carp::longmess()."\n-- end trace\n";
43 implements 'render' => as {
44 my ($self, $lset, $fname, $args) = @_;
46 confess "\$body not in scope" unless defined($body);
48 # foreach non-_ prefixed key in the args
49 # build a subref for this key that passes self so the generator has a
50 # rendering context when [% key %] is evaluated by TT as $val->()
51 # (assuming it's a subref - if not just pass through)
55 my $arg = $args->{$_};
56 ($_ => (ref $arg eq 'CODE' ? sub { $arg->($self, $args) } : $arg))
57 } grep { !/^_/ } keys %$args
60 $body .= $lset->tt_view->include($fname, $tt_args);
61 #warn "rendered ${fname}, body length now ".length($body)."\n";