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;
32 local $args_copy{_} = $_[0];
33 local $args_copy{count} = ++$count;
34 $body .= $widget->render($fname, $self, \%args_copy);
37 $body .= $widget->render($fname, $self, \%args_copy);
41 #warn "-- dispatch end, body: ${body}\n-- end body\nbacktrace: ".Carp::longmess()."\n-- end trace\n";
45 implements 'render' => as {
46 my ($self, $lset, $fname, $args) = @_;
48 confess "\$body not in scope" unless defined($body);
50 # foreach non-_ prefixed key in the args
51 # build a subref for this key that passes self so the generator has a
52 # rendering context when [% key %] is evaluated by TT as $val->()
53 # (assuming it's a subref - if not just pass through)
57 my $arg = $args->{$_};
58 ($_ => (ref $arg eq 'CODE' ? sub { $arg->($self, $args) } : $arg))
59 } grep { !/^_/ } keys %$args
62 $body .= $lset->tt_view->include($fname, $tt_args);
63 #warn "rendered ${fname}, body length now ".length($body)."\n";