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