Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/Action.pm @ 98:00d88c5e8203
minor changes
author | wizard |
---|---|
date | Wed, 05 May 2010 01:07:31 +0400 (2010-05-04) |
parents | 9f5795a10939 |
children | b56ebc31bf18 |
rev | line source |
---|---|
52 | 1 package IMPL::Web::Application::Action; |
55 | 2 use strict; |
52 | 3 |
62 | 4 use base qw(IMPL::Object IMPL::Object::Autofill); |
52 | 5 |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
6 __PACKAGE__->PassThroughArgs; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
7 |
52 | 8 use IMPL::Class::Property; |
9 | |
10 BEGIN { | |
11 public property application => prop_get | owner_set; | |
62 | 12 public property query => prop_get | owner_set; |
52 | 13 public property response => prop_get | owner_set; |
65 | 14 public property responseFactory => prop_get | owner_set; |
55 | 15 |
16 private property _entryPoint => prop_all; | |
17 } | |
18 | |
65 | 19 sub CTOR { |
20 my ($this) = @_; | |
21 | |
22 $this->responseFactory('IMPL::Web::Application::Response') unless $this->responseFactory; | |
23 $this->response( $this->responseFactory->new(query => $this->query) ); | |
24 } | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
25 |
55 | 26 sub Invoke { |
27 my ($this) = @_; | |
28 | |
29 if ($this->_entryPoint) { | |
30 $this->_entryPoint->(); | |
31 } else { | |
32 die new IMPL::InvalidOperationException("At least one handler is required"); | |
33 } | |
34 } | |
35 | |
65 | 36 sub ReinitResponse { |
37 my ($this) = @_; | |
38 | |
39 die new IMPL::InvalidOperationException("Response already sent") if $this->response->isHeaderPrinted; | |
40 | |
41 $this->response->Discard; | |
42 $this->response($this->responseFactory->new(query => $this->query)); | |
43 } | |
44 | |
55 | 45 sub ChainHandler { |
46 my ($this,$handler) = @_; | |
47 | |
48 my $delegateNext = $this->_entryPoint(); | |
49 | |
50 if (ref $handler eq 'CODE') { | |
56 | 51 $this->_entryPoint( sub { |
55 | 52 $handler->($this,$delegateNext); |
56 | 53 } ); |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
54 } elsif (ref $handler and UNIVERSAL::isa($handler,'IMPL::Web::QueryHandler')) { |
56 | 55 $this->_entryPoint( sub { |
55 | 56 $handler->Invoke($this,$delegateNext); |
56 | 57 } ); |
58 } elsif ($handler and not ref $handler) { | |
59 | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
60 if (my $method = $this->can($handler) ) { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
61 $this->_entryPoint( sub { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
62 $method->($this,$delegateNext); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
63 } ); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
64 } else { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
65 { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
66 no strict 'refs'; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
67 eval "require $handler; 1;" or die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler,"Failed to load module") unless keys %{"${handler}::"}; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
68 } |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
69 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
70 if (UNIVERSAL::isa($handler,'IMPL::Web::QueryHandler')) { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
71 $this->_entryPoint( sub { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
72 $handler->Invoke($this,$delegateNext); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
73 } ); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
74 } else { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
75 die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
76 } |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
77 } |
55 | 78 } else { |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
79 die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler); |
55 | 80 } |
81 | |
52 | 82 } |
83 | |
84 1; | |
85 | |
86 __END__ | |
87 | |
88 =pod | |
89 | |
67 | 90 =head1 NAME |
91 | |
92 C<IMPL::Web::Application::Action> - ������� ������ C<CGI> �������. | |
93 | |
52 | 94 =head1 DESCRIPTION |
95 | |
67 | 96 C<[Infrastructure]> |
52 | 97 |
67 | 98 ���������� ������� ���������� �������. ������ ����������� ���������������� ������� |
99 ������� ������������, ��� ���� ����������� ���� �������� ���������. | |
100 ����������� ����������� � �������, �������� �� ����������. | |
52 | 101 |
102 �������� ������� ����� ���� �����, � ������� ���������� | |
103 | |
67 | 104 =begin code |
105 | |
106 IMPL::Web::QueryHandler::SecCallToMethod | |
107 IMPL::Web::QueryHandler::AuthenticateCookie | |
108 IMPL::Web::QueryHandler::PageFormat | |
109 | |
110 =end code | |
52 | 111 |
112 ��� �������� � ��������� ������������������ | |
113 | |
67 | 114 =begin code |
115 | |
116 # the application creates a new Action object | |
117 | |
118 my $action = $application->actionFactory->new( | |
119 action => $application, # the application passes self | |
120 query => $query # current CGI query | |
121 ); | |
122 | |
123 # forms query handlers stack | |
124 | |
125 $action->ChainHandler($_) foreach qw ( | |
126 IMPL::Web::QueryHandler::SecCallToMethod | |
127 IMPL::Web::QueryHandler::AuthenticateCookie | |
128 IMPL::Web::QueryHandler::PageFormat | |
129 ); | |
130 | |
131 # and finally invokes the action | |
132 | |
133 $action->Invoke() { | |
134 | |
135 # some internals | |
136 | |
137 IMPL::Web::QueryHandler::PageFormat->Invoke($action,$nextHandlerIsAuthHandler) { | |
138 | |
139 #some internals | |
140 | |
141 my $result = $nextHandlerIsAuthHandler() { | |
142 | |
143 # some internals | |
144 | |
145 IMPL::Web::QueryHandler::AuthenticateCookie->Invoke($action,$nextHandlerIsSecCall) { | |
146 | |
147 # some internals | |
148 # do auth and generate security $context | |
149 | |
150 # impersonate $context and call the next handler | |
151 return $context->Impersonate($nextHandlerIsSecCall) { | |
152 | |
153 # some internals | |
154 | |
155 IMPL::Web::QueryHandler::SecCallToMethod->Invoke($action,undef) { | |
156 | |
157 # next handler isn't present as it is the last hanler | |
158 | |
159 # some internals | |
160 # calculate the $method and the $target from CGI request | |
161 | |
52 | 162 IMPL::Security->AccessCheck($target,$method); |
163 return $target->$method(); | |
67 | 164 |
52 | 165 } |
67 | 166 |
52 | 167 } |
67 | 168 |
52 | 169 } |
170 } | |
67 | 171 |
172 # some intenals | |
173 # formatted output to $action->response->streamBody | |
52 | 174 } |
175 } | |
176 | |
67 | 177 =end code |
178 | |
52 | 179 ��� ��� ������������ ����� ���� ��� |
180 | |
67 | 181 =begin code |
182 | |
183 IMPL::Web::QueryHandler::SecCallToMethod | |
184 IMPL::Web::QueryHandler::AuthenticateCookie | |
185 IMPL::Web::QueryHandler::Filter->new( target => IMPL::Transform::ObjectToJSON->new() , method => 'Transform') | |
186 IMLP::Web::QueryHandler::JSONFormat | |
187 | |
188 | |
189 =end code | |
52 | 190 |
191 � ������ ������� ����� ���������� ����� ������, �� ��� ��������� ����� ������������� | |
192 � ������� ��������� � ���������� JSON ���������������. ����� ������� ������ ������ | |
193 �� ��������� ����� � �������� �������, ��� ������ ��������� �������������� �������. | |
194 | |
67 | 195 =head1 MEMBERS |
196 | |
197 =head2 PROPERTIES | |
198 | |
199 =over | |
200 | |
201 =item C< [get] application> | |
202 | |
203 ��������� ���������� ���������� ������� ������ | |
204 | |
205 =item C< [get] query > | |
206 | |
207 ��������� C<CGI> ������� | |
208 | |
209 =item C< [get] response > | |
210 | |
211 ����� �� C<CGI> ������� C<IMPL::Web::Application::Response> | |
212 | |
213 =item C< [get] responseFactory > | |
214 | |
215 ������� ������� �� ������, ������������ ��� �������� ������ ������ | |
216 ���� ��� ��������������� �������� ������� C<IMPL::Web::Application::Action>, | |
217 ���� ��� ������ ������ C<ReinitResponse> � �������� �������. | |
218 | |
219 �� ��������� ����� �������� C<IMPL::Web::Application::Response> | |
220 | |
221 =back | |
222 | |
223 =head2 METHODS | |
224 | |
225 =over | |
226 | |
227 =item C< ReinitResponse() > | |
228 | |
229 ������ ������� ������ C<response> � �������� ������ ���� ������. | |
230 | |
231 ������ �������� ������ ���������� ��� ��������� ������, ����� | |
232 ��� �������������� ����� ��������� ��������. ������� ��������, | |
233 ��� ��� �������� �� ��������, ���� ����� �������� ��� ��������� | |
234 ��������� �������. ����� ��������� ���������� C<IMPL::InvalidOperationException>. | |
235 | |
236 =item C< ChainHandler($handler) > | |
237 | |
238 ��������� ����� ���������� � �������. ���������� ������� ���������� � �����, | |
239 ������ ��������� ����������� ����� �������� ������. | |
240 | |
241 =back | |
242 | |
56 | 243 =head1 HANDLERS |
244 | |
245 =head2 subroutines | |
246 | |
247 =over | |
248 | |
249 =item CODE ref | |
250 | |
251 ������ �� ��������� ����� �������� ������������, ��� ���� ������� ����� ������� � | |
252 ����� �����������: ������� �� action ������, � ������ ����� ���������� �����������. | |
253 | |
254 =item Method Name | |
255 | |
256 ��� ������, ���������� � ���� ������. � �������� ������� action ������ ����� � | |
257 ��������� ������, ����� ���� ������������ ������ �� ���� ����� ��� ������ � ����� | |
258 �����������: ������� �� action ������, � ������ ����� ���������� �����������. | |
259 | |
260 ���������� ����� ���������� ���������� C<< $action->MethodName($nextHandler) >>; | |
261 | |
262 =back | |
263 | |
67 | 264 =head2 C< IMPL::Web::QueryHandler > |
57 | 265 |
67 | 266 ����� ������ ������������� �� C< IMPL::Web::QueryHandler > ����� ���� |
57 | 267 ����������� � �������� ����������� ������� |
268 | |
52 | 269 =cut |