annotate Lib/IMPL/Web/Application/Action.pm @ 55:609b59c9f03c

Web application rewrote prop_list implementation to support IMPL::Object::List
author wizard
date Wed, 03 Mar 2010 17:40:18 +0300
parents 15d720913562
children 117b6956d5a5
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 $delegate;
609b59c9f03c Web application
wizard
parents: 52
diff changeset
30
609b59c9f03c Web application
wizard
parents: 52
diff changeset
31 my $delegateNext = $this->_entryPoint();
609b59c9f03c Web application
wizard
parents: 52
diff changeset
32
609b59c9f03c Web application
wizard
parents: 52
diff changeset
33 if (ref $handler eq 'CODE') {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
34 $delegate = sub {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
35 $handler->($this,$delegateNext);
609b59c9f03c Web application
wizard
parents: 52
diff changeset
36 };
609b59c9f03c Web application
wizard
parents: 52
diff changeset
37 } elsif (UNIVERSAL::isa($handler,'IMPL::Web::Application::QueryHandler')) {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
38 $delegate = sub {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
39 $handler->Invoke($this,$delegateNext);
609b59c9f03c Web application
wizard
parents: 52
diff changeset
40 }
609b59c9f03c Web application
wizard
parents: 52
diff changeset
41 } else {
609b59c9f03c Web application
wizard
parents: 52
diff changeset
42 die new IMPL::InvalidArgumentException("An invalid handler supplied");
609b59c9f03c Web application
wizard
parents: 52
diff changeset
43 }
609b59c9f03c Web application
wizard
parents: 52
diff changeset
44
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
45 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
46
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
47 1;
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
48
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
49 __END__
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
50
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
51 =pod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
53 =head1 DESCRIPTION
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
54
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
55 Определяет порядок выполнения запроса, форматирует результат, инициализирует контекст.
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
56
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
57 Объект создается обработчиком запросов, таким как C<IMPL::Web::Application::UriController>.
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
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 $objSecCallToMethod($target,$method)
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
65 $AuthenticateMethod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
66 $TDocumentOut($file)
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
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
70 Action->Invoke() {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
71 TDocumentOut->Invoke($Action,$nextHandler) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
72 my $result = $nextHandler() {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
73 $AuthenticateMethod($Action,$nextHandler) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
74 my $context = $Action->application->security->Authenticate($Action->request,$Action->response);
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
75 return $context->Impersonate($nextHandler) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
76 $objSecCallToMethod->Invoke($Action,undef) {
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
77 IMPL::Security->AccessCheck($target,$method);
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
78 return $target->$method();
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
79 }
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
80 }
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 $this->format($result,$Action->response->streamBody);
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 или как альтернатива может быть еще
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
88
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
89 $objSecCallToMethod($target,$method)
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
90 $AuthenticateMethod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
91 $TransfromToSimpleData
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
92 $JSONOut
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
93
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
94 В данной цепочке также происходит вызов метода, но его результат потом преобразуется
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
95 в простые структуры и передается JSON преобразователю. Таким образом модулю логики
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 =cut