annotate Lib/IMPL/Web/Application/ControllerUnit.pm @ 126:c8dfbbdd8005

Several bug fixes Forms support pre-alfa version
author wizard
date Fri, 11 Jun 2010 04:29:51 +0400
parents 7b14e0122b79
children 0dce0470a3d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
1 package IMPL::Web::Application::ControllerUnit;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
2 use strict;
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
3 use base qw(IMPL::Object);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
4
c13a215508ca Refactoring,
wizard
parents:
diff changeset
5 use IMPL::Class::Property;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
6 use IMPL::DOM::Transform::PostToDOM;
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
7 use IMPL::DOM::Schema;
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
8 use Class::Inspector;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
9 use File::Spec;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
10
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
11 use constant {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
12 CONTROLLER_METHODS => 'controller_methods',
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
13 STATE_CORRECT => 'correct',
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
14 STATE_NEW => 'new',
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
15 STATE_INVALID => 'invalid'
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
16 };
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
17
c13a215508ca Refactoring,
wizard
parents:
diff changeset
18 BEGIN {
c13a215508ca Refactoring,
wizard
parents:
diff changeset
19 public property action => prop_get | owner_set;
c13a215508ca Refactoring,
wizard
parents:
diff changeset
20 public property application => prop_get | owner_set;
c13a215508ca Refactoring,
wizard
parents:
diff changeset
21 public property query => prop_get | owner_set;
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
22 public property formData => prop_get | owner_set;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
23 public property formSchema => prop_get | owner_set;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
24 public property formErrors => prop_get | owner_set;
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
25 }
c13a215508ca Refactoring,
wizard
parents:
diff changeset
26
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
27 __PACKAGE__->class_data(CONTROLLER_METHODS,{});
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
28
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
29 sub CTOR {
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
30 my ($this,$action,$args) = @_;
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
31
c13a215508ca Refactoring,
wizard
parents:
diff changeset
32 $this->action($action);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
33 $this->application($action->application);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
34 $this->query($action->query);
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
35
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
36 $this->$_($args->{$_}) foreach qw(formData formSchema formErrors);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
37 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
38
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
39 sub forms {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
40 my ($self,%forms) = @_;
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
41
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
42 while ( my ($method,$info) = each %forms ) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
43 die new IMPL::Exception("A method doesn't exists in the controller",$self,$method) unless $self->can($method);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
44 if ( not ref $info ) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
45 $self->class_data(CONTROLLER_METHODS)->{$method} = {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
46 wrapper => 'FormWrapper',
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
47 schema => $info
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
48 };
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
49 } elsif (ref $info eq 'HASH') {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
50 die new IMPL::Exception("A schema must be specified",$self,$method) unless $info->{schema};
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
51
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
52 $self->class_data(CONTROLLER_METHODS)->{$method} = {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
53 wrapper => 'FormWrapper',
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
54 schema => $info->{schema}
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
55 };
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
56 } else {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
57 die new IMPL::Exception("Unsupported method information",$self,$method);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
58 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
59 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
60 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
61
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
62 sub transactions {
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
63 my ($self,@names) = @_;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
64
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
65 $self->class_data(CONTROLLER_METHODS)->{$_} = {} foreach @names;
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
66 }
c13a215508ca Refactoring,
wizard
parents:
diff changeset
67
c13a215508ca Refactoring,
wizard
parents:
diff changeset
68 sub InvokeAction {
c13a215508ca Refactoring,
wizard
parents:
diff changeset
69 my ($self,$method,$action) = @_;
c13a215508ca Refactoring,
wizard
parents:
diff changeset
70
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
71 if (my $methodInfo = $self->class_data(CONTROLLER_METHODS)->{$method}) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
72 if (my $wrapper = $methodInfo->{wrapper}) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
73 return $self->$wrapper($method,$action,$methodInfo);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
74 } else {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
75 return $self->TransactionWrapper($method,$action,$methodInfo);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
76 }
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
77 } else {
c13a215508ca Refactoring,
wizard
parents:
diff changeset
78 die new IMPL::InvalidOperationException("Invalid method call",$self,$method);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
79 }
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
80 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
81
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
82 sub TransactionWrapper {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
83 my ($self,$method,$action,$methodInfo) = @_;
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
84
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
85 my $unit = $self->new($action);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
86 return $unit->$method();
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
87 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
88
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
89 sub FormWrapper {
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
90 my ($self,$method,$action,$methodInfo) = @_;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
91
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
92 my $schema = $self->loadSchema($methodInfo->{schema});
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
93
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
94 my $process = $action->query->param('process') || 0;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
95 my $form = $methodInfo->{form}
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
96 || $action->query->param('form')
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
97 || $schema->selectSingleNode('ComplexNode')->name
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
98 or die new IMPL::Exception('No situable form name could be determined',$self,$method);
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
99
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
100 my %result;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
101
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
102 my $transform = IMPL::DOM::Transform::PostToDOM->new(
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
103 undef,
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
104 $schema,
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
105 $form
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
106 );
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
107
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
108 $result{formSchema} = $schema;
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
109 $result{formData} = $transform->Transform($action->query);
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
110
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
111
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
112 if ($process) {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
113 $result{formErrors} = $transform->Errors->as_list;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
114 if ($transform->Errors->Count) {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
115 $result{state} = STATE_INVALID;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
116 } else {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
117 $result{state} = STATE_CORRECT;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
118 my $unit = $self->new($action,\%result);
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
119 $result{result} = $unit->method();
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
120 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
121 } else {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
122 $result{state} = STATE_NEW;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
123 }
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
124
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
125 return \%result;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
126 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
127
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
128 sub loadSchema {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
129 my ($self,$name) = @_;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
130
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
131 if (-f $name) {
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
132 return IMPL::DOM::Schema->LoadSchema($name);
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
133 } else {
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
134 my ($vol,$dir,$file) = File::Spec->splitpath( Class::Inspector->resolved_filename(ref $self || $self) );
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
135
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
136 return IMPL::DOM::Schema->LoadSchema(File::Spec->catfile($vol,$dir,$name));
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
137 }
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
138 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
139
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
140 1;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
141
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
142 __END__
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
143
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
144 =pod
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
145
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
146 =head1 NAME
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
147
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
148 C<IMPL::Web::Application::ControllerUnit> - базовый класс для обработчика транзакций в модели контроллера.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
149
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
150 =head1 DESCRIPTION
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
151
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
152 Классы, наследуемые от данного класса называется пакетом транзакций. Часть методов в таком классе
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
153 объявляются как транзакции при помощи методов C<transaction>, C<form>.
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
154
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
155 Перед выполнением транзакции создается экземпляр объекта, в рамках которого будет выполнена транзакция.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
156 Для этого вызывается метод C<InvokeAction($method,$action)>, который создает/восстанавливает контекст
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
157 транзакции.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
158
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
159 Транзакции на данный момент делятся на простые и формы.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
160
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
161 =head2 Простые транзакции
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
162
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
163 Простые транзакции получаю только запрос, без предварительной обработки, и возвращенный результат напрямую
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
164 передается пользователю.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
165
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
166 =head2 Формы
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
167
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
168 При использовании форм запрос предварительно обрабатывается, для получения DOM документа с данными формы.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
169 Для постороенния DOM документа используется схема. При этом становятся доступны дополнительные свойства
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
170 C<formData>, C<formSchema>, C<formErrors>.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
171
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
172 Результат выполнения транзакции не возвращается напрямую пользователю, а включается в общий ответ, который
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
173 выглядит следующим образом
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
174
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
175 =begin code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
176
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
177 {
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
178 state => '{ new | correct | invalid }',
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
179 result => $transactionResult,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
180 formData => $formDOM,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
181 formSchema => $formSchema,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
182 formErrors => @errors
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
183 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
184
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
185 =end code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
186
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
187 =over
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
188
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
189 =item C<state>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
190
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
191 Состояние верификации формы.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
192
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
193 =over
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
194
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
195 =item C<new>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
196
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
197 Первоначальное содержимое формы, оно может быть некорректным, но это нормально.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
198 В данном состоянии транзакция обычно не выполняется.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
199
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
200 =item C<correct>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
201
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
202 Данные формы корректны, транзакция выполнена, и ее результат доступен через поле C<result>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
203
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
204 =item C<invalid>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
205
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
206 Содержимое формы не прошло верификацию, ошибки доступны через поле C<formErrors>. Транзакция
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
207 не выполнялась.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
208
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
209 =back
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
210
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
211 =item C<result>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
212
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
213 Результат выполнения транзакции, если конечно таковая выполнялась.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
214
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
215 =item C<formData>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
216
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
217 ДОМ документ с данными формами. Документ существует всегда, не зависимо от его корректности,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
218 может быть использован для построения формы, уже заполненную параметрами.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
219
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
220 =item C<formSchema>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
221
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
222 Схема данных формы, может использоваться для построения динамических форм.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
223
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
224 =item C<formErrors>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
225
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
226 Ошибки верификации данных, если таковые были
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
227
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
228 =back
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
229
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
230 =head1 MEMBERS
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
231
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
232 =over
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
233
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
234 =item C<[get] application>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
235
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
236 =item C<[get] query>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
237
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
238 =item C<[get] response>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
239
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
240 =item C<[get] formData>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
241
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
242 =item C<[get] formSchema>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
243
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
244 =item C<[get] formErrors>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
245
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
246 =item C<InvokeAction($method,$action)>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
247
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
248 Конструирует контекст выполнения транзакции, может быть переопределен для конструирования контекста по
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
249 своим правилам.
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
250
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
251 =item C<TransactionWrapper($method,$action,$methodInfo)>
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
252
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
253 Обертка для конструирования простых транзакций, может быть переопределен для конструирования контекста по
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
254 своим правилам.
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
255
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
256 =item C<FormWrapper($method,$action,$methodInfo)>
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
257
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
258 Обертка для конструирования форм, может быть переопределен для конструирования контекста по
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
259 своим правилам.
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
260
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
261 =back
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
262
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
263 =head1 EXAMPLE
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
264
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
265 =begin code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
266
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
267 package MyBooksUnit;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
268 use strict;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
269 use base qw(IMPL::Web::Application::ControllerUnit);
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
270
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
271 __PACKAGE__->PassThroughArgs;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
272
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
273 __PACKAGE__->transactions(qw(
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
274 find
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
275 info
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
276 ));
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
277 __PACKAGE__->forms(
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
278 create => 'books.create.xml'
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
279 );
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
280
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
281 sub find {
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
282 my ($this) = @_;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
283
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
284 return $this->application->dataSource->resultset('Books')->find({author => $this->query->param('author')});
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
285 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
286
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
287 sub info {
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
288 my ($this) = @_;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
289
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
290 return $this->application->dataSource->resultset('Books')->find({id => $this->query->param('id')});
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
291 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
292
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
293 sub create {
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
294 my ($this) = @_;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
295
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
296 my %book = map {
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
297 $_ => $this->formData->selectSingleNode($_)->nodeValue
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
298 } qw(author_id title year ISBN);
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
299
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
300 return $this->application->datasource->resultset('Books')->create(\%book);
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
301 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
302
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
303 =end code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
304
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
305 =cut