Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application.pm @ 70:2dfb0b0ad12f
More docs
author | wizard |
---|---|
date | Wed, 24 Mar 2010 17:42:04 +0300 |
parents | 9f5795a10939 |
children | 2f31ecabe9ea |
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; |
67 | 17 public property actionFactory => 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; |
65 | 19 public property responseCharset => prop_all; |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
20 public property options => prop_all; |
49 | 21 } |
22 | |
23 # custom factory | |
24 sub new { | |
25 my ($self,$file) = @_; | |
26 | |
27 return $self->LoadXMLFile($file); | |
28 } | |
29 | |
62 | 30 sub CTOR { |
31 my ($this) = @_; | |
32 | |
67 | 33 $this->actionFactory('IMPL::Web::Application::Action') unless $this->actionFactory; |
65 | 34 $this->responseCharset('utf-8') unless $this->responseCharset; |
62 | 35 } |
36 | |
49 | 37 sub Run { |
38 my ($this) = @_; | |
39 | |
58 | 40 while (my $query = $this->FetchRequest()) { |
41 | |
67 | 42 my $action = $this->actionFactory->new( |
62 | 43 query => $query, |
58 | 44 application => $this, |
65 | 45 ); |
46 | |
47 $action->response->charset($this->responseCharset); | |
58 | 48 |
49 $action->ChainHandler($_) foreach $this->handlersQuery; | |
50 | |
51 $action->Invoke(); | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
52 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
53 $action->response->Complete; |
49 | 54 } |
55 } | |
56 | |
57 | 57 { |
58 my $hasFetched = 0; | |
59 | |
60 sub FetchRequest { | |
61 return undef if $hasFetched; | |
62 $hasFetched = 1; | |
63 return CGI->new(); | |
64 } | |
65 } | |
66 | |
49 | 67 1; |
68 | |
52 | 69 __END__ |
70 | |
49 | 71 =pod |
72 | |
73 =head1 SYNOPSIS | |
74 | |
67 | 75 =begin code |
76 | |
49 | 77 require MyApp; |
67 | 78 |
79 my $instance = spawn MyApp('app.config'); | |
80 | |
81 $instance->Run(); | |
82 | |
83 =end code | |
49 | 84 |
85 =head1 DESCRIPTION | |
86 | |
87 Зкземпляр приложения содержит в себе глобальные настройки, реализует контроллер запросов, | |
52 | 88 в качестве источника запросов используется CGI или иной совместимый модуль. |
49 | 89 |
52 | 90 Процесс обработки запроса состоит из следующих частей |
49 | 91 |
67 | 92 =over |
93 | |
94 =item 1 | |
95 | |
96 Получение cgi запроса | |
97 | |
98 =item 2 | |
52 | 99 |
67 | 100 Создание объекта C<IMPL::Web::Application::Action> |
52 | 101 |
67 | 102 =item 3 |
52 | 103 |
67 | 104 Формирование цепочки вызовов при помощи C<< IMPL::Web::Application::Action->ChainHandler >> |
105 | |
106 =item 4 | |
107 | |
108 Выполнение запроса C<< IMPL::Web::Application::Action->Invoke >> | |
49 | 109 |
110 =cut | |
67 | 111 |
112 Также приложение поддерживает отложенное создание объектов, которые по первому обращению | |
113 к свойствам. Это реализовано в базовом классе C< IMPL::Configuration >. Для настройки | |
114 активаторов можно использовать свойство C<options>, в которое должен быть помещен хеш | |
115 со ссылками на активаторы, см. пример ниже C<CONFIGURATION>. | |
116 | |
117 =head2 CONFIGURATION | |
118 | |
119 Ниже приведен пример конфигурации приложения | |
120 | |
121 =begin code xml | |
122 | |
123 <?xml version="1.0" encoding="UTF-8"?> | |
124 <Application id='app' type="Test::Web::Application::Instance"> | |
125 | |
126 <!-- Begin custom properties --> | |
127 <name>Sample application</name> | |
128 <dataSource type='IMPL::Config::Activator' id='ds'> | |
129 <factory>IMPL::Object</factory> | |
130 <parameters type='HASH'> | |
131 <db>data</db> | |
132 <user>nobody</user> | |
133 </parameters> | |
134 </dataSource> | |
135 <securityMod type='IMPL::Config::Activator'> | |
136 <factory>IMPL::Object</factory> | |
137 <parameters type='HASH'> | |
138 <ds refid='ds'/> | |
139 </parameters> | |
140 </securityMod> | |
141 <!-- End custom properties --> | |
142 | |
143 <!-- direct access to the activators --> | |
144 <options type="HASH"> | |
145 <dataSource refid='ds'/> | |
146 </options> | |
147 | |
148 <!-- Set default output encoding, can be changed due query handling --> | |
149 <responseCharset>utf-8</responseCharset> | |
150 | |
151 <!-- Actions creation configuration --> | |
152 <actionFactory type="IMPL::Object::Factory"> | |
153 | |
154 <!-- Construct actions --> | |
155 <factory>IMPL::Web::Application::Action</factory> | |
156 <parameters type='HASH'> | |
157 | |
158 <!-- with special responseFactory --> | |
159 <responseFactory type='IMPL::Object::Factory'> | |
160 | |
161 <!-- Where resopnses have a special streamOut --> | |
162 <factory>IMPL::Web::Application::Response</factory> | |
163 <parameters type='HASH'> | |
164 | |
165 <!-- in memory dummy output instead of STDOUT --> | |
166 <streamOut>memory</streamOut> | |
167 | |
168 </parameters> | |
169 </responseFactory> | |
170 </parameters> | |
171 </actionFactory> | |
172 | |
173 <!-- Query processing chain --> | |
174 <handlersQuery type="IMPL::Object::List"> | |
175 <item type="IMPL::Web::QueryHandler::PageFormat"> | |
176 <templatesCharset>cp1251</templatesCharset> | |
177 </item> | |
178 </handlersQuery> | |
179 </Application> | |
180 | |
181 =end code xml | |
182 |