annotate Lib/IMPL/Web/Application.pm @ 68:739f1288ca84

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