annotate Lib/IMPL/Web/Application/Action.pm @ 64:259cd3df6e53

Doc generation Minor fixes
author wizard
date Mon, 15 Mar 2010 17:45:13 +0300
parents 76b878ad6596
children 2840c4c85db8
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;
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
14
609b59c9f03c Web application
wizard
parents: 52
diff changeset
15 private property _entryPoint => prop_all;
609b59c9f03c Web application
wizard
parents: 52
diff changeset
16 }
609b59c9f03c Web application
wizard
parents: 52
diff changeset
17
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
18 #todo: make ability to discard old and create new response
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
19
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
20 sub Invoke {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
21 my ($this) = @_;
609b59c9f03c Web application
wizard
parents: 52
diff changeset
22
609b59c9f03c Web application
wizard
parents: 52
diff changeset
23 if ($this->_entryPoint) {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
24 $this->_entryPoint->();
609b59c9f03c Web application
wizard
parents: 52
diff changeset
25 } else {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
26 die new IMPL::InvalidOperationException("At least one handler is required");
609b59c9f03c Web application
wizard
parents: 52
diff changeset
27 }
609b59c9f03c Web application
wizard
parents: 52
diff changeset
28 }
609b59c9f03c Web application
wizard
parents: 52
diff changeset
29
609b59c9f03c Web application
wizard
parents: 52
diff changeset
30 sub ChainHandler {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
31 my ($this,$handler) = @_;
609b59c9f03c Web application
wizard
parents: 52
diff changeset
32
609b59c9f03c Web application
wizard
parents: 52
diff changeset
33 my $delegateNext = $this->_entryPoint();
609b59c9f03c Web application
wizard
parents: 52
diff changeset
34
609b59c9f03c Web application
wizard
parents: 52
diff changeset
35 if (ref $handler eq 'CODE') {
56
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
36 $this->_entryPoint( sub {
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
37 $handler->($this,$delegateNext);
56
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
38 } );
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
39 } elsif (ref $handler and UNIVERSAL::isa($handler,'IMPL::Web::QueryHandler')) {
56
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
40 $this->_entryPoint( sub {
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
41 $handler->Invoke($this,$delegateNext);
56
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
42 } );
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
43 } elsif ($handler and not ref $handler) {
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
44
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
45 if (my $method = $this->can($handler) ) {
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
46 $this->_entryPoint( sub {
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
47 $method->($this,$delegateNext);
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
48 } );
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
49 } else {
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
50 {
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
51 no strict 'refs';
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
52 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
53 }
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
54
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
55 if (UNIVERSAL::isa($handler,'IMPL::Web::QueryHandler')) {
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
56 $this->_entryPoint( sub {
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
57 $handler->Invoke($this,$delegateNext);
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
58 } );
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
59 } else {
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
60 die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler);
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
61 }
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
62 }
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
63 } else {
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
64 die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler);
55
609b59c9f03c Web application
wizard
parents: 52
diff changeset
65 }
609b59c9f03c Web application
wizard
parents: 52
diff changeset
66
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
67 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
68
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
69 1;
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
70
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
71 __END__
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
72
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
73 =pod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
74
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
75 =head1 DESCRIPTION
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
76
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
77 Определяет порядок выполнения запроса.
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
78
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
79 Запрос выполняется последовательным вызовом цепочки обработчиков, при этом обработчики
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
80 сами вызывают следующие.
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
81
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
82 Типичная цепочка может быть такой, в порядке добавления
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
83
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
84 SecCallToMethod($target,$method)
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
85 AuthenticateMethod
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
86 TDocumentOut($file)
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
87
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
88 что приведет к следующей последовательности
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
89
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
90 Action->Invoke() {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
91 TDocumentOut->Invoke($Action,$nextHandler) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
92 my $result = $nextHandler() {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
93 $AuthenticateMethod($Action,$nextHandler) {
62
c64bd1bf727d Web application
wizard
parents: 57
diff changeset
94 my $context = $Action->application->security->Authenticate($Action->query,$Action->response);
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
95 return $context->Impersonate($nextHandler) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
96 $objSecCallToMethod->Invoke($Action,undef) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
97 IMPL::Security->AccessCheck($target,$method);
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
98 return $target->$method();
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
99 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
100 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
101 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
102 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
103 $this->format($result,$Action->response->streamBody);
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
104 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
105 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
106
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
107 или как альтернатива может быть еще
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
108
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
109 $objSecCallToMethod($target,$method)
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
110 $AuthenticateMethod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
111 $TransfromToSimpleData
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
112 $JSONOut
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
113
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
114 В данной цепочке также происходит вызов метода, но его результат потом преобразуется
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
115 в простые структуры и передается JSON преобразователю. Таким образом модулю логики
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
116 не требуется знать о выходном формате, всю работу проделают дополнительные фильтры.
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
117
56
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
118 =head1 HANDLERS
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
119
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
120 =head2 subroutines
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
121
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
122 =over
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
123
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
124 =item CODE ref
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
125
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
126 Ссылка на процедуру может являться обработчиком, при этом функция будет вызвана с
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
127 двумя параметрами: ссылкой на action объект, и точкой входа следующего обработчика.
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
128
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
129 =item Method Name
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
130
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
131 Имя метода, передается в виде строки. У текущего объекта action ищется метод с
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
132 указанным именем, после чего используется ссылка на этот метод для вызова с двумя
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
133 параметрами: ссылкой на action объект, и точкой входа следующего обработчика.
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
134
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
135 Получается вызов идентичный следующему C<< $action->MethodName($nextHandler) >>;
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
136
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
137 =back
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
138
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
139 =head2 C< IMPL::Web::Application::QueryHandler >
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
140
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
141 Любой объект наследованный от C< IMPL::Web::Application::QueryHandler > может быть
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
142 использован в качестве обработчика запроса
bf59ee1cd506 Web application main class functionality
wizard
parents: 56
diff changeset
143
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
144 =cut