Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application.pm @ 60:b0c068da93ac
Lazy activation for the configuration objects (final concept)
small fixes
author | wizard |
---|---|
date | Tue, 09 Mar 2010 19:47:39 +0300 |
parents | 0f3e369553bd |
children | c64bd1bf727d |
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; |
60
b0c068da93ac
Lazy activation for the configuration objects (final concept)
wizard
parents:
59
diff
changeset
|
19 public property configuration => prop_all; |
49 | 20 } |
21 | |
22 # custom factory | |
23 sub new { | |
24 my ($self,$file) = @_; | |
25 | |
26 return $self->LoadXMLFile($file); | |
27 } | |
28 | |
29 sub Run { | |
30 my ($this) = @_; | |
31 | |
58 | 32 while (my $query = $this->FetchRequest()) { |
33 my $response = new IMPL::Web::Application::Response(request => $query); | |
34 | |
35 my $action = new IMPL::Web::Application::Action( | |
36 request => $query, | |
37 response => $response, | |
38 application => $this, | |
39 ); | |
40 | |
41 $action->ChainHandler($_) foreach $this->handlersQuery; | |
42 | |
43 $action->Invoke(); | |
49 | 44 } |
45 } | |
46 | |
57 | 47 { |
48 my $hasFetched = 0; | |
49 | |
50 sub FetchRequest { | |
51 return undef if $hasFetched; | |
52 $hasFetched = 1; | |
53 return CGI->new(); | |
54 } | |
55 } | |
56 | |
49 | 57 1; |
58 | |
52 | 59 __END__ |
60 | |
49 | 61 =pod |
62 | |
63 =head1 SYNOPSIS | |
64 | |
65 require MyApp; | |
59
0f3e369553bd
Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
58
diff
changeset
|
66 MyApp->spawn('app.config')->Run(); |
49 | 67 |
68 =head1 DESCRIPTION | |
69 | |
70 Зкземпляр приложения содержит в себе глобальные настройки, реализует контроллер запросов, | |
52 | 71 в качестве источника запросов используется CGI или иной совместимый модуль. |
49 | 72 |
52 | 73 Процесс обработки запроса состоит из следующих частей |
49 | 74 |
52 | 75 1. Получение cgi запроса |
76 2. Вызов модуля для инициализации объекта действия | |
77 3. Инициализация контекста выполнения | |
78 4. Выполнение запроса | |
79 5. Преобразование полученных данных в тело ответа | |
80 | |
81 | |
82 | |
49 | 83 |
84 =cut |