Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/Action.pm @ 257:299af584c05f
collapse empty array elements in POSTed data
author | sergey |
---|---|
date | Fri, 14 Dec 2012 03:07:41 +0400 |
parents | 32aceba4ee6d |
children | 89179bb8c388 |
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(); |
238 | 8 |
9 use IMPL::declare { | |
10 base => [ | |
11 'IMPL::Object' => undef, | |
12 'IMPL::Object::Autofill' => '@_' | |
13 ], | |
14 props => [ | |
15 application => PROP_RO, | |
244 | 16 query => PROP_RO, |
17 context => PROP_RW | |
238 | 18 ] |
19 }; | |
55 | 20 |
65 | 21 sub CTOR { |
194 | 22 my ($this) = @_; |
244 | 23 |
24 $this->context({}); | |
65 | 25 } |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
26 |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
27 sub cookie { |
194 | 28 my ($this,$name,$rx) = @_; |
29 | |
30 $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
|
31 } |
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 sub param { |
194 | 34 my ($this,$name,$rx) = @_; |
35 | |
245 | 36 my $value; |
37 | |
38 if ( | |
39 $this->requestMethod eq 'GET' | |
40 or | |
41 $this->query->content_type eq 'multipart/form-data' | |
42 or | |
43 $this->query->content_type eq 'application/x-www-form-urlencoded' | |
44 ) { | |
45 $value = scalar( $this->query->param($name) ); | |
46 } else { | |
47 $value = scalar( $this->query->url_param($name) ); | |
48 } | |
49 | |
50 $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
|
51 } |
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
52 |
256
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
53 sub rawData { |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
54 my ($this) = @_; |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
55 |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
56 local $IMPL::Web::CGIWrapper::NO_DECODE = 1; |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
57 if ($this->requestMethod eq 'POST') { |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
58 return $this->query->param('POSTDATA'); |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
59 } elsif($this->requestMethod eq 'PUT') { |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
60 return $this->query->param('PUTDATA'); |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
61 } |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
62 } |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
63 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
64 sub requestMethod { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
65 my ($this) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
66 return $this->query->request_method; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
67 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
68 |
256
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
69 sub contentType { |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
70 return shift->query->content_type(); |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
71 } |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
245
diff
changeset
|
72 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
73 sub pathInfo { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
74 my ($this) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
75 return $this->query->path_info; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
76 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
77 |
238 | 78 sub baseUrl { |
79 my ($this) = @_; | |
80 | |
81 return $this->query->url(-base => 1); | |
82 } | |
83 | |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
84 sub _launder { |
194 | 85 my ($this,$value,$rx) = @_; |
86 | |
87 if ( $value ) { | |
88 if ($rx) { | |
89 if ( my @result = ($value =~ m/$rx/) ) { | |
90 return @result > 1 ? \@result : $result[0]; | |
91 } else { | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
92 return; |
194 | 93 } |
94 } else { | |
95 return $value; | |
96 } | |
97 } else { | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
98 return; |
194 | 99 } |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
100 } |
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
67
diff
changeset
|
101 |
52 | 102 1; |
103 | |
104 __END__ | |
105 | |
106 =pod | |
107 | |
67 | 108 =head1 NAME |
109 | |
180 | 110 C<IMPL::Web::Application::Action> - Обертка вокруг C<CGI> запроса. |
67 | 111 |
52 | 112 =head1 DESCRIPTION |
113 | |
67 | 114 C<[Infrastructure]> |
206 | 115 Свзяывет CGI запрос, приложение, орабатывающее его и ответ, который будет отправлен клиенту. |
52 | 116 |
67 | 117 =head1 MEMBERS |
118 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
119 =head2 C<CTOR(%args)> |
67 | 120 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
121 Инициализирует новый экземпляр. Именованными параметрами передаются значения |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
122 свойств. |
67 | 123 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
124 =head2 C< [get]application> |
67 | 125 |
180 | 126 Экземпляр приложения создавшего текущий объект |
67 | 127 |
128 =item C< [get] query > | |
129 | |
180 | 130 Экземпляр C<CGI> запроса |
67 | 131 |
132 =back | |
133 | |
134 | |
180 | 135 =cut |