Mercurial > pub > Impl
annotate Lib/IMPL/Web/View/TTRegistry.pm @ 307:2da2564f115d
*TTView: fixed memory leak
| author | cin |
|---|---|
| date | Thu, 18 Apr 2013 02:21:28 +0400 |
| parents | b5d5793f348e |
| children | 5e4e7c8fbca1 |
| rev | line source |
|---|---|
|
304
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
1 package IMPL::Web::View::TTRegistry; |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
2 use strict; |
| 305 | 3 use mro; |
|
304
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
4 |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
5 use IMPL::Const qw(:prop); |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
6 use IMPL::declare { |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
7 require => { |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
8 TTFactory => 'IMPL::Web::View::TTFactory' |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
9 }, |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
10 base => [ |
| 305 | 11 'IMPL::Object' => undef, |
| 12 'IMPL::Object::Disposable' => undef | |
|
304
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
13 ], |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
14 props => [ |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
15 loader => PROP_RW, |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
16 context => PROP_RW, |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
17 _cache => PROP_RW, |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
18 ] |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
19 }; |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
20 |
| 305 | 21 sub CTOR { |
| 22 my ($this,$loader,$context) = @_; | |
| 23 | |
| 24 $this->loader($loader); | |
| 25 $this->context($context); | |
| 26 $this->_cache({}); | |
| 27 } | |
| 28 | |
|
304
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
29 sub Require { |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
30 my ($this,$name) = @_; |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
31 |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
32 if(my $factory = $this->_cache->{$name}) { |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
33 return $factory; |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
34 } else { |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
35 my $template = $this->loader->template($name) |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
36 or die AppException->new("Failed to load a template $name"); |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
37 |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
38 $factory = TTFactory->new( |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
39 $template, |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
40 $this->context, |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
41 $name, |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
42 $this |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
43 ); |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
44 |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
45 $this->_cache->{$name} = $factory; |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
46 return $factory; |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
47 } |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
48 } |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
49 |
| 305 | 50 sub Dispose { |
| 51 my ($this) = @_; | |
| 52 | |
| 53 $this->_cache(undef); | |
| 54 $this->context(undef); | |
| 55 $this->loader(undef); | |
| 56 | |
| 57 $this->next::method(); | |
| 58 } | |
| 59 | |
|
304
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
60 1; |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
61 |
|
2ff513227cb4
*TTView: refactoring. Added control registry for the document.
cin
parents:
diff
changeset
|
62 __END__ |
| 305 | 63 |
| 64 =pod | |
| 65 | |
| 66 =head1 NAME | |
| 67 | |
| 68 C<IMPL::Web::View::Registry> - реестр шаблонов документа. | |
| 69 | |
| 70 =head1 DESCRIPTION | |
| 71 | |
| 72 Используется для реализации функции C<require> внутри шаблонов. | |
| 73 | |
| 74 | |
| 75 | |
| 76 =cut |
