annotate Lib/IMPL/Web/Application.pm @ 63:76b878ad6596

Added serialization support for the IMPL::Object::List More intelligent Exception message Fixed encoding support in the actions Improoved tests Minor fixes
author wizard
date Mon, 15 Mar 2010 02:38:09 +0300
parents c64bd1bf727d
children 2840c4c85db8
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;
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
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;
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
19 public property options => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
20 }
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 # custom factory
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
23 sub new {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
24 my ($self,$file) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
25
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
26 return $self->LoadXMLFile($file);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
27 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
28
62
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
29 sub CTOR {
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
30 my ($this) = @_;
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
31
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
32 $this->factoryAction('IMPL::Web::Application::Action') unless $this->factoryAction;
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
33 }
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
34
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
35 sub Run {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
36 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
37
58
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
38 while (my $query = $this->FetchRequest()) {
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
39
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
40 # todo: move a creation of the response to the ActionClass
62
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
41 my $action = $this->factoryAction->new(
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
42 query => $query,
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
43 response => new IMPL::Web::Application::Response(query => $query),
58
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
44 application => $this,
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
45 );
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
46
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
47 $action->ChainHandler($_) foreach $this->handlersQuery;
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
48
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
49 $action->Invoke();
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
50
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
51 $action->response->Complete;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
52 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
53 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
54
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
55 {
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
56 my $hasFetched = 0;
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
58 sub FetchRequest {
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
59 return undef if $hasFetched;
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
60 $hasFetched = 1;
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
61 return CGI->new();
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
62 }
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
63 }
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
64
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
65 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
66
52
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
67 __END__
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
68
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
69 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
70
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
71 =head1 SYNOPSIS
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 require MyApp;
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents: 58
diff changeset
74 MyApp->spawn('app.config')->Run();
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
75
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
76 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
77
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
78 Зкземпляр приложения содержит в себе глобальные настройки, реализует контроллер запросов,
52
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
79 в качестве источника запросов используется CGI или иной совместимый модуль.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
80
52
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
81 Процесс обработки запроса состоит из следующих частей
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
82
52
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
83 1. Получение cgi запроса
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
84 2. Вызов модуля для инициализации объекта действия
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
85 3. Инициализация контекста выполнения
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
86 4. Выполнение запроса
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
87 5. Преобразование полученных данных в тело ответа
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
88
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
89
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
92 =cut