Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application.pm @ 63:76b878ad6596
Added serialization support for the IMPL::Object::List
More intelligent Exception message
Fixed encoding support in the actions
Improoved tests
Minor fixes
author | wizard |
---|---|
date | Mon, 15 Mar 2010 02:38:09 +0300 |
parents | c64bd1bf727d |
children | 2840c4c85db8 |
rev | line source |
---|---|
49 | 1 package IMPL::Web::Application; |
2 use strict; | |
3 use warnings; | |
4 | |
60
b0c068da93ac
Lazy activation for the configuration objects (final concept)
wizard
parents:
59
diff
changeset
|
5 use base qw(IMPL::Config IMPL::Object::Singleton); |
58 | 6 |
7 require IMPL::Web::Application::Action; | |
8 require IMPL::Web::Application::Response; | |
9 | |
49 | 10 use IMPL::Class::Property; |
57 | 11 use CGI; |
49 | 12 |
60
b0c068da93ac
Lazy activation for the configuration objects (final concept)
wizard
parents:
59
diff
changeset
|
13 __PACKAGE__->PassThroughArgs; |
b0c068da93ac
Lazy activation for the configuration objects (final concept)
wizard
parents:
59
diff
changeset
|
14 |
49 | 15 BEGIN { |
52 | 16 public property handlerError => prop_all; |
57 | 17 public property factoryAction => prop_all; |
59
0f3e369553bd
Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
58
diff
changeset
|
18 public property handlersQuery => prop_all | prop_list; |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
19 public property options => prop_all; |
49 | 20 } |
21 | |
22 # custom factory | |
23 sub new { | |
24 my ($self,$file) = @_; | |
25 | |
26 return $self->LoadXMLFile($file); | |
27 } | |
28 | |
62 | 29 sub CTOR { |
30 my ($this) = @_; | |
31 | |
32 $this->factoryAction('IMPL::Web::Application::Action') unless $this->factoryAction; | |
33 } | |
34 | |
49 | 35 sub Run { |
36 my ($this) = @_; | |
37 | |
58 | 38 while (my $query = $this->FetchRequest()) { |
39 | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
40 # todo: move a creation of the response to the ActionClass |
62 | 41 my $action = $this->factoryAction->new( |
42 query => $query, | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
43 response => new IMPL::Web::Application::Response(query => $query), |
58 | 44 application => $this, |
45 ); | |
46 | |
47 $action->ChainHandler($_) foreach $this->handlersQuery; | |
48 | |
49 $action->Invoke(); | |
63
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 $action->response->Complete; |
49 | 52 } |
53 } | |
54 | |
57 | 55 { |
56 my $hasFetched = 0; | |
57 | |
58 sub FetchRequest { | |
59 return undef if $hasFetched; | |
60 $hasFetched = 1; | |
61 return CGI->new(); | |
62 } | |
63 } | |
64 | |
49 | 65 1; |
66 | |
52 | 67 __END__ |
68 | |
49 | 69 =pod |
70 | |
71 =head1 SYNOPSIS | |
72 | |
73 require MyApp; | |
59
0f3e369553bd
Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
58
diff
changeset
|
74 MyApp->spawn('app.config')->Run(); |
49 | 75 |
76 =head1 DESCRIPTION | |
77 | |
78 Зкземпляр приложения содержит в себе глобальные настройки, реализует контроллер запросов, | |
52 | 79 в качестве источника запросов используется CGI или иной совместимый модуль. |
49 | 80 |
52 | 81 Процесс обработки запроса состоит из следующих частей |
49 | 82 |
52 | 83 1. Получение cgi запроса |
84 2. Вызов модуля для инициализации объекта действия | |
85 3. Инициализация контекста выполнения | |
86 4. Выполнение запроса | |
87 5. Преобразование полученных данных в тело ответа | |
88 | |
89 | |
90 | |
49 | 91 |
92 =cut |