annotate Lib/IMPL/Web/Application.pm @ 212:292226770180

bugfixes
author sergey
date Fri, 29 Jun 2012 19:24:15 +0400
parents 2ffe6f661605
children d6e2ea24af08
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
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
5 use IMPL::lang qw(:declare :constants);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
6 use CGI;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
7 use Carp qw(carp);
58
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
8
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
9 use IMPL::declare {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
10 require => {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
11 TAction => 'IMPL::Web::Application::Action',
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
12 TResponse => 'IMPL::Web::Application::Response',
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
13 TFactory => '-IMPL::Object::Factory'
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
14 },
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
15 base => {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
16 'IMPL::Config' => '@_',
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
17 'IMPL::Object::Singleton' => '@_'
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
18 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
19 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
20
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
21 BEGIN {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
22 public property handlerError => PROP_ALL;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
23 public property actionFactory => PROP_ALL;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
24 public property handlers => PROP_ALL | PROP_LIST;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
25 public property responseCharset => PROP_ALL;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
26 public property security => PROP_ALL;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
27 public property options => PROP_ALL;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
28 public property fetchRequestMethod => PROP_ALL;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
29 }
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
30
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
31
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
32 #TODO: remove
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
33 sub handlersQuery {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
34 carp "handlersQuery is obsolete use handlers instead";
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
35 goto &handlers;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
36 }
170
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
37
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
38
62
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
39 sub CTOR {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
40 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
41
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
42 die IMPL::InvalidArgumentException->new("handlers","At least one handler should be supplied") unless $this->handlers->Count;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
43
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
44 $this->actionFactory(TAction) unless $this->actionFactory;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
45 $this->responseCharset('utf-8') unless $this->responseCharset;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
46 $this->fetchRequestMethod(\&defaultFetchRequest) unless $this->fetchRequestMethod;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
47 $this->handlerError(\&defaultHandlerError) unless $this->handlerError;
62
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
48 }
c64bd1bf727d Web application
wizard
parents: 60
diff changeset
49
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
50 sub Run {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
51 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
52
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
53 my $handler;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
54
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
55 $handler = _ChainHandler($_,$handler) foreach $this->handlers;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
56
58
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
57 while (my $query = $this->FetchRequest()) {
a35b60b16a99 Configuration, late activation
wizard
parents: 57
diff changeset
58
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
59 my $action = $this->actionFactory->new(
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
60 query => $query,
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
61 application => $this,
65
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
62 );
2840c4c85db8 Application configuration improvements
wizard
parents: 63
diff changeset
63
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
64 eval {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
65 $action->response->charset($this->responseCharset);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
66
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
67 $handler->($action);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
68
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
69 $action->response->Complete;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
70 };
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
71 if ($@) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
72 my $e = $@;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
73 # we are expecting this method to be safe otherwise we can trust nothing in this wolrd
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
74 $this->handlerError()->($this,$action,$e);
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
75 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
76 }
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
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
79 sub _ChainHandler {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
80 my ($handler,$next) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
81
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
82 if (ref $handler eq 'CODE') {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
83 return sub {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
84 my ($action) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
85 return $handler->($action,$next);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
86 };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
87 } elsif (eval { $handler->can('Invoke') } ) {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
88 return sub {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
89 my ($action) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
90 return $handler->Invoke($action,$next);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
91 };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
92 } elsif (eval{ $handler->isa(TFactory) }) {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
93 return sub {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
94 my ($action) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
95 my $inst = $handler->new();
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
96 return $inst->Invoke($action,$next);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
97 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
98 } elsif ($handler and not ref $handler and $handler =~ m/^(-)?(\w+(?:::\w+)*)$/) {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
99 my $class = $2;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
100 if (not $1) {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
101 my $mod = $class;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
102 $mod =~ s/::/\//g;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
103 require "$mod.pm";
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
104
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
105 die IMPL::InvalidArgumentException->("An invalid handler supplied",$handler) unless $class->can('Invoke');
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
106 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
107
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
108 return sub {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
109 my ($action) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
110 my $inst = $class->new();
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
111 return $inst->Invoke($action,$next);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
112 };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
113 } else {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
114 die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
115 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
116 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 194
diff changeset
117
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
118 sub FetchRequest {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
119 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
120
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
121 if( ref $this->fetchRequestMethod eq 'CODE' ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
122 return $this->fetchRequestMethod->($this);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
123 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
124 die new IMPL::Exception("Unknown fetchRequestMethod type",ref $this->fetchRequestMethod);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
125 }
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
126 }
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
127
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
128 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
129 my $hasFetched = 0;
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
130
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
131 sub defaultFetchRequest {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
132 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
133 return undef if $hasFetched;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
134 $hasFetched = 1;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
135 my $query = CGIWrapper->new();
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
136 $query->charset($this->responseCharset);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
137 return $query;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
138 }
57
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
139 }
bf59ee1cd506 Web application main class functionality
wizard
parents: 52
diff changeset
140
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
141 sub defaultHandlerError {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
142 my ($this,$action,$e) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
143 warn $e;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
144 if ( eval { $action->ReinitResponse(); 1; } ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
145 $action->response->contentType('text/plain');
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
146 $action->response->charset($this->responseCharset);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
147 $action->response->status(500);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
148 my $hout = $action->response->streamBody;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
149 print $hout $e;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
150 $action->response->Complete();
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
151 }
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
152 }
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
153
130
06a34c197b05 Added support for utf-8 and old versions of CGI module
wizard
parents: 129
diff changeset
154 package CGIWrapper;
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 138
diff changeset
155 use parent qw(CGI);
130
06a34c197b05 Added support for utf-8 and old versions of CGI module
wizard
parents: 129
diff changeset
156
06a34c197b05 Added support for utf-8 and old versions of CGI module
wizard
parents: 129
diff changeset
157 use Encode;
06a34c197b05 Added support for utf-8 and old versions of CGI module
wizard
parents: 129
diff changeset
158
138
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 130
diff changeset
159 our $NO_DECODE = 0;
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 130
diff changeset
160
130
06a34c197b05 Added support for utf-8 and old versions of CGI module
wizard
parents: 129
diff changeset
161 sub param {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
162 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
163
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
164 return $this->SUPER::param(@_) if $NO_DECODE;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
165
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
166 if (wantarray) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
167 my @result = $this->SUPER::param(@_);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
168
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
169 return map Encode::is_utf8($_) ? $_ : Encode::decode($this->charset,$_,Encode::LEAVE_SRC), @result;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
170 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
171 my $result = $this->SUPER::param(@_);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
172
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
173 return Encode::is_utf8($result) ? $result : Encode::decode($this->charset,$result,Encode::LEAVE_SRC);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
174 }
130
06a34c197b05 Added support for utf-8 and old versions of CGI module
wizard
parents: 129
diff changeset
175
06a34c197b05 Added support for utf-8 and old versions of CGI module
wizard
parents: 129
diff changeset
176 }
06a34c197b05 Added support for utf-8 and old versions of CGI module
wizard
parents: 129
diff changeset
177
138
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 130
diff changeset
178 sub upload {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
179 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
180
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
181 local $NO_DECODE = 1;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
182 my $oldCharset = $this->charset();
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
183 $this->charset('ISO-8859-1');
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
184
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
185 my $fh = $this->SUPER::upload(@_);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
186
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
187 $this->charset($oldCharset);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
188 return $fh;
138
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 130
diff changeset
189 }
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 130
diff changeset
190
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
191 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
192
52
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
193 __END__
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
194
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
195 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
196
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
197 =head1 SYNOPSIS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
198
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
199 =begin code
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
200
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
201 require MyApp;
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
202
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
203 my $instance = spawn MyApp('app.config');
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
204
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
205 $instance->Run();
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
206
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
207 =end code
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
208
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
209 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
210
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 138
diff changeset
211 C< use parent qw( IMPL::Config IMPL::Object::Singleton )>
73
wizard
parents: 67
diff changeset
212
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
213 Зкземпляр приложения содержит в себе глобальные настройки, реализует контроллер запросов,
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
214 в качестве источника запросов используется CGI или иной совместимый модуль.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
215
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
216 Процесс обработки запроса состоит из следующих частей
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
217
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
218 =over
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
219
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
220 =item 1
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
221
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
222 Получение cgi запроса
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
223
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
224 =item 2
52
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
225
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
226 Создание объекта C<IMPL::Web::Application::Action>
52
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
227
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
228 =item 3
52
15d720913562 security in work
wizard@linux-odin.local
parents: 49
diff changeset
229
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
230 Формирование цепочки вызовов при помощи C<< IMPL::Web::Application::Action->ChainHandler >>
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
231
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
232 =item 4
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
233
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
234 Выполнение запроса C<< IMPL::Web::Application::Action->Invoke >>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
235
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
236 =cut
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
237
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
238 Также приложение поддерживает отложенное создание объектов, которые по первому обращению
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
239 к свойствам. Это реализовано в базовом классе C< IMPL::Configuration >. Для настройки
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
240 активаторов можно использовать свойство C<options>, в которое должен быть помещен хеш
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
241 со ссылками на активаторы, см. пример ниже C<CONFIGURATION>.
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
242
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
243 =head2 CONFIGURATION
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
244
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
245 Ниже приведен пример конфигурации приложения
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
246
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
247 =begin code xml
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
248
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
249 <?xml version="1.0" encoding="UTF-8"?>
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
250 <Application id='app' type="Test::Web::Application::Instance">
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
251
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
252 <!-- Begin custom properties -->
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
253 <name>Sample application</name>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
254 <dataSource type='IMPL::Config::Activator' id='ds'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
255 <factory>IMPL::Object</factory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
256 <parameters type='HASH'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
257 <db>data</db>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
258 <user>nobody</user>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
259 </parameters>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
260 </dataSource>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
261 <securityMod type='IMPL::Config::Activator'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
262 <factory>IMPL::Object</factory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
263 <parameters type='HASH'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
264 <ds refid='ds'/>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
265 </parameters>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
266 </securityMod>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
267 <!-- End custom properties -->
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
268
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
269 <!-- direct access to the activators -->
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
270 <options type="HASH">
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
271 <dataSource refid='ds'/>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
272 </options>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
273
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
274 <!-- Set default output encoding, can be changed due query handling -->
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
275 <responseCharset>utf-8</responseCharset>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
276
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
277 <!-- Actions creation configuration -->
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
278 <actionFactory type="IMPL::Object::Factory">
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
279
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
280 <!-- Construct actions -->
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
281 <factory>IMPL::Web::Application::Action</factory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
282 <parameters type='HASH'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
283
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
284 <!-- with special responseFactory -->
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
285 <responseFactory type='IMPL::Object::Factory'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
286
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
287 <!-- Where resopnses have a special streamOut -->
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
288 <factory>IMPL::Web::Application::Response</factory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
289 <parameters type='HASH'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
290
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
291 <!-- in memory dummy output instead of STDOUT -->
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
292 <streamOut>memory</streamOut>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
293
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
294 </parameters>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
295 </responseFactory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
296 </parameters>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
297 </actionFactory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
298
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
299 <!-- Query processing chain -->
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
300 <handlersQuery type="IMPL::Object::List">
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
301 <item type="IMPL::Web::QueryHandler::PageFormat">
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
302 <templatesCharset>cp1251</templatesCharset>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
303 </item>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
304 </handlersQuery>
67
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
305 </Application>
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
306
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
307 =end code xml
9f5795a10939 Documentation, minor fixes
wizard
parents: 65
diff changeset
308
73
wizard
parents: 67
diff changeset
309 =head1 MEMBERS
wizard
parents: 67
diff changeset
310
wizard
parents: 67
diff changeset
311 =over
wizard
parents: 67
diff changeset
312
wizard
parents: 67
diff changeset
313 =item C<[get,set] handlerError>
wizard
parents: 67
diff changeset
314
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
315 Обработчик который будет вызван в случае возникновения необработанной ошибки
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
316 в процессе работы приложения. После чего приложение корректно завершается.
73
wizard
parents: 67
diff changeset
317
wizard
parents: 67
diff changeset
318 =item C<[get,set] actionFactory>
wizard
parents: 67
diff changeset
319
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
320 Фабрика объектов, которая используется приложением, для создания объектов
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
321 типа C<IMPL::Web::Application::Action> при обработки C<CGI> запросов.
73
wizard
parents: 67
diff changeset
322
wizard
parents: 67
diff changeset
323 =begin code
wizard
parents: 67
diff changeset
324
wizard
parents: 67
diff changeset
325 my $action = $this->actionFactory->new(
wizard
parents: 67
diff changeset
326 query => $query,
wizard
parents: 67
diff changeset
327 application => $this,
wizard
parents: 67
diff changeset
328 );
wizard
parents: 67
diff changeset
329
wizard
parents: 67
diff changeset
330 =end code
wizard
parents: 67
diff changeset
331
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
332 =item C< [get,set] fetchRequestMethod >
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
333
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
334 Метод получения CGI запроса. Возвращает C<CGI> объект следующего запроса, если
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
335 запросов больше нет, то возвращает C<undef>. По-умолчанию использует C<defaultFetchRequest>.
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
336
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
337 Может быть как ссылкой на функцию, так и объектом типа C<IMPL::Web::Application::RequestFetcher>.
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 73
diff changeset
338
73
wizard
parents: 67
diff changeset
339 =item C< [get,set,list] handlersQuery >
wizard
parents: 67
diff changeset
340
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
341 Список обработчиков запросов, которые будут переданы созданному объекту-действию.
73
wizard
parents: 67
diff changeset
342
wizard
parents: 67
diff changeset
343 =item C< [get,set] responseCharset>
wizard
parents: 67
diff changeset
344
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
345 Кодировка ответа клиенту.
73
wizard
parents: 67
diff changeset
346
wizard
parents: 67
diff changeset
347 =item C< [get,set] security >
wizard
parents: 67
diff changeset
348
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
349 Объект C<IMPL::Web::Security>, для работы с инфраструктурой безопасности.
73
wizard
parents: 67
diff changeset
350
wizard
parents: 67
diff changeset
351 =item C< [get,set] options >
wizard
parents: 67
diff changeset
352
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
353 Обычно ссылка на хеш с настраиваемыми объектами, используется для возможности
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
354 програмной настройки активаторов, т.к. напрямую через свойства приложения получить
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
355 к ним доступ не получится.
73
wizard
parents: 67
diff changeset
356
wizard
parents: 67
diff changeset
357 =back
wizard
parents: 67
diff changeset
358
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 170
diff changeset
359 =cut