comparison Lib/IMPL/Web/View/TTDocument.pm @ 301:aeeb57a12046

*IMPL::Web::View: templates inheritance support
author cin
date Mon, 25 Mar 2013 02:04:18 +0400
parents bf3af33b9003
children a5eb64c6e6f7
comparison
equal deleted inserted replaced
300:bf3af33b9003 301:aeeb57a12046
29 sub CTOR { 29 sub CTOR {
30 my ($this,$template,$ctx,$loader,$vars) = @_; 30 my ($this,$template,$ctx,$loader,$vars) = @_;
31 31
32 $this->loader($loader) if $loader; 32 $this->loader($loader) if $loader;
33 $this->layout( $template->layout ) unless $this->layout; 33 $this->layout( $template->layout ) unless $this->layout;
34 $this->title( $template->title ) unless $this->title;
34 35
35 $this->context->stash->update($vars) 36 $this->context->stash->update($vars)
36 if ref $vars eq 'HASH'; 37 if ref $vars eq 'HASH';
37 } 38 }
38 39
49 50
50 $require = sub { 51 $require = sub {
51 my $control = shift; 52 my $control = shift;
52 53
53 unless($self) { 54 unless($self) {
54 carp("Cant load control $control outside the rendering procedure"); 55 carp("Cant load control $control outside the document rendering process");
55 return; 56 return;
56 } 57 }
57 58
58 if (my $factory = $controls{$control}) { 59 if (my $factory = $controls{$control}) {
59 return $factory; 60 return $factory;
60 } else { 61 } else {
61 my $path = $control; 62 my $path = $control;
62 63
63 if ( my $template = $self->loader->template($path) ) { 64 if ( my $template = $self->loader->template($path) ) {
65
66 $documentContext->localise();
67 my $ctx = _clone_context($documentContext);
68 $documentContext->delocalise();
64 69
65 $factory = new IMPL::Web::View::TTFactory( 70 $factory = new IMPL::Web::View::TTFactory(
66 $template, 71 $template,
67 $documentContext, 72 $ctx,
68 join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) ), 73 join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) ),
69 $require 74 $require
70 ); 75 );
71 76
72 $controls{$control} = $factory; 77 $controls{$control} = $factory;
112 ); 117 );
113 } else { 118 } else {
114 return $this->next::method($args); 119 return $this->next::method($args);
115 } 120 }
116 }; 121 };
122
123 my $e = $@;
117 124
118 undef $require; 125 undef $require;
119 undef $documentContext; 126 undef $documentContext;
120 undef %controls; 127 undef %controls;
121 undef $self; 128 undef $self;
122 $this->context->delocalise(); 129 $this->context->delocalise();
123 130
124
125 my $e = $@;
126 if ($e) { 131 if ($e) {
127 die $e; 132 die $e;
128 } else { 133 } else {
129 return $text; 134 return $text;
130 } 135 }
131
132
133 } 136 }
134 137
135 sub _clone_context { 138 sub _clone_context {
136 my $args = { %{shift || {}} }; 139 my $args = { %{shift || {}} };
137 delete $args->{CONFIG}; 140 delete $args->{CONFIG};