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