Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/ResourceContract.pm @ 332:04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
author | cin |
---|---|
date | Sun, 09 Jun 2013 21:48:57 +0400 |
parents | 2ff1726c066c |
children |
rev | line source |
---|---|
226 | 1 package IMPL::Web::Application::ResourceContract; |
2 use strict; | |
302 | 3 |
4 use IMPL::lang; | |
230 | 5 use IMPL::Const qw(:prop); |
226 | 6 use IMPL::declare { |
227 | 7 require => { |
240
abc7c26bf615
+Added ObjectFactory for templates with static members support
sergey
parents:
230
diff
changeset
|
8 Exception => 'IMPL::Exception', |
abc7c26bf615
+Added ObjectFactory for templates with static members support
sergey
parents:
230
diff
changeset
|
9 ArgumentException => '-IMPL::ArgumentException', |
abc7c26bf615
+Added ObjectFactory for templates with static members support
sergey
parents:
230
diff
changeset
|
10 KeyNotFoundException => '-IMPL::KeyNotFoundException', |
330 | 11 ResourceClass => 'IMPL::Web::Application::CustomResource', |
12 CustomContract => 'IMPL::Web::Application::CustomResourceContract', | |
13 Factory => 'IMPL::Object::Factory' | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
14 }, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
15 base => [ 'IMPL::Object' => undef ], |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
16 props => [ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
17 resourceFactory => PROP_ALL, |
248 | 18 verbs => PROP_ALL, |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
19 _namedResources => PROP_ALL, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
20 _regexpResources => PROP_ALL | PROP_LIST, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
21 ] |
226 | 22 }; |
23 | |
227 | 24 sub CTOR { |
25 my $this = shift; | |
26 my %args = @_; | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
27 |
330 | 28 my $factory = delete $args{resourceFactory} || ResourceClass; |
29 my $resources = delete $args{resources} || []; | |
30 my $verbs = delete $args{verbs} || {}; | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
31 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
32 die ArgumentException->new( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
33 resources => 'resources parameter must be a reference to an array' ) |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
34 unless ref $resources eq 'ARRAY'; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
35 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
36 die ArgumentException->new( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
37 opearations => 'operations parameter must be a reference to a hash' ) |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
38 unless ref $verbs eq 'HASH'; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
39 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
40 $this->verbs( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
41 { map { lc($_), $verbs->{$_} } keys %$verbs } ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
42 |
228 | 43 my %nameMap; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
44 |
230 | 45 foreach my $res (@$resources) { |
302 | 46 if (ref $res->{contract} eq 'HASH') { |
331 | 47 # custom contract will add OPTIONS verb if needed |
48 $res->{contract} = CustomContract->new(%{$res->{contract}}); | |
302 | 49 } |
50 | |
228 | 51 next unless $res->{contract}; |
302 | 52 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
53 if ( my $name = $res->{name} ) { |
228 | 54 $nameMap{$name} = $res; |
55 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
56 if ( $res->{match} ) { |
228 | 57 $this->_regexpResources->Append($res); |
58 } | |
59 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
60 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
61 $this->_namedResources( \%nameMap ); |
330 | 62 |
63 $this->resourceFactory( %args ? Factory->new($factory,\%args) : $factory ); | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
64 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
65 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
66 sub AddChildResourceContract { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
67 my ($this,$res) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
68 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
69 die ArgumentException->new(res => "A valid child resource definition") |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
70 unless ref $res eq 'HASH'; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
71 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
72 $this->_namedResources->{$res->{name}} = $res if $res->{name}; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
73 $this->_regexpResources->Append($res) if $res->{match}; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
74 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
75 return; |
227 | 76 } |
77 | |
78 sub CreateResource { | |
228 | 79 my $this = shift; |
80 my %args = @_; | |
81 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
82 return $this->resourceFactory->new( %args, contract => $this ); |
228 | 83 } |
84 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
85 sub FindChildResourceInfo { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
86 my ( $this, $name ) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
87 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
88 if ( my $info = $this->_namedResources->{$name} ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
89 return $info, [$name]; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
90 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
91 else { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
92 foreach my $info ( $this->_regexpResources ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
93 my $rx = $info->{match}; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
94 if(my @childId = $name =~ m/$rx/) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
95 return $info, \@childId; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
96 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
97 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
98 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
99 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
100 return; |
227 | 101 } |
102 | |
226 | 103 1; |
104 | |
105 __END__ | |
106 | |
107 =pod | |
108 | |
109 =head1 NAME | |
110 | |
111 C<IMPL::Web::Application::ResourceContract> - описание ресурса | |
112 | |
113 =head1 SYNIOSIS | |
114 | |
115 =begin code | |
116 | |
117 use IMPL::require { | |
118 ResourceContract => 'IMPL::Web::Application::ResourceContract', | |
119 OperationContract => 'IMPL::Web::Application::OperationContract' | |
120 }; | |
121 | |
122 my $contract = ResourceContract->new( | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
123 verbs => { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
331
diff
changeset
|
124 get => sub { |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
331
diff
changeset
|
125 my ($resource,$action) = @_; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
331
diff
changeset
|
126 return "Hello!"; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
331
diff
changeset
|
127 }, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
331
diff
changeset
|
128 post => OperationContract->new( |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
129 binding => sub { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
130 my ($resource,$action) = @_; |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
331
diff
changeset
|
131 my $data = My::App::ModelBinder->new($resource->ds)->Bind($action); |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
132 return IMPL::Web::HttpResponse->Redirect( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
133 location => $resource->location->Child($result->id) |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
134 ) |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
135 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
136 ), |
226 | 137 }, |
138 resources => [ | |
139 { | |
140 name => 'info', | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
141 binding => sub { |
226 | 142 return $_[0]->model->info; |
143 }, | |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
331
diff
changeset
|
144 contract => { |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
145 verbs => { |
285
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
146 get => sub { |
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
147 my ($resource,$action) = @_; |
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
148 return $resource->model; |
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
149 } |
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
150 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
151 } |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
331
diff
changeset
|
152 } |
226 | 153 } |
154 ] | |
155 ) | |
156 | |
227 | 157 my $obj = My::App::Data->fetch('something'); |
158 | |
159 my $resource = $contract->CreateResource( | |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
331
diff
changeset
|
160 request => $currentRequest, |
227 | 161 model => $obj, |
162 parent => $prentResource, | |
163 id => 'item-something' | |
164 ); | |
165 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
166 my $child = $contract->FetchChildResource('info'); |
228 | 167 |
226 | 168 =end code |
169 | |
170 =head1 DESCRIPTION | |
171 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
172 Контракт описывает структуру Веб-ресурса и отображение операций над ним в методы |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
173 предметной области. Контракты используются инфраструктурой и пользователь |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
174 не использует их напрямую, до тех пор пока не требуется изменить стандартный |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
175 функционал. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
176 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
177 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
178 Ресурс представляе собой набор контрактов операций, соответствующих методам |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
179 C<HTTP> которые доступны у данного ресурса. Кроме операций ресурс состоит из |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
180 дочерних ресурсов, которые могут соответствовать регулярным выражениям, либо |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
181 иметь фиксированные имена. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
182 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
183 Каждая операция над ресурсом C<IMPL::Web::Application::OperationContract> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
184 описывается преобразованием параметров, привязкой к предметной области, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
185 дополнительным обработчиком результата выполнения привязки, либо обработчиком |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
186 исключения, если привязку не удалось выполнить. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
187 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
188 Основное назначение контракта - создавать объекты ресурсов, над которыми |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
189 контроллер запросов C<HTTP> сможет выполнить операцию. Контракт может создавать |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
190 дочерние ресурсы, на основе указанного родительского ресурса и идетификатора |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
191 нового ресурса. При этом будет найден подходящий контракт для дочернего ресурса |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
192 и с его помощью создан дочерний ресурс. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
193 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
194 =head2 Динамический контракт |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
195 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
196 Основная функция контракта - превращать данные модели предметной области в |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
197 данные ресурсной модели, тоесть в ресурсы, для чего каждый контракт обязан |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
198 реализовывать метод C<CreateResource(%args)>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
199 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
200 Результатом выполнения этого метода должен быть Web-ресурс, см. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
201 C<IMPL::Web::Application::Resource>. Другими словами не существует жесткого |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
202 требования к реализации самого контракта, как и того, что созданный ресурс |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
203 должен ссылаться именно на этот контракт (да и вообще ссылаться на контракт). |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
204 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
205 Таким образом можно реализовать контракт, который выполняет роль посредника, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
206 ниже приведен пример, который выбирает нужный контракт на основе типа модели |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
207 переданной для создания ресурса. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
208 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
209 =begin code |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
210 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
211 package My::Web::Application::ContractMapper; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
212 use strict; |
230 | 213 use IMPL::Const qw(:prop); |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
214 use IMPL::declare { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
215 require => { |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
216 ForbiddenException => 'IMPL::Web::ForbiddenException' |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
217 }, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
218 base => [ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
219 'IMPL::Object' => undef, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
220 'IMPL::Object::Autofill' => '@_' |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
221 ], |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
222 props => [ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
223 map => PROP_GET | PROP_OWNERSET |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
224 ] |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
225 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
226 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
227 sub CreateResource { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
228 my ($this,%args) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
229 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
230 my $type = ref $args{model} || '_default'; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
231 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
232 my $contract = $this->map->{$type}; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
233 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
234 die ForbiddenException->new() |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
235 unless $contract; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
236 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
237 return $contract->CreateResource(%args); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
238 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
239 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
240 =end code |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
241 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
242 =head1 MEMBERS |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
243 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
244 =head2 C<CTOR(%args)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
245 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
246 =over |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
247 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
248 =item * C<resourceFactory> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
249 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
250 Фабрика объектов C<IMPL::Object::Factory> которая будет использоваться при |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
251 создании новых ресурсов. По-умолчанию C<IMPL::Web::Application::Resource>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
252 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
253 =item * C<operations> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
254 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
255 Хеш с доступными действиями над C<HTTP> ресурсом, ключом является имя ресурса, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
256 значением C<IMPL::Web::Application::OperationContract>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
257 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
258 =item * C<resources> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
259 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
260 Ссылка на массив хешей, каждый хеш описывает правила, как получить дочерний |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
261 ресурс и связать его с контрактом. Ниже преведено описание элементов хеша. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
262 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
263 =over |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
264 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
265 =item * C<name> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
266 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
267 Имя дочернегно ресурса. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
268 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
269 =item * C<match> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
270 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
271 Регулярное выражение, которому должно удовлетворять имя дочернего ресурса. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
272 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
273 =item * C<bind> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
274 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
275 Делегат, получающий модель для дочернего ресурса. Первым параметром ему |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
276 передается родительский объект, далее передаются граппы из регулярного |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
277 выражения, если это ресурс с именем удовлетворяющим регулярному выражению из |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
278 элемента C<match>, либо имя ресурса, если это ресурс с именем, указанным в |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
279 элементе C<name>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
280 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
281 =item * C<contract> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
282 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
283 Ссылка на C<IMPL::Web::Application::ResourceContract> для дочернего ресурса. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
284 У данного контракта используется только метод C<CreateContract>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
285 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
286 Для реализации отложенной загрузки контракта (чтобы снизить ресурсоемкость |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
287 запуска приложения) вместо ссылки на контракт может быть либо ссылка на |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
288 процедуру, либо объект имеющий метод C<Invoke>. |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
289 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
290 =back |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
291 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
292 По крайней мере C<name> или C<match> должны присутсвовать. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
293 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
294 =back |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
295 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
296 =head2 C<CreateResource(%args)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
297 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
298 Создает ресурс, параметры C<%args> будут переданы напрямую констркутору |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
299 ресурса, для создания ресурса используется фабрика C<resourceFactory>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
300 При создании, конгструктору ресурса, будет передана ссылка на текущй контракт. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
301 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
302 По-сути никакого дополнительного функционала данный метод не несет. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
303 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
304 =head2 C<FindChildResourceInfo($childId)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
305 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
306 Используется для поиска информации о дочернем ресурсе, возвращает список из двух |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
307 элементов. C<($info,$childIdParts)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
308 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
309 =over |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
310 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
311 =item * C<$info> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
312 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
313 Информация о контракте дочернего ресурса, как правило это ссылка на хеш, похожий |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
314 по формату на |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
315 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
316 =back |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
317 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
318 =head2 C<[get]verbs> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
319 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
320 Хеш с доступными действиями над C<HTTP> ресурсом, все имена операций приведены |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
321 к нижнему регистру. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
322 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
323 =begin code |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
324 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
325 my $result = $contract->verbs->{get}->Invoke($resource,$action); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
326 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
327 =end code |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
328 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
329 =cut |