« lib/Reaction/UI/Widget/Data.pm
↑ Summary
lib/Reaction/UI/ViewPort/Field/Mutable/MatchingPasswords.pm »
| 1 | package Reaction::UI::RenderingContext::TT; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 3 | ▶ | use Reaction::Class; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 3 | ▶ | use aliased 'Reaction::UI::RenderingContext'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 3 | ▶ | use aliased 'Template::View'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 3 | ▶ | use namespace::clean -except => [ qw(meta) ]; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 3 | extends RenderingContext; | |||||||||||||
| 9 | |||||||||||||||
| 10 | |||||||||||||||
| 11 | |||||||||||||||
| 12 | 3 | our $body; | |||||||||||||
| 13 | 607 | ▶ | sub dispatch { | ||||||||||||
|
Subroutine
dispatch: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||
| 14 | 607 | my ($self, $render_tree, $args) = @_; | |||||||||||||
| 15 | #warn "-- dispatch start\n"; | ||||||||||||||
| 16 | 607 | local $body = ''; | |||||||||||||
| 17 | 607 | my %args_copy = %$args; | |||||||||||||
| 18 | 607 | foreach my $to_render (@$render_tree) { | |||||||||||||
| 19 | 590 | my ($type, @to) = @$to_render; | |||||||||||||
| 20 | 590 | ▶ | if ($type eq '-layout') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 21 | 493 | my ($lset, $fname, $next) = @to; | |||||||||||||
| 22 | local $args_copy{call_next} = | ||||||||||||||
| 23 | (@$next | ||||||||||||||
| 24 | 0 | ▶ | ? sub { $self->dispatch($next, $args); } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 25 | 493 | ▶ | : '' # no point running internal dispatch if nothing -to- dispatch | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | ); | ||||||||||||||
| 27 | 493 | $self->render($lset, $fname, \%args_copy); | |||||||||||||
| 28 | } elsif ($type eq '-render') { | ||||||||||||||
| 29 | 97 | my ($widget, $fname, $over) = @to; | |||||||||||||
| 30 | #warn "@to"; | ||||||||||||||
| 31 | 97 | ▶ | if (defined $over) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 20 | my $count = 0; | |||||||||||||
| 33 | 0 | ▶ | $over->each(sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 34 | 0 | local $args_copy{_} = $_[0]; | |||||||||||||
| 35 | 0 | local $args_copy{count} = ++$count; | |||||||||||||
| 36 | 0 | $body .= $widget->render($fname, $self, \%args_copy); | |||||||||||||
| 37 | 20 | }); | |||||||||||||
| 38 | } else { | ||||||||||||||
| 39 | 77 | $body .= $widget->render($fname, $self, \%args_copy); | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | } | ||||||||||||||
| 42 | } | ||||||||||||||
| 43 | #warn "-- dispatch end, body: ${body}\n-- end body\nbacktrace: ".Carp::longmess()."\n-- end trace\n"; | ||||||||||||||
| 44 | 607 | return $body; | |||||||||||||
| 45 | }; | ||||||||||||||
| 46 | 493 | ▶ | sub render { | ||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 47 | 493 | my ($self, $lset, $fname, $args) = @_; | |||||||||||||
| 48 | |||||||||||||||
| 49 | 493 | ▶ | confess "\$body not in scope" unless defined($body); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | |||||||||||||||
| 51 | # foreach non-_ prefixed key in the args | ||||||||||||||
| 52 | # build a subref for this key that passes self so the generator has a | ||||||||||||||
| 53 | # rendering context when [% key %] is evaluated by TT as $val->() | ||||||||||||||
| 54 | # (assuming it's a subref - if not just pass through) | ||||||||||||||
| 55 | |||||||||||||||
| 56 | my $tt_args = { | ||||||||||||||
| 57 | map { | ||||||||||||||
| 58 | 13724 | my $arg = $args->{$_}; | |||||||||||||
| 59 | 13724 | ▶ | ($_ => (ref $arg eq 'CODE' ? sub { $arg->($self, $args) } : $arg)) | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||
| 60 | 493 | } grep { !/^_/ } keys %$args | |||||||||||||
| 61 | }; | ||||||||||||||
| 62 | |||||||||||||||
| 63 | 493 | $body .= $lset->tt_view->include($fname, $tt_args); | |||||||||||||
| 64 | #warn "rendered ${fname}, body length now ".length($body)."\n"; | ||||||||||||||
| 65 | }; | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 68 | |||||||||||||||
| 69 | |||||||||||||||
| 70 | 2 | 1; | |||||||||||||