Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/RestResource.pm @ 197:6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
IMPL::Transform now admires object inheritance while searching for the transformation
Added HTTP some exceptions
IMPL::Web::Application::RestResource almost implemented
author | sergey |
---|---|
date | Thu, 19 Apr 2012 02:10:02 +0400 |
parents | a705e848dcc7 |
children | 2ffe6f661605 |
rev | line source |
---|---|
196 | 1 package IMPL::Web::Application::RestResource; |
2 use strict; | |
3 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
4 use IMPL::lang qw(:declare :constants); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
5 use IMPL::declare { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
6 require => { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
7 ForbiddenException => 'IMPL::Web::ForbiddenException' |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
8 }, |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
9 base => { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
10 'IMPL::Object' => undef |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
11 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
12 }; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
13 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
14 BEGIN { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
15 public property target => PROP_GET | PROP_OWNERSET; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
16 public property methods => PROP_GET | PROP_OWNERSET; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
17 public property childRegex => PROP_GET | PROP_OWNERSET; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
18 public property list => PROP_GET | PROP_OWNERSET; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
19 public property fetch => PROP_GET | PROP_OWNERSET; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
20 public property insert => PROP_GET | PROP_OWNERSET; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
21 public property update => PROP_GET | PROP_OWNERSET; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
22 public property delete => PROP_GET | PROP_OWNERSET; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
23 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
24 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
25 sub GetHttpImpl { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
26 my($this,$method) = @_; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
27 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
28 my %map = ( |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
29 GET => 'GetImpl', |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
30 PUT => 'PutImpl', |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
31 POST => 'PostImpl', |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
32 DELETE => 'DeleteImpl' |
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 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
35 return $map{$method}; |
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 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
38 sub InvokeHttpMethod { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
39 my ($this,$method,$child,$action) = @_; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
40 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
41 my $impl = $this->GetHttpImpl($method) || 'FallbackImpl'; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
42 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
43 return $this->$impl($child,$action); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
44 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
45 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
46 sub GetImpl { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
47 my ($this,$id,$action) = @_; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
48 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
49 my $rx; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
50 my $method; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
51 if (length $id == 0) { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
52 $method = $this->list; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
53 } elsif ($method = $this->methods->{$id}) { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
54 if (ref $method eq 'HASH' and not $method->{allowGet}) { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
55 die ForbiddenException->new(); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
56 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
57 } elsif($rx = $this->childRegex and $id =~ m/$rx/ ) { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
58 $method = $this->fetch or die ForbiddenException->new(); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
59 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
60 $method = { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
61 method => $method, |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
62 parameters => [qw(id)] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
63 } unless ref $method; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
64 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
65 } else { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
66 die ForbiddenException->new(); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
67 } |
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 return $this->InvokeMember($method,$id,$action); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
70 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
71 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
72 sub PutImpl { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
73 my ($this,$id,$action) = @_; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
74 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
75 my $rx = $this->childRegex; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
76 if ( $rx and $id =~ m/$rx/ and $this->update ) { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
77 my $method = $this->update or die ForbiddenException->new(); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
78 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
79 $method = { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
80 method => $method, |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
81 parameters => [qw(id query)] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
82 } unless ref $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 return $this->InvokeMember($method,$id,$action); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
85 } else { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
86 die ForbiddenException->new(); |
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 } |
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 sub PostImpl { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
91 my ($this,$id,$action) = @_; |
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 my $method; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
94 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
95 if (length $id == 0) { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
96 $method = $this->insert or die ForbiddenException->new(); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
97 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
98 $method = { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
99 method => $method, |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
100 parameters => [qw(query)] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
101 } unless ref $method; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
102 } elsif ($method = $this->methods->{$id}) { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
103 die ForbiddenException->new() unless ref $method and $method->{allowPost}; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
104 } else { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
105 die ForbiddenException->new(); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
106 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
107 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
108 return $this->InvokeMemeber($method,$id,$action); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
109 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
110 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
111 sub DeleteImpl { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
112 my ($this,$id,$action) = @_; |
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 my $rx = $this->childRegex; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
115 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
|
116 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
117 $method = { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
118 method => $method, |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
119 parameters => [qw(id)] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
120 } unless ref $method; |
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 return $this->InvokeMember($method,$id,$action); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
123 } else { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
124 die ForbiddenException->new(); |
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 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
127 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
128 sub HttpFallbackImpl { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
129 die ForbiddenException->new(); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
130 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
131 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
132 sub InvokeMember { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
133 my ($this,$method,$id,$action) = @_; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
134 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
135 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
136 |
196 | 137 1; |
138 | |
139 __END__ | |
140 | |
141 =pod | |
142 | |
143 =head1 NAME | |
144 | |
145 C<IMPL::Web::Application::RestResource> - ресурс Rest вебсервиса. | |
146 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
147 =head1 SYNOPSIS |
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 =begin text |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
150 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
151 [REQUEST] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
152 GET /artists |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
153 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
154 [RESPONSE] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
155 <artists> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
156 <artist id="1"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
157 <name>The Beatles <name/> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
158 </atrist> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
159 <artist id="2"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
160 <name>Bonobo</name> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
161 </artist> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
162 </artists> |
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 [REQUEST] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
165 GET /artists/1/cds?title='Live at BBC' |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
166 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
167 [RESPONSE] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
168 <cds> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
169 <cd id="14"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
170 <title>Live at BBC 1</title> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
171 </cd> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
172 <cd id="15"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
173 <title>Live at BBC 2</title> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
174 </cd> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
175 </cds> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
176 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
177 [REQUEST] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
178 GET /cds/15 |
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 [RESPONSE] |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
181 <cd id="15"> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
182 <title>Live at BBC 2</title> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
183 </cd> |
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 =end text |
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 =begin code |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
188 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
189 use IMPL::require { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
190 TRes => 'IMPL::Web:Application::RestResource', |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
191 DataContext => 'My::App::DataContext' |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
192 }; |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
193 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
194 my $cds = TRes->new( |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
195 DataContext->Default, |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
196 { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
197 methods => { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
198 get => { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
199 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
200 }, |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
201 post => { |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
202 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
203 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
204 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
205 get => 'search', |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
206 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
207 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
208 } |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
209 ); |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
210 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
211 =end code |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
212 |
196 | 213 =head1 DESCRIPTION |
214 | |
197
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
215 Каждый ресурс представляет собой коллекцию и реализует методы C<HTTP> C<GET,POST,PUT,DELETE>. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
216 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
217 =head2 HTTP METHODS |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
218 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
219 =head3 C<GET> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
220 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
221 Возвращает коллекцию дочерних ресурсов. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
222 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
223 =head3 C<GET {id}> |
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 Возвращает дочерний объект с идентификатором C<id> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
226 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
227 =head3 C<GET {method}> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
228 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
229 Вызывает метод C<method> и возвращает его результаты. При публикации методов доступных |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
230 через C<GET> данные методы не должны вносить изменений в предметную область. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
231 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
232 =head3 C<PUT {id}> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
233 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
234 Обновляет дочерний ресурс с указанным идентификатором. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
235 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
236 =head3 C<DELETE {id}> |
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 Удаляет дочерний ресурс с указанным идентификатором. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
239 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
240 =head3 C<POST> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
241 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
242 Добавляет новый дочерний ресурс в коллекцию. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
243 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
244 =head2 HTTP METHOD MAPPING |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
245 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
246 =head3 C<POST {method}> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
247 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
248 Вызывает метод C<method>, в отличии от C<GET> методы опубликованные через C<POST> могут вносить |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
249 изменения в объекты. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
250 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
251 =head1 MEMBERS |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
252 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
253 =head2 C<[get]target> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
254 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
255 Объект (также может быть и класс), обеспечивающий функционал ресурса. |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
256 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
257 =head2 C<[get]methods> |
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 =head2 C<[get]childRegex> |
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 =head2 C<[get]fetch> |
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 =head2 C<[get]list> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
264 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
265 =head2 C<[get]insert> |
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 =head2 C<[get]update> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
268 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
269 =head2 C<[get]delete> |
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 =head2 C<GetImpl($child,$action)> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
272 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
273 =head2 C<PutImpl($child,$action)> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
274 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
275 =head2 C<PostImpl($child,$action)> |
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 =head2 C<DeleteImpl($child,$action)> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
278 |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
279 =head2 C<InvokeMember($memberInfo,$child,$action)> |
6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
196
diff
changeset
|
280 |
196 | 281 =cut |