Mercurial > pub > Impl
comparison Lib/IMPL/Web/View/TTDocument.pm @ 305:b5d5793f348e
TTView refactoring, still experiencing memory leaks
author | sergey |
---|---|
date | Wed, 17 Apr 2013 18:00:19 +0400 |
parents | 2ff513227cb4 |
children | 2da2564f115d |
comparison
equal
deleted
inserted
replaced
304:2ff513227cb4 | 305:b5d5793f348e |
---|---|
7 use Carp qw(carp); | 7 use Carp qw(carp); |
8 use mro; | 8 use mro; |
9 | 9 |
10 use IMPL::declare { | 10 use IMPL::declare { |
11 require => { | 11 require => { |
12 TTRegistry => 'IMPL::Web::View::TTRegistry', | |
12 TTFactory => 'IMPL::Web::View::TTFactory', | 13 TTFactory => 'IMPL::Web::View::TTFactory', |
13 TTControl => 'IMPL::Web::View::TTControl', | 14 TTControl => 'IMPL::Web::View::TTControl', |
14 Loader => 'IMPL::Code::Loader' | 15 Loader => 'IMPL::Code::Loader' |
15 }, | 16 }, |
16 base => [ | 17 base => [ |
39 | 40 |
40 sub Render { | 41 sub Render { |
41 my ($this,$args) = @_; | 42 my ($this,$args) = @_; |
42 | 43 |
43 $args ||= {}; | 44 $args ||= {}; |
45 | |
46 $this->context->localise(); # localise stash | |
47 my $documentContext = _clone_context( $this->context ); # create a new context | |
48 | |
49 my $registry = TTRegistry->new($this->loader, $documentContext); | |
44 | 50 |
45 my %controls; | 51 $this->context->stash->update({ |
46 my $require; | 52 require => sub { $registry->Require(shift) }, |
47 my $documentContext; | 53 document => $this |
48 | 54 }); |
49 my $self = $this; | |
50 | |
51 $require = sub { | |
52 my $control = shift; | |
53 | |
54 unless($self) { | |
55 carp("Cant load control $control outside the document rendering process"); | |
56 return; | |
57 } | |
58 | |
59 if (my $factory = $controls{$control}) { | |
60 return $factory; | |
61 } else { | |
62 my $path = $control; | |
63 | |
64 if ( my $template = $self->loader->template($path) ) { | |
65 | |
66 $documentContext->localise(); | |
67 my $ctx = _clone_context($documentContext); | |
68 $documentContext->delocalise(); | |
69 | |
70 $factory = new IMPL::Web::View::TTFactory( | |
71 $template, | |
72 $ctx, | |
73 join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) ), | |
74 $require | |
75 ); | |
76 | |
77 $controls{$control} = $factory; | |
78 | |
79 return $factory; | |
80 | |
81 } else { | |
82 die new IMPL::KeyNotFoundException($control); | |
83 } | |
84 } | |
85 }; | |
86 | |
87 $this->context->localise(); | |
88 $documentContext = _clone_context( $this->context ); | |
89 | |
90 $this->context->stash->set(require => $require); | |
91 $this->context->stash->set(document => sub { $self }); | |
92 | 55 |
93 my $text = eval { | 56 my $text = eval { |
94 | 57 |
95 if ($this->layout) { | 58 if ($this->layout) { |
96 my $tlayout = $this->loader->layout($this->layout); | 59 my $tlayout = $this->loader->layout($this->layout); |
120 } | 83 } |
121 }; | 84 }; |
122 | 85 |
123 my $e = $@; | 86 my $e = $@; |
124 | 87 |
125 undef $require; | 88 $registry->Dispose(); |
126 undef $documentContext; | 89 undef $registry; |
127 undef %controls; | |
128 undef $self; | |
129 $this->context->delocalise(); | 90 $this->context->delocalise(); |
130 | 91 |
131 if ($e) { | 92 if ($e) { |
132 die $e; | 93 die $e; |
133 } else { | 94 } else { |