annotate Lib/IMPL/Web/Application/Action.pm @ 56:117b6956d5a5

Web application in progress
author wizard
date Thu, 04 Mar 2010 15:46:17 +0300
parents 609b59c9f03c
children bf59ee1cd506
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
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
4 use base qw(IMPL::Object);
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;
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
10 public property request => prop_get | owner_set;
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
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
59 Определяет порядок выполнения запроса, форматирует результат, инициализирует контекст.
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
60
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
61 Объект создается обработчиком запросов, таким как C<IMPL::Web::Application::UriController>.
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
62 При этом формируется цепочка обработчиков запроса, эта цапочка будет выполняться с последнего добавленного,
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
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
66 Типичная цепочка может быть такой, в порядке добавления
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
67
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
68 $objSecCallToMethod($target,$method)
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
69 $AuthenticateMethod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
70 $TDocumentOut($file)
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
71
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
72 что приведет к следующей последовательности
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
73
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
74 Action->Invoke() {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
75 TDocumentOut->Invoke($Action,$nextHandler) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
76 my $result = $nextHandler() {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
77 $AuthenticateMethod($Action,$nextHandler) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
78 my $context = $Action->application->security->Authenticate($Action->request,$Action->response);
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
79 return $context->Impersonate($nextHandler) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
80 $objSecCallToMethod->Invoke($Action,undef) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
81 IMPL::Security->AccessCheck($target,$method);
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
82 return $target->$method();
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 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
86 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
87 $this->format($result,$Action->response->streamBody);
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 или как альтернатива может быть еще
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
92
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
93 $objSecCallToMethod($target,$method)
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
94 $AuthenticateMethod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
95 $TransfromToSimpleData
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
96 $JSONOut
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
97
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
98 В данной цепочке также происходит вызов метода, но его результат потом преобразуется
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
99 в простые структуры и передается JSON преобразователю. Таким образом модулю логики
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
100 не требуется знать о выходном формате, всю работу проделают дополнительные фильтры.
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
101
56
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
102 =head1 HANDLERS
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
103
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
104 =head2 subroutines
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
105
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
106 =over
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
107
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
108 =item CODE ref
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
109
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
110 Ссылка на процедуру может являться обработчиком, при этом функция будет вызвана с
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
111 двумя параметрами: ссылкой на action объект, и точкой входа следующего обработчика.
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
112
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
113 =item Method Name
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 параметрами: ссылкой на action объект, и точкой входа следующего обработчика.
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
118
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
119 Получается вызов идентичный следующему C<< $action->MethodName($nextHandler) >>;
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
120
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
121 =back
117b6956d5a5 Web application in progress
wizard
parents: 55
diff changeset
122
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
123 =cut