comparison Lib/IMPL/Web/View/TTDocument.pm @ 308:47a09a8dc23a

sync
author sergey
date Thu, 18 Apr 2013 20:06:05 +0400
parents 2da2564f115d
children 5e4e7c8fbca1
comparison
equal deleted inserted replaced
307:2da2564f115d 308:47a09a8dc23a
21 return $template, $ctx; # context 21 return $template, $ctx; # context
22 } 22 }
23 ], 23 ],
24 props => [ 24 props => [
25 layout => PROP_RW, 25 layout => PROP_RW,
26 loader => PROP_RW,
27 baseLocation => PROP_RW 26 baseLocation => PROP_RW
28 ] 27 ]
29 }; 28 };
30 29
31 sub CTOR { 30 sub CTOR {
32 my ($this,$template,$ctx,$loader,$vars) = @_; 31 my ($this,$template,$ctx,$vars) = @_;
33 32
34 $this->loader($loader) if $loader;
35 $this->layout( $template->layout ) unless $this->layout; 33 $this->layout( $template->layout ) unless $this->layout;
36 $this->title( $template->title ) unless $this->title; 34 $this->title( $template->title ) unless $this->title;
37 35
38 $this->context->stash->update($vars) 36 $this->context->stash->update($vars)
39 if ref $vars eq 'HASH'; 37 if ref $vars eq 'HASH';
44 42
45 $args ||= {}; 43 $args ||= {};
46 44
47 $this->context->localise(); # localise stash 45 $this->context->localise(); # localise stash
48 my $documentContext = _clone_context( $this->context ); # create a new context 46 my $documentContext = _clone_context( $this->context ); # create a new context
49
50 my $registry = TTRegistry->new($this->loader, $documentContext);
51 47
52 $this->context->stash->update({ 48 $this->context->stash->update({
53 require => sub { $registry->Require(shift) },
54 document => sub { $this } 49 document => sub { $this }
55 }); 50 });
56 51
57 my $text = eval { 52 my $text = eval {
58 53
59 if ($this->layout) { 54 if ($this->layout) {
60 my $tlayout = $this->loader->layout($this->layout); 55 my $tlayout = $this->GetTemplate($this->layout);
61 if(my $init = $tlayout->blocks->{INIT}) { 56 if(my $init = $tlayout->blocks->{INIT}) {
62 $this->context->process( 57 $this->context->process(
63 $init, 58 $init,
64 hashMerge( 59 hashMerge(
65 $args, 60 $args,
84 } 79 }
85 }; 80 };
86 81
87 my $e = $@; 82 my $e = $@;
88 83
89 $registry->Dispose();
90 undef $registry;
91 $this->context->delocalise(); 84 $this->context->delocalise();
92 85
93 undef $this; 86 undef $this;
94 87
95 if ($e) { 88 if ($e) {
101 94
102 sub GetTemplate { 95 sub GetTemplate {
103 my ($this,$name) = @_; 96 my ($this,$name) = @_;
104 97
105 $this->template->blocks->{$name}; 98 $this->template->blocks->{$name};
99 }
100
101 sub DTOR {
102 my $this = shift;
103
104 $this->registry->Dispose() if $this->registry;
106 } 105 }
107 106
108 sub _clone_context { 107 sub _clone_context {
109 my $args = { %{shift || {}} }; 108 my $args = { %{shift || {}} };
110 delete $args->{CONFIG}; 109 delete $args->{CONFIG};