Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application.pm @ 62:c64bd1bf727d
Web application
Page query handler
author | wizard |
---|---|
date | Fri, 12 Mar 2010 16:23:46 +0300 |
parents | b0c068da93ac |
children | 76b878ad6596 |
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 | |
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()) { |
62 | 39 my $response = new IMPL::Web::Application::Response(query => $query); |
58 | 40 |
62 | 41 my $action = $this->factoryAction->new( |
42 query => $query, | |
58 | 43 response => $response, |
44 application => $this, | |
45 ); | |
46 | |
47 $action->ChainHandler($_) foreach $this->handlersQuery; | |
48 | |
49 $action->Invoke(); | |
49 | 50 } |
51 } | |
52 | |
57 | 53 { |
54 my $hasFetched = 0; | |
55 | |
56 sub FetchRequest { | |
57 return undef if $hasFetched; | |
58 $hasFetched = 1; | |
59 return CGI->new(); | |
60 } | |
61 } | |
62 | |
49 | 63 1; |
64 | |
52 | 65 __END__ |
66 | |
49 | 67 =pod |
68 | |
69 =head1 SYNOPSIS | |
70 | |
71 require MyApp; | |
59
0f3e369553bd
Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
58
diff
changeset
|
72 MyApp->spawn('app.config')->Run(); |
49 | 73 |
74 =head1 DESCRIPTION | |
75 | |
76 Зкземпляр приложения содержит в себе глобальные настройки, реализует контроллер запросов, | |
52 | 77 в качестве источника запросов используется CGI или иной совместимый модуль. |
49 | 78 |
52 | 79 Процесс обработки запроса состоит из следующих частей |
49 | 80 |
52 | 81 1. Получение cgi запроса |
82 2. Вызов модуля для инициализации объекта действия | |
83 3. Инициализация контекста выполнения | |
84 4. Выполнение запроса | |
85 5. Преобразование полученных данных в тело ответа | |
86 | |
87 | |
88 | |
49 | 89 |
90 =cut |