Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application.pm @ 65:2840c4c85db8
Application configuration improvements
Documentation
author | wizard |
---|---|
date | Tue, 16 Mar 2010 17:36:13 +0300 |
parents | 76b878ad6596 |
children | 9f5795a10939 |
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; |
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 | |
33 $this->factoryAction('IMPL::Web::Application::Action') unless $this->factoryAction; | |
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 | |
62 | 42 my $action = $this->factoryAction->new( |
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 | |
75 require MyApp; | |
59
0f3e369553bd
Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
58
diff
changeset
|
76 MyApp->spawn('app.config')->Run(); |
49 | 77 |
78 =head1 DESCRIPTION | |
79 | |
80 Зкземпляр приложения содержит в себе глобальные настройки, реализует контроллер запросов, | |
52 | 81 в качестве источника запросов используется CGI или иной совместимый модуль. |
49 | 82 |
52 | 83 Процесс обработки запроса состоит из следующих частей |
49 | 84 |
52 | 85 1. Получение cgi запроса |
86 2. Вызов модуля для инициализации объекта действия | |
87 3. Инициализация контекста выполнения | |
88 4. Выполнение запроса | |
89 5. Преобразование полученных данных в тело ответа | |
90 | |
91 | |
92 | |
49 | 93 |
94 =cut |