annotate Lib/IMPL/Web/View/TTFactory.pm @ 250:129e48bb5afb

DOM refactoring ObjectToDOM methods are virtual QueryToDOM uses inflators Fixed transform for the complex values in the ObjectToDOM QueryToDOM doesn't allow to use complex values (HASHes) as values for nodes (overpost problem)
author sergey
date Wed, 07 Nov 2012 04:17:53 +0400
parents 5c82eec23bb6
children bbc0da7ef90e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
1 package IMPL::Web::View::TTFactory;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
2 use strict;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
3
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
4 use Template::Context();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
5
232
5c82eec23bb6 Fixed degradations due refactoring
sergey
parents: 194
diff changeset
6 use IMPL::lang qw(:hash :declare );
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
7 use IMPL::Exception();
192
a9faf883cdce IMPL::Web::View refactoring
cin
parents: 191
diff changeset
8 use Scalar::Util qw(weaken);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
9
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
10
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
11 use parent qw(IMPL::Object::Factory);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
12
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
13 BEGIN {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
14 public property template => PROP_ALL;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
15 public property context => PROP_ALL;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
16 public property opts => PROP_ALL;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
17 public property nodeProperties => PROP_ALL;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
18 public property instances => PROP_GET | PROP_OWNERSET;
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
19 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
20
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
21 __PACKAGE__->PassThroughArgs;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
22
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
23 sub CTOR {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
24 my ($this,$factory,$template,$context,$options,$nodeProps) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
25
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
26 die IMPL::ArgumentException("A template is required") unless $template;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
27
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
28 $options ||= {};
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
29 $context ||= new Template::Context($options);
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
30
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
31 $this->template($template);
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
32 $this->context($context);
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
33 $this->opts($options);
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
34 $this->nodeProperties($nodeProps || {});
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
35 $this->instances(0);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
36 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
37
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
38 our %CTOR = (
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
39 'IMPL::Object::Factory' => sub {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
40 $_[0]
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
41 }
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
42 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
43
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
44 sub MergeParameters {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
45 my ($this,$name,$refProps) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
46
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
47 my $opts = { %{ $this->opts } };
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
48 $opts->{STASH} = $opts->{STASH}->clone() if $opts->{STASH};
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
49
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
50 my $ctx = new Template::Context($opts);
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
51
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
52 return ($name, $this->template, $ctx, hashMerge($this->nodeProperties,$refProps));
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
53 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
54
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
55 sub CreateObject {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
56 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
57
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
58 my $count = $this->instances;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
59
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
60 unless($count) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
61 # нужно выполнить именно блок INIT шаблона при создании первого экземпляра
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
62 if (my $init = $this->template->blocks->{INIT}) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
63 $this->context->process($init);
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
64 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
65 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
66
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
67 my $instance = $this->SUPER::CreateObject(@_);
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
68
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
69 $instance->InitInstance();
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
70
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
71 $count++;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
72 $this->instances($count);
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
73
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
74 return $instance;
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
75 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
76
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
77 sub save {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
78 die new IMPL::NotImplementedException("This class doesn't support serialization");
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
79 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
80
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
81 sub restore {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
82 die new IMPL::NotImplementedException("This class doesn't support serialization");
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
83 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
84
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
85 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
86
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
87 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
88
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
89 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
90
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
91 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
92
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
93 C<IMPL::Web::View::TTFactory> - фабрика элементов управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
94
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
95 =head1 SYNOPSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
96
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
97 =begin code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
98
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
99 my $factory = new IMPL::Web::View::TTFactory(
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
100 typeof IMPL::Web::View::TTControl,
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
101 $doc,
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
102 $context,
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
103 {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
104 TRIM => 1
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
105 },
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
106 {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
107 myprop => 'my value'
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
108 },
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
109 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
110
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
111 my $input1 = $factory->new('login', { class => "required" } );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
112
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
113 my $propval = $input->nodeProperty('myprop'); # 'my value'
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
114
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
115 =end code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
116
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
117 =begin text
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
118
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
119 [%
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
120 this.appendChild(
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
121 my.org.input.new('login', class = this.errors('login') ? "invalid" : "" )
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
122 );
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
123 %]
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
124
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
125 =end text
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
126
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
127 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
128
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
129 C< Inherits L<IMPL::Object::Factory> >
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
130
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
131 =head1 MEMBERS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
132
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
133 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
134
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
135 =item C<[get,set]template>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
136
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
137 Документ C<Template::Document> который описывает элемент управления. См. C<IMPL::Web::View::TTControl>.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
138
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
139 =item C<[get,set]context>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
140
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
141 Контекст фабрики элементов управления, в этом контексте выполняет шаблон элемента управления при загрузке.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
142 Далее в этом контексте будет выполнен блок инициализации при создании первого элемента управления.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
143
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
144 =item C<[get,set]opts>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
145
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
146 Параметры контекста элемента управления (ссылка на хеш). Каждый элемент управления при создании получает свой контекст,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
147 который создает с данными параметрами и хранилищем переменных, дочерним к контексту фабрики.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
148
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
149 =item C<[get,set]nodeProperties>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
150
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
151 Ссылка на хеш со значениями свойств по умолчанию для создаваемого элемента управления.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
152
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
153 =item C<[get]instances>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
154
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
155 Количество созданных элементов управления данной фабрикой
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
156
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
157 =item C<[override]MergeParameters($name,$nodeProps)>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
158
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
159 Превращает значения переданные методу C<new> фабрики в параметры для создания элемента управления.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
160
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
161 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
162
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
163 =item C<$name>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
164
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
165 Имя создаваемого узла (C<nodeName>).
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
166
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
167 =item C<$nodeProps>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
168
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
169 Ссылка на шех со значениями свойств узла. Данные значения будут совмещены со значениями из свойства C<nodeProperties>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
170
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
171 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
172
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
173 =item C<[override]CreateObject(@params)>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
174
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
175 Создает экземпляр элемента управления стандартным образом. Учитывает количество экземпляров и если это первый,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
176 то производит дополнительную инициализацию контекста выполнив блок шаблона C<INIT>.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
177
191
78a18a2b6266 IMPL::Web::View improvements (unstable)
cin
parents: 186
diff changeset
178 =item C<[inherited]new($name,$nodeProps)>
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
179
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
180 Создает элемент управления с указанным именем и набором свойств.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
182 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
183
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
184 =cut