comparison Lib/IMPL/Web/View/TTDocument.pm @ 290:7b0dad6117d5

*TTView: fixed memory leak
author sergey
date Wed, 20 Feb 2013 17:24:57 +0400
parents 85572f512abc
children 5d14baa35790
comparison
equal deleted inserted replaced
289:85572f512abc 290:7b0dad6117d5
46 $args ||= {}; 46 $args ||= {};
47 47
48 my %controls; 48 my %controls;
49 my $require; 49 my $require;
50 my $documentContext; 50 my $documentContext;
51
52 my $self = $this;
53
51 $require = sub { 54 $require = sub {
52 my $control = shift; 55 my $control = shift;
56
57 carp("Cant load control $control outside the rendering procedure") unless $self;
58
53 if (my $factory = $controls{$control}) { 59 if (my $factory = $controls{$control}) {
54 return $factory; 60 return $factory;
55 } else { 61 } else {
56 my $path = $control; 62 my $path = $control;
57 63
58 if ( my $template = $this->loader->template($path) ) { 64 if ( my $template = $self->loader->template($path) ) {
59 65
60 $factory = new IMPL::Web::View::TTFactory( 66 $factory = new IMPL::Web::View::TTFactory(
61 $template->class || TTControl, 67 $template->class || TTControl,
62 $template, 68 $template,
63 $documentContext, 69 $documentContext,
79 } 85 }
80 }; 86 };
81 87
82 $this->context->localise(); 88 $this->context->localise();
83 $documentContext = _clone_context( $this->context ); 89 $documentContext = _clone_context( $this->context );
84 my $self = $this; 90
85 weaken($self);
86 $this->context->stash->set(require => $require); 91 $this->context->stash->set(require => $require);
87 #$this->context->stash->set(document => sub { $self }); 92 $this->context->stash->set(document => sub { $self });
88 93
89 94
90 my $text = eval { 95 my $text = eval {
91 96
92 if ($this->layout) { 97 if ($this->layout) {
118 }; 123 };
119 124
120 undef $require; 125 undef $require;
121 undef $documentContext; 126 undef $documentContext;
122 undef %controls; 127 undef %controls;
128 undef $self;
123 $this->context->delocalise(); 129 $this->context->delocalise();
124 130
125 131
126 my $e = $@; 132 my $e = $@;
127 if ($e) { 133 if ($e) {