Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/RestResource.pm @ 201:0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
author | sergey |
---|---|
date | Tue, 24 Apr 2012 19:52:07 +0400 |
parents | a9dbe534d236 |
children | 5146e17a7b76 |
rev | line source |
---|---|
196 | 1 package IMPL::Web::Application::RestResource; |
2 use strict; | |
3 | |
198 | 4 use IMPL::lang qw(:declare :constants is); |
5 use IMPL::Exception(); | |
6 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
7 use IMPL::declare { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
8 require => { |
198 | 9 ForbiddenException => 'IMPL::Web::ForbiddenException', |
200 | 10 NotFoundException => 'IMPL::Web::NotFoundException', |
198 | 11 InvalidOpException => '-IMPL::InvalidOperationException', |
12 ArgumentException => '-IMPL::InvalidArgumentException', | |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
13 TTransform => '-IMPL::Transform', |
200 | 14 TResolve => '-IMPL::Config::Resolve', |
15 CustomResource => 'IMPL::Web::Application::CustomResource' | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
16 }, |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
17 base => { |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
18 'IMPL::Web::Application::RestCustomResource' => '@_' |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
19 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
20 }; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
21 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
22 BEGIN { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
23 public property target => PROP_GET | PROP_OWNERSET; |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
24 public property index => PROP_GET | PROP_OWNERSET; |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
25 public property fetch => PROP_GET | PROP_OWNERSET; |
200 | 26 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
27 public property methods => PROP_GET | PROP_OWNERSET; |
200 | 28 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
29 public property childRegex => PROP_GET | PROP_OWNERSET; |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
30 public property enableForms => PROP_GET | PROP_OWNERSET; |
200 | 31 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
32 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
33 |
198 | 34 sub CTOR { |
35 my ($this) = @_; | |
36 | |
37 die ArgumentException->new("target") unless $this->target; | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
38 |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
39 $this->final($this->childRegex ? 0 : 1); |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
40 |
200 | 41 if ($this->enableForms) { |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
42 $this->methods->{create} = { |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
43 get => \&_ParentGet, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
44 post => \&_ParentPost, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
45 final => 1 # this resource doesn't have any children |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
46 }; |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
47 |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
48 $this->methods->{edit} = { |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
49 get => \&_ParentGet, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
50 post => \&_ParentPut, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
51 final => 1 # this resource doesn't have any children |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
52 }; |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
53 |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
54 $this->methods->{delete} { |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
55 get => \&_ParentGet, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
56 post => \&_ParentDelete |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
57 final => 1 # this resource doesn't have any children |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
58 } |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
59 } |
198 | 60 } |
61 | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
62 sub _ParentGet { |
200 | 63 my ($this,$action) = @_; |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
64 return $this->parent->GetImpl($action); |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
65 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
66 |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
67 sub _ParentPut { |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
68 my ($this,$action) = @_; |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
69 return $this->parent->PutImpl($action); |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
70 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
71 |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
72 sub _ParentPost { |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
73 my ($this,$action) = @_; |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
74 return $this->parent->PostImpl($action); |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
75 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
76 |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
77 sub _ParentDelete { |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
78 my ($this,$action) = @_; |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
79 return $this->parent->DeleteImpl($action); |
200 | 80 } |
81 | |
82 sub FetchChildResource { | |
83 my ($this,$id,$action) = @_; | |
84 | |
85 my $rx = $this->childRegex; | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
86 |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
87 my $res; |
200 | 88 |
89 if (length $id == 0) { | |
90 | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
91 my $method = $this->index; |
200 | 92 die ForbiddenException->new() unless $method; |
93 | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
94 $res = $this->InvokeMember($method,$action); |
200 | 95 |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
96 } elsif (my $resource = $this->methods->{$id}) { |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
97 return CustomResource->new( |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
98 get => $resource->{get}, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
99 post => $resource->{post}, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
100 put => $resource->{put}, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
101 delete => $resource->{delete}, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
102 parent => $this, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
103 id => $id, |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
104 target => $this->target |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
105 ); |
200 | 106 |
107 } elsif ($rx and $id =~ m/^$rx$/ and $method = $this->fetch) { | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
108 $res = $this->InvokeMember($method,$action, { id => $id } ); |
200 | 109 } else { |
110 die ForbiddenException->new(); | |
111 } | |
112 | |
113 die NotFoundException->new() unless defined $res; | |
114 | |
115 return $this->contract->Transform($res, {parent => $this, id => $id} ); | |
116 } | |
117 | |
196 | 118 1; |
119 | |
120 __END__ | |
121 | |
122 =pod | |
123 | |
124 =head1 NAME | |
125 | |
126 C<IMPL::Web::Application::RestResource> - ресурс Rest вебсервиса. | |
127 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
128 =head1 SYNOPSIS |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
129 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
130 =begin text |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
131 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
132 [REQUEST] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
133 GET /artists |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
134 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
135 [RESPONSE] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
136 <artists> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
137 <artist id="1"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
138 <name>The Beatles <name/> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
139 </atrist> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
140 <artist id="2"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
141 <name>Bonobo</name> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
142 </artist> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
143 </artists> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
144 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
145 [REQUEST] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
146 GET /artists/1/cds?title='Live at BBC' |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
147 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
148 [RESPONSE] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
149 <cds> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
150 <cd id="14"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
151 <title>Live at BBC 1</title> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
152 </cd> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
153 <cd id="15"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
154 <title>Live at BBC 2</title> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
155 </cd> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
156 </cds> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
157 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
158 [REQUEST] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
159 GET /cds/15 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
160 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
161 [RESPONSE] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
162 <cd id="15"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
163 <title>Live at BBC 2</title> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
164 </cd> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
165 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
166 =end text |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
167 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
168 =begin code |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
169 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
170 use IMPL::require { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
171 TRes => 'IMPL::Web:Application::RestResource', |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
172 DataContext => 'My::App::DataContext' |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
173 }; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
174 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
175 my $cds = TRes->new( |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
176 DataContext->Default, |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
177 { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
178 methods => { |
198 | 179 history => { |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
180 get => { |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
181 method => 'GetHistory', |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
182 parameters => [qw(from to)] |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
183 }, |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
184 }, |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
185 rating => { |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
186 get => { |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
187 method => 'GetRating' |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
188 } |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
189 post => { |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
190 method => 'Vote', |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
191 parameters => [qw(id rating comment)] |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
192 } |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
193 } |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
194 } |
198 | 195 list => 'search', |
196 fetch => 'GetItemById' | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
197 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
198 ); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
199 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
200 =end code |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
201 |
196 | 202 =head1 DESCRIPTION |
203 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
204 Каждый ресурс представляет собой коллекцию и реализует методы C<HTTP> C<GET,POST,PUT,DELETE>. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
205 |
200 | 206 Ресурсы выстраиваются в иерархию, на основе пути. Поиск конечного реурса происходит последовательным |
207 вызовом метода GET с именем очередного ресурса. | |
208 | |
209 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
210 =head2 HTTP METHODS |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
211 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
212 =head3 C<GET> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
213 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
214 Возвращает коллекцию дочерних ресурсов. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
215 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
216 =head3 C<GET {id}> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
217 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
218 Возвращает дочерний объект с идентификатором C<id> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
219 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
220 =head3 C<GET {method}> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
221 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
222 Вызывает метод C<method> и возвращает его результаты. При публикации методов доступных |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
223 через C<GET> данные методы не должны вносить изменений в предметную область. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
224 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
225 =head3 C<PUT {id}> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
226 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
227 Обновляет дочерний ресурс с указанным идентификатором. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
228 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
229 =head3 C<DELETE {id}> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
230 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
231 Удаляет дочерний ресурс с указанным идентификатором. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
232 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
233 =head3 C<POST> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
234 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
235 Добавляет новый дочерний ресурс в коллекцию. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
236 |
198 | 237 =head3 C<POST {method}> |
238 | |
239 Вызывает метод C<method>. | |
240 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
241 =head2 HTTP METHOD MAPPING |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
242 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
243 =head3 C<POST {method}> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
244 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
245 Вызывает метод C<method>, в отличии от C<GET> методы опубликованные через C<POST> могут вносить |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
246 изменения в объекты. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
247 |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
248 =head1 BROWSER COMPATIBILITY |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
249 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
250 Однако существует проблема с браузерами, поскольку тег C<< <form> >> реализет только методы |
200 | 251 C<GET,POST>. Для решения данной проблемы используется режим совместимости C<enableForms>. В |
252 случае когда данный режим активен, автоматически публикуются дочерние ресурсы C<create,edit,delete>. | |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
253 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
254 =head2 C<GET create> |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
255 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
256 Возвращает C<target>. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
257 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
258 =head2 C<POST create> |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
259 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
260 Вызывает метод C<PostImpl> передавая ему свои параметры. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
261 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
262 =head2 C<GET edit> |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
263 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
264 Возвращает C<target>. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
265 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
266 =head2 C<POST edit> |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
267 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
268 Вызывает метод C<$this->parent->PutImpl($this->id)> передавая ему свои параметры. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
269 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
270 =head2 C<GET delete>. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
271 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
272 Возвращает C<target>. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
273 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
274 =head2 C<POST delete>. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
275 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
276 Вызывает метод C<$this->parent->DeleteImpl($this->id)> передавая ему свои параметры. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
277 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
278 =head1 MEMBERS |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
279 |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
280 =head2 C<[get]id> |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
281 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
282 Идентификатор текущего ресурса. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
283 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
284 =head2 C<[get]target> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
285 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
286 Объект (также может быть и класс), обеспечивающий функционал ресурса. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
287 |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
288 =head2 C<[get]parent> |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
289 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
290 Родительский ресурс, в котором находится текущий ресурс. Может быть C<undef>, |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
291 если текущий ресурс является корнем. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
292 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
293 =head2 C<[get]methods> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
294 |
198 | 295 Содержит описания методов, которые будут публиковаться как дочерние ресурсы. |
296 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
297 =head2 C<[get]childRegex> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
298 |
198 | 299 Содержит регулярное выражение для идентификаторов дочерних объектов. Если оно |
300 не задано, то данный ресурс не является коллекцией. | |
301 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
302 =head2 C<[get]fetch> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
303 |
198 | 304 Содержит описание метода для получения дочернего объекта. Если данный метод |
305 отсутствует, то дочерние ресурсы не получится адресовать относительно данного. | |
306 По умолчанию получает идентификатор дочернего ресурса первым параметром. | |
307 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
308 =head2 C<[get]list> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
309 |
198 | 310 Описание метода для получения списка дочерних объектов. По умолчанию не |
311 получает параметров. | |
312 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
313 =head2 C<[get]insert> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
314 |
198 | 315 Описание метода для добавление дочернего ресурса. По умолчанию получает |
316 объект C<CGI> описывабщий текущий запрос первым параметром. | |
317 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
318 =head2 C<[get]update> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
319 |
198 | 320 Описание метода для обновления дочернего ресурса. По умолчанию получает |
321 идентификатор дочернего ресурса и объект C<CGI> текущего запроса. | |
322 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
323 =head2 C<[get]delete> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
324 |
198 | 325 Описание метода для удаления дочернего ресурса. По умолчанию получает |
326 идентификатор дочернего ресурса. | |
327 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
328 =head2 C<GetImpl($child,$action)> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
329 |
198 | 330 =over |
331 | |
332 =item C<$child> | |
333 | |
334 Идентификатор дочернего ресутсра | |
335 | |
336 =item C<$action> | |
337 | |
338 Текущий запрос C<IMPL::Web::Application::Action>. | |
339 | |
340 =back | |
341 | |
342 Переадресует запрос нужному методу внутреннего объекта C<target> при | |
343 помощи C<InvokeMember>. | |
344 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
345 =head2 C<PutImpl($child,$action)> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
346 |
198 | 347 =over |
348 | |
349 =item C<$child> | |
350 | |
351 Идентификатор дочернего ресутсра | |
352 | |
353 =item C<$action> | |
354 | |
355 Текущий запрос C<IMPL::Web::Application::Action>. | |
356 | |
357 =back | |
358 | |
359 Переадресует запрос нужному методу внутреннего объекта C<target> при | |
360 помощи C<InvokeMember>. | |
361 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
362 =head2 C<PostImpl($child,$action)> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
363 |
198 | 364 =over |
365 | |
366 =item C<$child> | |
367 | |
368 Идентификатор дочернего ресутсра | |
369 | |
370 =item C<$action> | |
371 | |
372 Текущий запрос C<IMPL::Web::Application::Action>. | |
373 | |
374 =back | |
375 | |
376 Переадресует запрос нужному методу внутреннего объекта C<target> при | |
377 помощи C<InvokeMember>. | |
378 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
379 =head2 C<DeleteImpl($child,$action)> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
380 |
198 | 381 =over |
382 | |
383 =item C<$child> | |
384 | |
385 Идентификатор дочернего ресутсра | |
386 | |
387 =item C<$action> | |
388 | |
389 Текущий запрос C<IMPL::Web::Application::Action>. | |
390 | |
391 =back | |
392 | |
393 Переадресует запрос нужному методу внутреннего объекта C<target> при | |
394 помощи C<InvokeMember>. | |
395 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
396 =head2 C<InvokeMember($memberInfo,$child,$action)> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
397 |
198 | 398 =over |
399 | |
400 =item C<$memberInfo> | |
401 | |
402 Описание члена внутреннего объекта C<target>, который нужно вызвать. | |
403 | |
404 =item C<$child> | |
405 | |
406 Идентификатор дочернего ресутсра | |
407 | |
408 =item C<$action> | |
409 | |
410 Текущий запрос C<IMPL::Web::Application::Action>. | |
411 | |
412 =back | |
413 | |
414 Вызывает метод внутреннего объекта C<target>, предварительно подготовив | |
415 параметры на основе описания C<$memberInfo> и при помощи С<MakeParameter()>. | |
416 | |
417 =head2 C<MakeParameter($paramDef,$child,$action)> | |
418 | |
419 =over | |
420 | |
421 =item C<$paramDef> | |
422 | |
423 Описание параметра, может быть C<IMPL::Transform> или простая строка. | |
424 | |
425 Если описание параметра - простая строка, то ее имя либо | |
426 | |
427 =over | |
428 | |
429 =item C<id> | |
430 | |
431 Идентификатор дочернего ресурса | |
432 | |
433 =item C<query> | |
434 | |
435 Объект C<CGI> текущего запроса | |
436 | |
437 =item C<action> | |
438 | |
439 Текущий запрос C<IMPL::Web::Application::Action> | |
440 | |
441 =item C<любое другое значение> | |
442 | |
443 Интерпретируется как параметр текущего запроса. | |
444 | |
445 =back | |
446 | |
447 Если описание параметра - объект C<IMPL::Transform>, то будет выполнено это преобразование над C<CGI> | |
448 объектом текущего запроса C<< $paramDef->Transform($action->query) >>. | |
449 | |
450 =back | |
451 | |
196 | 452 =cut |