comparison Lib/IMPL/Web/View/TTContext.pm @ 352:675cd1829255

working on TTView: added control classes support
author cin
date Thu, 10 Oct 2013 19:51:19 +0400
parents cfd7570c2af2
children feeb3bc4a818
comparison
equal deleted inserted replaced
351:cfd7570c2af2 352:675cd1829255
11 use IMPL::declare { 11 use IMPL::declare {
12 require => { 12 require => {
13 Document => '-Template::Document', 13 Document => '-Template::Document',
14 TypeKeyedCollection => 'IMPL::TypeKeyedCollection', 14 TypeKeyedCollection => 'IMPL::TypeKeyedCollection',
15 ArgException => '-IMPL::InvalidArgumentException', 15 ArgException => '-IMPL::InvalidArgumentException',
16 Resources => 'IMPL::Resources' 16 Resources => 'IMPL::Resources',
17 Loader => 'IMPL::Code::Loader'
17 }, 18 },
18 base => [ 19 base => [
19 'Template::Context' => '@_' 20 'Template::Context' => '@_'
20 ] 21 ]
21 }; 22 };
30 parent 31 parent
31 prefix 32 prefix
32 cache 33 cache
33 includes 34 includes
34 modules 35 modules
36 aliases
35 )) { 37 )) {
36 my $t = $prop; 38 my $t = $prop;
37 39
38 *{__PACKAGE__ . '::' . $prop} = sub { 40 *{__PACKAGE__ . '::' . $prop} = sub {
39 my $this = shift; 41 my $this = shift;
91 my $info = $this->modules->{$file}; 93 my $info = $this->modules->{$file};
92 return $cache->{$name} = $info 94 return $cache->{$name} = $info
93 if $info; 95 if $info;
94 } else { 96 } else {
95 if( my $tt = eval { $this->template($file) } ) { 97 if( my $tt = eval { $this->template($file) } ) {
98 my $class;
99 if ($class = $tt->class) {
100 $class = $this->aliases->{$class} || $class;
101 Loader->safe->Require($class);
102 }
96 my $info = { 103 my $info = {
97 base => $base, 104 base => $base,
98 labels => $this->load_labels($file), 105 labels => $this->load_labels($file),
99 template => $tt, 106 template => $tt,
100 initialized => 0 107 initialized => 0,
108 class => $class
101 }; 109 };
102 $this->modules->{$file} = $info; 110 $this->modules->{$file} = $info;
103 return $cache->{$name} = $info; 111 return $cache->{$name} = $info;
104 } else { 112 } else {
105 $this->modules->{$file} = undef; 113 $this->modules->{$file} = undef;
186 194
187 my $out = eval { 195 my $out = eval {
188 $this->localise( 196 $this->localise(
189 hashApply( 197 hashApply(
190 { 198 {
199 aliases => $this->aliases || {},
191 root => $this->root || $this, 200 root => $this->root || $this,
192 modules => $this->modules || {}, 201 modules => $this->modules || {},
193 cache => TypeKeyedCollection->new(), 202 cache => TypeKeyedCollection->new(),
194 display => sub { 203 display => sub {
195 $this->display(@_); 204 $this->display(@_);
234 } 243 }
235 244
236 return $this->invoke_environment( 245 return $this->invoke_environment(
237 sub { 246 sub {
238 my $ctx = shift; 247 my $ctx = shift;
239 248
240 unless($info->{initialized}) { 249 unless($info->{initialized}) {
241 if(my $init = $info->{template}->blocks->{INIT}) { 250 if(my $init = $info->{template}->blocks->{INIT}) {
242 $info->{initialized} = 1; 251 $info->{initialized} = 1;
243 eval { 252 eval {
244 $ctx->visit($info->{template}->blocks); 253 $ctx->visit($info->{template}->blocks);
245 $ctx->include($init); 254 $ctx->include($init);
246 }; 255 };
247 $ctx->leave(); 256 $ctx->leave();
248 } 257 }
249 } 258 }
250 259
251 return $ctx->include($info->{template},$args); 260 if (my $class = $info->{class}) {
261 $class->new($this,$info->{template})->Render($args);
262 } else {
263 return $ctx->include($info->{template},$args);
264 }
252 }, 265 },
253 hashMerge( 266 hashMerge(
254 $info->{labels} || {}, 267 $info->{labels} || {},
255 { 268 {
256 base => $info->{base}, 269 base => $info->{base},