annotate Lib/IMPL/Web/Application/Action.pm @ 62:c64bd1bf727d

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