diff options
author | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2008-07-24 01:42:34 +0000 |
---|---|---|
committer | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2008-07-24 01:42:34 +0000 |
commit | 8139388160b0a38002b22ff95c3fee3d8380f156 (patch) | |
tree | d7610c5db84c2c996107adb36bca1fe8a2b0b7cb /lib/Reaction/UI/RenderingContext | |
parent | 2a4c89335368295f0fc55f79d2c8fd5e33afd212 (diff) | |
download | reaction-8139388160b0a38002b22ff95c3fee3d8380f156.tar.gz reaction-8139388160b0a38002b22ff95c3fee3d8380f156.zip |
rclass stuff ripped out of everything but widget classes
Diffstat (limited to 'lib/Reaction/UI/RenderingContext')
-rw-r--r-- | lib/Reaction/UI/RenderingContext/TT.pm | 100 |
1 files changed, 51 insertions, 49 deletions
diff --git a/lib/Reaction/UI/RenderingContext/TT.pm b/lib/Reaction/UI/RenderingContext/TT.pm index c69fe18..a29d8d4 100644 --- a/lib/Reaction/UI/RenderingContext/TT.pm +++ b/lib/Reaction/UI/RenderingContext/TT.pm @@ -4,65 +4,67 @@ use Reaction::Class; use aliased 'Reaction::UI::RenderingContext'; use aliased 'Template::View'; -class TT is RenderingContext, which { +use namespace::clean -except => [ qw(meta) ]; +extends RenderingContext; - our $body; - implements 'dispatch' => as { - my ($self, $render_tree, $args) = @_; + +our $body; +sub dispatch { + my ($self, $render_tree, $args) = @_; #warn "-- dispatch start\n"; - local $body = ''; - my %args_copy = %$args; - foreach my $to_render (@$render_tree) { - my ($type, @to) = @$to_render; - if ($type eq '-layout') { - my ($lset, $fname, $next) = @to; - local $args_copy{call_next} = - (@$next - ? sub { $self->dispatch($next, $args); } - : '' # no point running internal dispatch if nothing -to- dispatch - ); - $self->render($lset, $fname, \%args_copy); - } elsif ($type eq '-render') { - my ($widget, $fname, $over) = @to; - #warn "@to"; - if (defined $over) { - my $count = 0; - $over->each(sub { - local $args_copy{_} = $_[0]; - local $args_copy{count} = ++$count; - $body .= $widget->render($fname, $self, \%args_copy); - }); - } else { + local $body = ''; + my %args_copy = %$args; + foreach my $to_render (@$render_tree) { + my ($type, @to) = @$to_render; + if ($type eq '-layout') { + my ($lset, $fname, $next) = @to; + local $args_copy{call_next} = + (@$next + ? sub { $self->dispatch($next, $args); } + : '' # no point running internal dispatch if nothing -to- dispatch + ); + $self->render($lset, $fname, \%args_copy); + } elsif ($type eq '-render') { + my ($widget, $fname, $over) = @to; + #warn "@to"; + if (defined $over) { + my $count = 0; + $over->each(sub { + local $args_copy{_} = $_[0]; + local $args_copy{count} = ++$count; $body .= $widget->render($fname, $self, \%args_copy); - } + }); + } else { + $body .= $widget->render($fname, $self, \%args_copy); } } + } #warn "-- dispatch end, body: ${body}\n-- end body\nbacktrace: ".Carp::longmess()."\n-- end trace\n"; - return $body; - }; - - implements 'render' => as { - my ($self, $lset, $fname, $args) = @_; + return $body; +}; +sub render { + my ($self, $lset, $fname, $args) = @_; - confess "\$body not in scope" unless defined($body); - - # foreach non-_ prefixed key in the args - # build a subref for this key that passes self so the generator has a - # rendering context when [% key %] is evaluated by TT as $val->() - # (assuming it's a subref - if not just pass through) - - my $tt_args = { - map { - my $arg = $args->{$_}; - ($_ => (ref $arg eq 'CODE' ? sub { $arg->($self, $args) } : $arg)) - } grep { !/^_/ } keys %$args - }; - - $body .= $lset->tt_view->include($fname, $tt_args); -#warn "rendered ${fname}, body length now ".length($body)."\n"; + confess "\$body not in scope" unless defined($body); + + # foreach non-_ prefixed key in the args + # build a subref for this key that passes self so the generator has a + # rendering context when [% key %] is evaluated by TT as $val->() + # (assuming it's a subref - if not just pass through) + + my $tt_args = { + map { + my $arg = $args->{$_}; + ($_ => (ref $arg eq 'CODE' ? sub { $arg->($self, $args) } : $arg)) + } grep { !/^_/ } keys %$args }; + $body .= $lset->tt_view->include($fname, $tt_args); +#warn "rendered ${fname}, body length now ".length($body)."\n"; }; +__PACKAGE__->meta->make_immutable; + + 1; |