Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/RestResource.pm @ 220:5c82c15b25b1
sync, updated schema
author | sergey |
---|---|
date | Thu, 23 Aug 2012 17:44:31 +0400 |
parents | e9fd7ff3f54c |
children |
rev | line source |
---|---|
196 | 1 package IMPL::Web::Application::RestResource; |
2 use strict; | |
3 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
4 use IMPL::lang qw(:declare :constants is :hash); |
198 | 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', |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
15 CustomResource => 'IMPL::Web::Application::RestCustomResource' |
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 { |
216 | 23 # объект, который представляется данным ресурсом |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
24 public property target => PROP_GET | PROP_OWNERSET; |
216 | 25 |
26 # получение индекса, тоесть обращение по пути '/foo/bar/' | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
27 public property index => PROP_GET | PROP_OWNERSET; |
216 | 28 |
29 # получение дочернего ресурса по идентификатору, который | |
30 # удовлетворяет childRegex | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
31 public property fetch => PROP_GET | PROP_OWNERSET; |
200 | 32 |
216 | 33 # публикует ресурсы связанные с методами объекта |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
34 public property methods => PROP_GET | PROP_OWNERSET; |
200 | 35 |
216 | 36 # формат идентификаторов дочерних ресурсов для метода fetch |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
37 public property childRegex => PROP_GET | PROP_OWNERSET; |
216 | 38 |
39 # поддержка форм браузеров при помощи создания дочерних ресурсов | |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
40 public property enableForms => PROP_GET | PROP_OWNERSET; |
200 | 41 |
216 | 42 # контракты именованных дочерних ресурсов |
43 public property nestedResources => PROP_GET | PROP_OWNERSET; | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
44 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
45 |
198 | 46 sub CTOR { |
212 | 47 my ($this,%args) = @_; |
198 | 48 |
49 die ArgumentException->new("target") unless $this->target; | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
50 |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
51 $this->final($this->childRegex ? 0 : 1); |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
52 $this->methods({}) unless $this->methods; |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
53 |
212 | 54 $this->index($this->get) unless defined $this->index; |
55 | |
200 | 56 if ($this->enableForms) { |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
57 $this->methods->{create} = { |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
58 get => $this->get, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
59 post => $this->post, |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
60 final => 1 # this resource doesn't have any children |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
61 } if $this->post; |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
62 |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
63 $this->methods->{edit} = { |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
64 get => $this->get, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
65 post => $this->put, |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
66 final => 1 # this resource doesn't have any children |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
67 } if $this->put; |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
68 |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
69 $this->methods->{delete} { |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
70 get => $this->get, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
71 post => $this->delete, |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
72 final => 1 # this resource doesn't have any children |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
73 } if $this->delete; |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
74 } |
198 | 75 } |
76 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
77 # создает дочерний ресурс из описания, однако все методы созданного |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
78 # ресурса переадресуются к его родителю, это нужно, чтобы публиковать |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
79 # методы и свойства объекта |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
80 sub _CreateSubResource { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
81 my ($this,$resource,$id) = @_; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
82 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
83 my %methods = map { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
84 my $method = $resource->{$_}; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
85 $_ => sub { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
86 my ($this,$action) = @_; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
87 return $this->parent->InvokeMember($method,$action); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
88 }; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
89 } grep $resource->{$_}, qw(get post put delete); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
90 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
91 return CustomResource->new( |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
92 %methods, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
93 final => $resource->{final}, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
94 parent => $this, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
95 id => $id, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
96 contract => $this->contract |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
97 ); |
200 | 98 } |
99 | |
100 sub FetchChildResource { | |
101 my ($this,$id,$action) = @_; | |
102 | |
103 my $rx = $this->childRegex; | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
104 |
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
105 my $res; |
200 | 106 |
107 if (length $id == 0) { | |
108 | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
109 my $method = $this->index; |
200 | 110 die ForbiddenException->new() unless $method; |
111 | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
112 $res = $this->InvokeMember($method,$action); |
200 | 113 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
114 } elsif ($this->methods and my $resource = $this->methods->{$id}) { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
115 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
116 return $this->_CreateSubResource($resource,$id); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
117 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
118 } elsif ($rx and $id =~ m/^$rx$/ and my $method = $this->fetch) { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
119 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
120 $method = { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
121 method => $method, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
122 parameters => 'id' |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
123 } unless ref $method; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
124 |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
125 $res = $this->InvokeMember($method,$action, { id => $id } ); |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
126 |
200 | 127 } |
128 | |
129 die NotFoundException->new() unless defined $res; | |
130 | |
131 return $this->contract->Transform($res, {parent => $this, id => $id} ); | |
132 } | |
133 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
134 sub InvokeMember { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
135 my ($this,$method,$action,$predefined) = @_; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
136 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
137 die ArgumentException->new("method","No method information provided") unless $method; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
138 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
139 #normalize method info |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
140 if (not ref $method) { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
141 $method = { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
142 method => $method |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
143 }; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
144 } |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
145 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
146 if (ref $method eq 'HASH') { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
147 my $member = $method->{method} or die InvalidOpException->new("A member name isn't specified"); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
148 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
149 $member = $member->Invoke($this) if eval { $member->isa(TResolve) }; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
150 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
151 my @args; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
152 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
153 if (my $params = $method->{parameters}) { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
154 if (ref $params eq 'HASH') { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
155 @args = map { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
156 $_, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
157 $this->MakeParameter($params->{$_},$action,$predefined) |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
158 } keys %$params; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
159 } elsif (ref $params eq 'ARRAY') { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
160 @args = map $this->MakeParameter($_,$action,$predefined), @$params; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
161 } else { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
162 @args = ($this->MakeParameter($params,$action,$predefined)); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
163 } |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
164 } |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
165 return $this->target->$member(@args); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
166 } elsif (ref $method eq TResolve) { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
167 return $method->Invoke($this); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
168 } elsif (ref $method eq 'CODE') { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
169 return $method->($this,$action); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
170 } else { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
171 die InvalidOpException->new("Unsupported type of the method information", ref $method); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
172 } |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
173 } |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
174 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
175 sub MakeParameter { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
176 my ($this,$param,$action,$predefined) = @_; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
177 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
178 my $params = hashApply( |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
179 { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
180 id => $this->id, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
181 action => $action, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
182 query => $action->query |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
183 }, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
184 $predefined || {} |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
185 ); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
186 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
187 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
188 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
189 if ($param) { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
190 if (is $param, TTransform ) { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
191 return $param->Transform($action->query); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
192 } elsif ($param and not ref $param) { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
193 return $params->{$param} || $action->query->param($param); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
194 } else { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
195 die InvalidOpException->new("Unsupported parameter mapping", $param); |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
196 } |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
197 } else { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
198 return undef; |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
199 } |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
200 } |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
201 |
196 | 202 1; |
203 | |
204 __END__ | |
205 | |
206 =pod | |
207 | |
208 =head1 NAME | |
209 | |
210 C<IMPL::Web::Application::RestResource> - ресурс Rest вебсервиса. | |
211 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
212 =head1 SYNOPSIS |
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 =begin text |
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 [REQUEST] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
217 GET /artists |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
218 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
219 [RESPONSE] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
220 <artists> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
221 <artist id="1"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
222 <name>The Beatles <name/> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
223 </atrist> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
224 <artist id="2"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
225 <name>Bonobo</name> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
226 </artist> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
227 </artists> |
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 [REQUEST] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
230 GET /artists/1/cds?title='Live at BBC' |
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 [RESPONSE] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
233 <cds> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
234 <cd id="14"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
235 <title>Live at BBC 1</title> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
236 </cd> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
237 <cd id="15"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
238 <title>Live at BBC 2</title> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
239 </cd> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
240 </cds> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
241 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
242 [REQUEST] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
243 GET /cds/15 |
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 [RESPONSE] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
246 <cd id="15"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
247 <title>Live at BBC 2</title> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
248 </cd> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
249 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
250 =end text |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
251 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
252 =begin code |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
253 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
254 use IMPL::require { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
255 TRes => 'IMPL::Web:Application::RestResource', |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
256 DataContext => 'My::App::DataContext' |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
257 }; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
258 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
259 my $cds = TRes->new( |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
260 DataContext->Default, |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
261 { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
262 methods => { |
198 | 263 history => { |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
264 get => { |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
265 method => 'GetHistory', |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
266 parameters => [qw(from to)] |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
267 }, |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
268 }, |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
269 rating => { |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
270 get => { |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
271 method => 'GetRating' |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
272 } |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
273 post => { |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
274 method => 'Vote', |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
275 parameters => [qw(id rating comment)] |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
276 } |
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 } |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
279 index => { |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
280 method => 'search', |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
281 paremeters => [qw(filter page limit)] |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
282 }, |
198 | 283 fetch => 'GetItemById' |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
284 } |
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 =end code |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
288 |
196 | 289 =head1 DESCRIPTION |
290 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
291 Каждый ресурс представляет собой коллекцию и реализует методы C<HTTP> C<GET,POST,PUT,DELETE>. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
292 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
293 Вызов каждого из этих методов позволяет выполнить одну из операций над ресурсом, однако |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
294 операций может быть больше, для этого создаются дочерние ресурсы (каждый из которых также |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
295 может иметь четыре метода C<GET,POST,PUT,DELETE>), однако обращения к методам у дочерних |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
296 ресурсов отображаются в вызовы методов у родительского ресурса. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
297 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
298 Такой подход позволяет расширить функциональность не изменяя стандарт C<HTTP>, а также обойти |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
299 ограничения браузеров на методы C<PUT,DELETE>. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
300 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
301 Данный тип ресутсов расчитан на использование с конфигурацией, которую можно будет |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
302 сохранить или прочитать, например, из файла. Для этого у ресурса есть ряд настроек, |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
303 которые позволяют в простой форме задать отображения между C<HTTP> методами и методами |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
304 объекта представленного данным ресурсом. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
305 |
216 | 306 Следует отметить, что свойство C<final> вычисляется автоматически. |
307 | |
200 | 308 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
309 =head2 HTTP METHODS |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
310 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
311 =head3 C<GET> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
312 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
313 Возвращает данные из текущего ресурса. Обращение к данному методу не должно вносить |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
314 изменений в ресурсы. |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
315 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
316 =head3 C<PUT> |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
317 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
318 Обновляет ресурс. Повторное обращение к данному методу должно приводить к одному и |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
319 томуже результату. |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
320 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
321 =head3 C<DELETE> |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
322 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
323 Удаляет ресурс. |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
324 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
325 =head3 C<POST> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
326 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
327 Данный метод может вести себя как угодно, однако обычно он используется для добавления |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
328 нового дочернего ресурса в коллекцию,также может использоваться для вызова метода, в случае |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
329 если происходит публикация методов в качестве дочерних ресурсов. |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
330 |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
331 =head1 BROWSER COMPATIBILITY |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
332 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
333 Однако существует проблема с браузерами, поскольку тег C<< <form> >> реализет только методы |
200 | 334 C<GET,POST>. Для решения данной проблемы используется режим совместимости C<enableForms>. В |
335 случае когда данный режим активен, автоматически публикуются дочерние ресурсы C<create,edit,delete>. | |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
336 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
337 Данные ресуры пбликуются как методы, что означает то, что обращения к ним будут превращены в |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
338 выполнения соответсвующих методов на родительском объекте. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
339 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
340 =head2 C<create> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
341 |
216 | 342 По сути данные ресурсы не является необходимостью, однако создается для целостности модели. |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
343 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
344 =head3 C<GET> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
345 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
346 Передает управление методу C<get> |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
347 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
348 =head3 C<POST> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
349 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
350 Передает управление методу C<post> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
351 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
352 =head2 C<edit> |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
353 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
354 =head3 C<GET> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
355 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
356 Передает управление методу C<get> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
357 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
358 =head3 C<POST> |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
359 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
360 Передает управление методу C<put>, как если бы он был выполнен непосредственно у |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
361 родительского ресурса. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
362 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
363 =head2 C<delete> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
364 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
365 =head3 C<GET> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
366 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
367 Передает управление методу C<get> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
368 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
369 =head3 C<POST> |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
370 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
371 Передает управление методу C<delete>, , как если бы он был выполнен непосредственно у |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
372 родительского ресурса. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
373 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
374 =head1 METHOD DEFINITIONS |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
375 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
376 Все методы ресурсов данного типа задаются описаниями, хранящимися в соответствующих |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
377 свойствах. Когда наступает необходимость вызова соответствующего метода, его описание |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
378 бедется из свойства и передается методу C<InvokeMember>, который и производит вызов. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
379 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
380 =head2 C<HASH> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
381 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
382 Содержит в себе описание метода, который нужно вызвать, а также его параметры. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
383 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
384 =over |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
385 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
386 =item C<method> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
387 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
388 Имя метода который будет вызван. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
389 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
390 =item C<paremeters> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
391 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
392 Описание параметров метода, может быть либо массивом, либо хешем, либо простым |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
393 значением. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
394 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
395 =over |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
396 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
397 =item C<ARRAY> |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
398 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
399 Метод получает список параметров, каждый элемент данного массива будет превращен |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
400 в параметр при помощи метода C<MakeParameter> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
401 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
402 =item C<HASH> |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
403 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
404 Метод получает список параметров, который состоит пар ключ-значение, каждое значение |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
405 данного хеша будет превращено в зачение параметра метода при помощи метода C<MakeParameter>. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
406 Ключи хеша изменениям не подвергаются. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
407 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
408 =item Простое значение |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
409 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
410 Метод получает одно значение, которое будет получено из текущего при помощи C<MakeParameter>. |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
411 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
412 =back |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
413 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
414 =back |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
415 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
416 =head2 C<CODE> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
417 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
418 Если в описании метода находится ссылка на функцию, то эта функция будет вызвана с параметрами. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
419 Данный вариант полезен когда ресурсы создаются програмно обычного механизма описаний не достаточно |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
420 для реализации требуемого функционала. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
421 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
422 =over |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
423 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
424 =item C<$resource> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
425 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
426 Текущий ресурс у которого производится вызов метода. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
427 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
428 =item C<$action> |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
429 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
430 Текущий запрос C<IMPL::Web::Application::Action>. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
431 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
432 =back |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
433 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
434 =head2 Простое значение |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
435 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
436 Интерпретируется как имя метода у объекта данных текущего ресурса. |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
437 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
438 =head1 MEMBERS |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
439 |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
440 =head2 C<[get]id> |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
441 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
442 Идентификатор текущего ресурса. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
443 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
444 =head2 C<[get]target> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
445 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
446 Объект данных (может быть и класс, поскольку у него будут только вызываться |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
447 методы), обеспечивающий функционал ресурса. |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
448 |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
449 =head2 C<[get]parent> |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
450 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
451 Родительский ресурс, в котором находится текущий ресурс. Может быть C<undef>, |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
452 если текущий ресурс является корнем. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
453 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
454 =head2 C<[get]methods> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
455 |
198 | 456 Содержит описания методов, которые будут публиковаться как дочерние ресурсы. |
457 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
458 =head2 C<[get]childRegex> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
459 |
198 | 460 Содержит регулярное выражение для идентификаторов дочерних объектов. Если оно |
461 не задано, то данный ресурс не является коллекцией. | |
462 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
463 =head2 C<[get]fetch> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
464 |
198 | 465 Содержит описание метода для получения дочернего объекта. Если данный метод |
466 отсутствует, то дочерние ресурсы не получится адресовать относительно данного. | |
467 По умолчанию получает идентификатор дочернего ресурса первым параметром. | |
468 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
469 =head2 C<[get]index> |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
470 |
198 | 471 Описание метода для получения списка дочерних объектов. По умолчанию не |
472 получает параметров. | |
473 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
474 =head2 C<[get]post> |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
475 |
198 | 476 Описание метода для добавление дочернего ресурса. По умолчанию получает |
477 объект C<CGI> описывабщий текущий запрос первым параметром. | |
478 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
479 =head2 C<[get]put> |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
480 |
198 | 481 Описание метода для обновления дочернего ресурса. По умолчанию получает |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
482 объект C<CGI> текущего запроса. |
198 | 483 |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
484 =head2 C<[get]delete> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
485 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
486 Описание метода для удаления дочернего ресурса. По умолчанию не получает |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
487 параметров. |
198 | 488 |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
489 =head2 C<GetImpl($action)> |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
490 |
198 | 491 =over |
492 | |
493 =item C<$action> | |
494 | |
495 Текущий запрос C<IMPL::Web::Application::Action>. | |
496 | |
497 =back | |
498 | |
499 Переадресует запрос нужному методу внутреннего объекта C<target> при | |
500 помощи C<InvokeMember>. | |
501 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
502 =head2 C<PutImpl($action)> |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
503 |
198 | 504 =over |
505 | |
506 =item C<$action> | |
507 | |
508 Текущий запрос C<IMPL::Web::Application::Action>. | |
509 | |
510 =back | |
511 | |
512 Переадресует запрос нужному методу внутреннего объекта C<target> при | |
513 помощи C<InvokeMember>. | |
514 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
515 =head2 C<PostImpl($action)> |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
516 |
198 | 517 =over |
518 | |
519 =item C<$action> | |
520 | |
521 Текущий запрос C<IMPL::Web::Application::Action>. | |
522 | |
523 =back | |
524 | |
525 Переадресует запрос нужному методу внутреннего объекта C<target> при | |
526 помощи C<InvokeMember>. | |
527 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
528 =head2 C<DeleteImpl($action)> |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
529 |
198 | 530 =over |
531 | |
532 =item C<$action> | |
533 | |
534 Текущий запрос C<IMPL::Web::Application::Action>. | |
535 | |
536 =back | |
537 | |
538 Переадресует запрос нужному методу внутреннего объекта C<target> при | |
539 помощи C<InvokeMember>. | |
540 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
541 =head2 C<InvokeMember($memberInfo,$action,$params)> |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
542 |
198 | 543 =over |
544 | |
545 =item C<$memberInfo> | |
546 | |
547 Описание члена внутреннего объекта C<target>, который нужно вызвать. | |
548 | |
549 =item C<$action> | |
550 | |
551 Текущий запрос C<IMPL::Web::Application::Action>. | |
552 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
553 =item C<$params> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
554 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
555 Ссылка на хеш с предопределенными параметрами. |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
556 |
198 | 557 =back |
558 | |
559 Вызывает метод внутреннего объекта C<target>, предварительно подготовив | |
560 параметры на основе описания C<$memberInfo> и при помощи С<MakeParameter()>. | |
561 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
562 =head2 C<MakeParameter($paramDef,$action)> |
198 | 563 |
564 =over | |
565 | |
566 =item C<$paramDef> | |
567 | |
568 Описание параметра, может быть C<IMPL::Transform> или простая строка. | |
569 | |
570 Если описание параметра - простая строка, то ее имя либо | |
571 | |
572 =over | |
573 | |
574 =item C<id> | |
575 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
576 Идентификатор ресурса |
198 | 577 |
578 =item C<query> | |
579 | |
580 Объект C<CGI> текущего запроса | |
581 | |
582 =item C<action> | |
583 | |
584 Текущий запрос C<IMPL::Web::Application::Action> | |
585 | |
586 =item C<любое другое значение> | |
587 | |
588 Интерпретируется как параметр текущего запроса. | |
589 | |
590 =back | |
591 | |
592 Если описание параметра - объект C<IMPL::Transform>, то будет выполнено это преобразование над C<CGI> | |
593 объектом текущего запроса C<< $paramDef->Transform($action->query) >>. | |
594 | |
202
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
595 =item C<$action> |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
596 |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
597 Текущий запрос |
5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
sergey
parents:
201
diff
changeset
|
598 |
198 | 599 =back |
600 | |
196 | 601 =cut |