Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/Action.pm @ 320:28eba7e0c592
*web application action: added method to access HTTP request header.
author | sergey |
---|---|
date | Thu, 16 May 2013 17:16:41 +0400 |
parents | 4abda21186cd |
children | 3dc9260017ad |
rev | line source |
---|---|
52 | 1 package IMPL::Web::Application::Action; |
55 | 2 use strict; |
52 | 3 |
206 | 4 use Carp qw(carp); |
52 | 5 |
238 | 6 use IMPL::Const qw(:prop); |
256
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
7 use IMPL::Web::CGIWrapper(); |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
8 use URI; |
238 | 9 |
10 use IMPL::declare { | |
11 base => [ | |
12 'IMPL::Object' => undef, | |
13 'IMPL::Object::Autofill' => '@_' | |
14 ], | |
15 props => [ | |
16 application => PROP_RO, | |
244 | 17 query => PROP_RO, |
18 context => PROP_RW | |
238 | 19 ] |
20 }; | |
55 | 21 |
65 | 22 sub CTOR { |
194 | 23 my ($this) = @_; |
244 | 24 |
25 $this->context({}); | |
65 | 26 } |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
27 |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
28 sub cookie { |
194 | 29 my ($this,$name,$rx) = @_; |
30 | |
31 $this->_launder(scalar( $this->query->cookie($name) ), $rx ); | |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
32 } |
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
33 |
320
28eba7e0c592
*web application action: added method to access HTTP request header.
sergey
parents:
268
diff
changeset
|
34 sub header { |
28eba7e0c592
*web application action: added method to access HTTP request header.
sergey
parents:
268
diff
changeset
|
35 my ($this,$header) = @_; |
28eba7e0c592
*web application action: added method to access HTTP request header.
sergey
parents:
268
diff
changeset
|
36 |
28eba7e0c592
*web application action: added method to access HTTP request header.
sergey
parents:
268
diff
changeset
|
37 $this->query->https ? $this->query->https($header) : $this->query->http($header); |
28eba7e0c592
*web application action: added method to access HTTP request header.
sergey
parents:
268
diff
changeset
|
38 } |
28eba7e0c592
*web application action: added method to access HTTP request header.
sergey
parents:
268
diff
changeset
|
39 |
28eba7e0c592
*web application action: added method to access HTTP request header.
sergey
parents:
268
diff
changeset
|
40 sub isSecure { |
28eba7e0c592
*web application action: added method to access HTTP request header.
sergey
parents:
268
diff
changeset
|
41 shift->query->https ? 1 : 0; |
28eba7e0c592
*web application action: added method to access HTTP request header.
sergey
parents:
268
diff
changeset
|
42 } |
28eba7e0c592
*web application action: added method to access HTTP request header.
sergey
parents:
268
diff
changeset
|
43 |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
44 sub param { |
194 | 45 my ($this,$name,$rx) = @_; |
46 | |
245 | 47 my $value; |
48 | |
49 if ( | |
50 $this->requestMethod eq 'GET' | |
51 or | |
52 $this->query->content_type eq 'multipart/form-data' | |
53 or | |
54 $this->query->content_type eq 'application/x-www-form-urlencoded' | |
55 ) { | |
56 $value = scalar( $this->query->param($name) ); | |
57 } else { | |
58 $value = scalar( $this->query->url_param($name) ); | |
59 } | |
60 | |
61 $this->_launder($value, $rx ); | |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
62 } |
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
63 |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
64 sub urlParam { |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
65 my ($this,$name,$rx) = @_; |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
66 |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
67 $this->_launder(scalar( $this->query->url_param($name) ), $rx); |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
68 } |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
69 |
256
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
70 sub rawData { |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
71 my ($this) = @_; |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
72 |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
73 local $IMPL::Web::CGIWrapper::NO_DECODE = 1; |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
74 if ($this->requestMethod eq 'POST') { |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
75 return $this->query->param('POSTDATA'); |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
76 } elsif($this->requestMethod eq 'PUT') { |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
77 return $this->query->param('PUTDATA'); |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
78 } |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
79 } |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
80 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
81 sub requestMethod { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
82 my ($this) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
83 return $this->query->request_method; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
84 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
85 |
256
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
86 sub contentType { |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
87 return shift->query->content_type(); |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
88 } |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
89 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
90 sub pathInfo { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
91 my ($this) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
92 return $this->query->path_info; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
93 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
94 |
238 | 95 sub baseUrl { |
96 my ($this) = @_; | |
97 | |
98 return $this->query->url(-base => 1); | |
99 } | |
100 | |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
101 sub applicationUrl { |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
102 shift->application->baseUrl; |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
103 } |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
104 |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
105 sub applicationFullUrl { |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
106 my ($this) = @_; |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
107 |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
108 return URI->new_abs($this->application->baseUrl, $this->query->url(-base => 1)); |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
109 } |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
110 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
266
diff
changeset
|
111 # creates an url that contains server, schema and path parts |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
112 sub CreateFullUrl { |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
113 my ($this,$path) = @_; |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
114 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
266
diff
changeset
|
115 return $path ? URI->new_abs($path,$this->applicationFullUrl) : $this->applicationFullUrl; |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
116 } |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
117 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
266
diff
changeset
|
118 # creates an url that contains only a path part |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
119 sub CreateAbsoluteUrl { |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
120 my ($this,$path) = @_; |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
121 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
266
diff
changeset
|
122 return $path ? URI->new_abs($path,$this->applicationUrl) : $this->applicationUrl; |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
123 } |
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
124 |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
125 sub _launder { |
194 | 126 my ($this,$value,$rx) = @_; |
127 | |
128 if ( $value ) { | |
129 if ($rx) { | |
130 if ( my @result = ($value =~ m/$rx/) ) { | |
131 return @result > 1 ? \@result : $result[0]; | |
132 } else { | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
133 return; |
194 | 134 } |
135 } else { | |
136 return $value; | |
137 } | |
138 } else { | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
139 return; |
194 | 140 } |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
141 } |
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
142 |
52 | 143 1; |
144 | |
145 __END__ | |
146 | |
147 =pod | |
148 | |
67 | 149 =head1 NAME |
150 | |
180 | 151 C<IMPL::Web::Application::Action> - Обертка вокруг C<CGI> запроса. |
67 | 152 |
52 | 153 =head1 DESCRIPTION |
154 | |
67 | 155 C<[Infrastructure]> |
206 | 156 Свзяывет CGI запрос, приложение, орабатывающее его и ответ, который будет отправлен клиенту. |
52 | 157 |
67 | 158 =head1 MEMBERS |
159 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
160 =head2 C<CTOR(%args)> |
67 | 161 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
162 Инициализирует новый экземпляр. Именованными параметрами передаются значения |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
163 свойств. |
67 | 164 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
165 =head2 C< [get]application> |
67 | 166 |
180 | 167 Экземпляр приложения создавшего текущий объект |
67 | 168 |
169 =item C< [get] query > | |
170 | |
180 | 171 Экземпляр C<CGI> запроса |
67 | 172 |
173 =back | |
174 | |
175 | |
180 | 176 =cut |