X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FLayoutSet%2FTT.pm;h=fbdf56966eedb78033059665f5512f09583a1560;hb=87d3d076c2d0e7f15c93c8cbdaaff34fd7caab75;hp=02b3cde9ddda2918f37c86a37fa69ab8b50a7115;hpb=6ab43711ccd779eedce107001b300043e2056a0c;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/LayoutSet/TT.pm b/lib/Reaction/UI/LayoutSet/TT.pm index 02b3cde..fbdf569 100644 --- a/lib/Reaction/UI/LayoutSet/TT.pm +++ b/lib/Reaction/UI/LayoutSet/TT.pm @@ -4,42 +4,43 @@ use Reaction::Class; use aliased 'Reaction::UI::LayoutSet'; use aliased 'Template::View'; -class TT is LayoutSet, which { - - has 'tt_view' => (is => 'rw', isa => View, lazy_fail => 1); - - implements 'BUILD' => as { - my ($self, $args) = @_; - - # Do this at build time rather than on demand so any exception if it - # goes wrong gets thrown sometime sensible - - $self->tt_view($self->_build_tt_view($args)); - }; - - implements '_build_tt_view' => as { - my ($self, $args) = @_; - my $tt_object = $args->{tt_object} - || confess "tt_object not provided to new()"; - my $tt_args = { data => {} }; - my $name = $self->name; - $name =~ s/\//__/g; #slashes are not happy here... - my $fragments = $self->fragments; - my $tt_source = qq{[% VIEW ${name};\n\n}. - join("\n\n", - map { - qq{BLOCK $_; -%]\n}.$fragments->{$_}.qq{\n[% END;}; - } keys %$fragments - ).qq{\nEND; # End view\ndata.view = ${name};\n %]}; - $tt_object->process(\$tt_source, $tt_args) - || confess "Template processing error: ".$tt_object->error - ." processing:\n${tt_source}"; - confess "View template processed but no view object found" - ." after processing:\n${tt_source}" - unless $tt_args->{data}{view}; - return $tt_args->{data}{view}; - }; +use namespace::clean -except => [ qw(meta) ]; +extends LayoutSet; + + +has 'tt_view' => (is => 'rw', isa => View, lazy_fail => 1); +sub BUILD { + my ($self, $args) = @_; + + # Do this at build time rather than on demand so any exception if it + # goes wrong gets thrown sometime sensible + + $self->tt_view($self->_build_tt_view($args)); }; +sub _build_tt_view { + my ($self, $args) = @_; + my $tt_object = $args->{tt_object} + || confess "tt_object not provided to new()"; + my $tt_args = { data => {} }; + my $name = $self->name; + $name =~ s/\//__/g; #slashes are not happy here... + my $layouts = $self->layouts; + + my $tt_source = join("\n", "[%- VIEW ${name};", + (map {("BLOCK $_; -%]" . $layouts->{$_} ."[%- END;") } keys %$layouts), + "END; # End view\ndata.view = ${name}; -%]" ); + + $tt_object->process(\$tt_source, $tt_args) + || confess "Template processing error: ".$tt_object->error + ." processing:\n${tt_source}"; + confess "View template processed but no view object found" + ." after processing:\n${tt_source}" + unless $tt_args->{data}{view}; + return $tt_args->{data}{view}; +}; + +__PACKAGE__->meta->make_immutable; + 1;