annotate Lib/IMPL/Web/Application/Action.pm @ 65:2840c4c85db8

Application configuration improvements Documentation
author wizard
date Tue, 16 Mar 2010 17:36:13 +0300
parents 76b878ad6596
children 9f5795a10939
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
1 package IMPL::Web::Application::Action;
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
2 use strict;
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
3
62
c64bd1bf727d Web application
wizard
parents: 57
diff changeset
4 use base qw(IMPL::Object IMPL::Object::Autofill);
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
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
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
8 use IMPL::Class::Property;
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
9
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
10 BEGIN {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
11 public property application => prop_get | owner_set;
62
c64bd1bf727d Web application
wizard
parents: 57
diff changeset
12 public property query => prop_get | owner_set;
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
13 public property response => prop_get | owner_set;
65
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
14 public property responseFactory => prop_get | owner_set;
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
15
609b59c9f03c Web application
wizard
parents: 52
diff changeset
16 private property _entryPoint => prop_all;
609b59c9f03c Web application
wizard
parents: 52
diff changeset
17 }
609b59c9f03c Web application
wizard
parents: 52
diff changeset
18
65
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
19 sub CTOR {
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
20 my ($this) = @_;
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
21
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
22 $this->responseFactory('IMPL::Web::Application::Response') unless $this->responseFactory;
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
23 $this->response( $this->responseFactory->new(query => $this->query) );
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
24 }
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
25
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
26 sub Invoke {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
27 my ($this) = @_;
609b59c9f03c Web application
wizard
parents: 52
diff changeset
28
609b59c9f03c Web application
wizard
parents: 52
diff changeset
29 if ($this->_entryPoint) {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
30 $this->_entryPoint->();
609b59c9f03c Web application
wizard
parents: 52
diff changeset
31 } else {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
32 die new IMPL::InvalidOperationException("At least one handler is required");
609b59c9f03c Web application
wizard
parents: 52
diff changeset
33 }
609b59c9f03c Web application
wizard
parents: 52
diff changeset
34 }
609b59c9f03c Web application
wizard
parents: 52
diff changeset
35
65
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
36 sub ReinitResponse {
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
37 my ($this) = @_;
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
38
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
39 die new IMPL::InvalidOperationException("Response already sent") if $this->response->isHeaderPrinted;
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
40
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
41 $this->response->Discard;
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
42 $this->response($this->responseFactory->new(query => $this->query));
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
43 }
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
44
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
45 sub ChainHandler {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
46 my ($this,$handler) = @_;
609b59c9f03c Web application
wizard
parents: 52
diff changeset
47
609b59c9f03c Web application
wizard
parents: 52
diff changeset
48 my $delegateNext = $this->_entryPoint();
609b59c9f03c Web application
wizard
parents: 52
diff changeset
49
609b59c9f03c Web application
wizard
parents: 52
diff changeset
50 if (ref $handler eq 'CODE') {
56
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
51 $this->_entryPoint( sub {
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
52 $handler->($this,$delegateNext);
56
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
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
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
55 $this->_entryPoint( sub {
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
56 $handler->Invoke($this,$delegateNext);
56
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
57 } );
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
58 } elsif ($handler and not ref $handler) {
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
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
609b59c9f03c Web application
wizard
parents: 52
diff changeset
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
609b59c9f03c Web application
wizard
parents: 52
diff changeset
80 }
609b59c9f03c Web application
wizard
parents: 52
diff changeset
81
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
82 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
83
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
84 1;
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
85
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
86 __END__
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
87
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
88 =pod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
89
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
90 =head1 DESCRIPTION
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
91
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
92 Определяет порядок выполнения запроса.
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
93
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
94 Запрос выполняется последовательным вызовом цепочки обработчиков, при этом обработчики
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
95 сами вызывают следующие.
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
96
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
97 Типичная цепочка может быть такой, в порядке добавления
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
98
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
99 SecCallToMethod($target,$method)
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
100 AuthenticateMethod
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
101 TDocumentOut($file)
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
102
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
103 что приведет к следующей последовательности
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
104
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
105 Action->Invoke() {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
106 TDocumentOut->Invoke($Action,$nextHandler) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
107 my $result = $nextHandler() {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
108 $AuthenticateMethod($Action,$nextHandler) {
62
c64bd1bf727d Web application
wizard
parents: 57
diff changeset
109 my $context = $Action->application->security->Authenticate($Action->query,$Action->response);
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
110 return $context->Impersonate($nextHandler) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
111 $objSecCallToMethod->Invoke($Action,undef) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
112 IMPL::Security->AccessCheck($target,$method);
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
113 return $target->$method();
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
114 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
115 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
116 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
117 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
118 $this->format($result,$Action->response->streamBody);
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
119 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
120 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
121
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
122 или как альтернатива может быть еще
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
123
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
124 $objSecCallToMethod($target,$method)
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
125 $AuthenticateMethod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
126 $TransfromToSimpleData
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
127 $JSONOut
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
128
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
129 В данной цепочке также происходит вызов метода, но его результат потом преобразуется
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
130 в простые структуры и передается JSON преобразователю. Таким образом модулю логики
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
131 не требуется знать о выходном формате, всю работу проделают дополнительные фильтры.
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
132
56
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
133 =head1 HANDLERS
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
134
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
135 =head2 subroutines
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
136
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
137 =over
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
138
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
139 =item CODE ref
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
140
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
141 Ссылка на процедуру может являться обработчиком, при этом функция будет вызвана с
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
142 двумя параметрами: ссылкой на action объект, и точкой входа следующего обработчика.
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
143
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
144 =item Method Name
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
145
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
146 Имя метода, передается в виде строки. У текущего объекта action ищется метод с
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
147 указанным именем, после чего используется ссылка на этот метод для вызова с двумя
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
148 параметрами: ссылкой на action объект, и точкой входа следующего обработчика.
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
149
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
150 Получается вызов идентичный следующему C<< $action->MethodName($nextHandler) >>;
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
151
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
152 =back
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
153
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
154 =head2 C< IMPL::Web::Application::QueryHandler >
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
155
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
156 Любой объект наследованный от C< IMPL::Web::Application::QueryHandler > может быть
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
157 использован в качестве обработчика запроса
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
158
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
159 =cut