annotate Lib/IMPL/Web/Application/RestResource.pm @ 200:a9dbe534d236

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