Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/ResourceContract.pm @ 319:d485467eca92
small fixes
author | cin |
---|---|
date | Wed, 15 May 2013 02:00:42 +0400 |
parents | 673581380e79 |
children | fe725fad2d90 |
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', |
abc7c26bf615
+Added ObjectFactory for templates with static members support
sergey
parents:
230
diff
changeset
|
11 ResourceClass => 'IMPL::Web::Application::Resource' |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
12 }, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
13 base => [ 'IMPL::Object' => undef ], |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
14 props => [ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
15 resourceFactory => PROP_ALL, |
248 | 16 verbs => PROP_ALL, |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
17 _namedResources => PROP_ALL, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
18 _regexpResources => PROP_ALL | PROP_LIST, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
19 ] |
226 | 20 }; |
21 | |
227 | 22 sub CTOR { |
23 my $this = shift; | |
24 my %args = @_; | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
25 |
227 | 26 $this->resourceFactory( $args{resourceFactory} || ResourceClass ); |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
27 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
28 my $resources = $args{resources} || []; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
29 my $verbs = $args{verbs} || {}; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
30 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
31 die ArgumentException->new( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
32 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
|
33 unless ref $resources eq 'ARRAY'; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
34 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
35 die ArgumentException->new( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
36 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
|
37 unless ref $verbs eq 'HASH'; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
38 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
39 $this->verbs( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
40 { map { lc($_), $verbs->{$_} } keys %$verbs } ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
41 |
228 | 42 my %nameMap; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
43 |
230 | 44 foreach my $res (@$resources) { |
302 | 45 if (ref $res->{contract} eq 'HASH') { |
46 $res->{contract} = __PACKAGE__->new(%{$res->{contract}}); | |
47 } | |
48 | |
228 | 49 next unless $res->{contract}; |
302 | 50 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
51 if ( my $name = $res->{name} ) { |
228 | 52 $nameMap{$name} = $res; |
53 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
54 if ( $res->{match} ) { |
228 | 55 $this->_regexpResources->Append($res); |
56 } | |
57 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
58 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
59 $this->_namedResources( \%nameMap ); |
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
62 sub AddChildResourceContract { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
63 my ($this,$res) = @_; |
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 die ArgumentException->new(res => "A valid child resource definition") |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
66 unless ref $res eq 'HASH'; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
67 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
68 $this->_namedResources->{$res->{name}} = $res if $res->{name}; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
69 $this->_regexpResources->Append($res) if $res->{match}; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
70 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
71 return; |
227 | 72 } |
73 | |
74 sub CreateResource { | |
228 | 75 my $this = shift; |
76 my %args = @_; | |
77 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
78 return $this->resourceFactory->new( %args, contract => $this ); |
228 | 79 } |
80 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
81 sub FindChildResourceInfo { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
82 my ( $this, $name ) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
83 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
84 if ( my $info = $this->_namedResources->{$name} ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
85 return $info, [$name]; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
86 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
87 else { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
88 foreach my $info ( $this->_regexpResources ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
89 my $rx = $info->{match}; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
90 if(my @childId = $name =~ m/$rx/) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
91 return $info, \@childId; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
92 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
93 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
94 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
95 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
96 return; |
227 | 97 } |
98 | |
226 | 99 1; |
100 | |
101 __END__ | |
102 | |
103 =pod | |
104 | |
105 =head1 NAME | |
106 | |
107 C<IMPL::Web::Application::ResourceContract> - описание ресурса | |
108 | |
109 =head1 SYNIOSIS | |
110 | |
111 =begin code | |
112 | |
113 use IMPL::require { | |
114 ResourceContract => 'IMPL::Web::Application::ResourceContract', | |
115 OperationContract => 'IMPL::Web::Application::OperationContract' | |
116 }; | |
117 | |
118 my $contract = ResourceContract->new( | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
119 verbs => { |
226 | 120 get => OperationContract->new( |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
121 binding => sub { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
122 my ($resource,$action) = @_; |
226 | 123 return "Hello!"; |
124 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
125 ), |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
126 post => OperationContract->new( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
127 parameters => [ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
128 IMPL::Transform::DataToModel->new() # создаем преобразование для формы |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
129 ], |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
130 binding => sub { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
131 my ($resource,$action,$data) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
132 return $resource->model->AddItem($data); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
133 }, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
134 success => sub { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
135 my ($resource,$action,$result) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
136 return IMPL::Web::HttpResponse->Redirect( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
137 location => $resource->location->Child($result->id) |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
138 ) |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
139 }, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
140 error => sub { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
141 my ($resource,$action,$error) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
142 $action->errors->Append($error); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
143 return $resource->model; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
144 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
145 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
146 ), |
226 | 147 }, |
148 resources => [ | |
149 { | |
150 name => 'info', | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
151 binding => sub { |
226 | 152 return $_[0]->model->info; |
153 }, | |
154 contract => ResourceContract->new( | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
155 verbs => { |
285
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
156 # using method references is also possible |
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
157 get => sub { |
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
158 my ($resource,$action) = @_; |
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
159 return $resource->model; |
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
160 } |
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
161 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
162 } |
226 | 163 ) |
164 } | |
165 ] | |
166 ) | |
167 | |
227 | 168 my $obj = My::App::Data->fetch('something'); |
169 | |
170 my $resource = $contract->CreateResource( | |
171 model => $obj, | |
172 parent => $prentResource, | |
173 id => 'item-something' | |
174 ); | |
175 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
176 my $child = $contract->FetchChildResource('info'); |
228 | 177 |
226 | 178 =end code |
179 | |
180 =head1 DESCRIPTION | |
181 | |
229
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 предметной области. Контракты используются инфраструктурой и пользователь |
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 Каждая операция над ресурсом C<IMPL::Web::Application::OperationContract> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
194 описывается преобразованием параметров, привязкой к предметной области, |
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 Основное назначение контракта - создавать объекты ресурсов, над которыми |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
199 контроллер запросов C<HTTP> сможет выполнить операцию. Контракт может создавать |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
200 дочерние ресурсы, на основе указанного родительского ресурса и идетификатора |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
201 нового ресурса. При этом будет найден подходящий контракт для дочернего ресурса |
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 =head2 Динамический контракт |
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 реализовывать метод C<CreateResource(%args)>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
209 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
210 Результатом выполнения этого метода должен быть Web-ресурс, см. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
211 C<IMPL::Web::Application::Resource>. Другими словами не существует жесткого |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
212 требования к реализации самого контракта, как и того, что созданный ресурс |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
213 должен ссылаться именно на этот контракт (да и вообще ссылаться на контракт). |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
214 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
215 Таким образом можно реализовать контракт, который выполняет роль посредника, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
216 ниже приведен пример, который выбирает нужный контракт на основе типа модели |
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
219 =begin code |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
220 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
221 package My::Web::Application::ContractMapper; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
222 use strict; |
230 | 223 use IMPL::Const qw(:prop); |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
224 use IMPL::declare { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
225 require => { |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
226 ForbiddenException => 'IMPL::Web::ForbiddenException' |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
227 }, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
228 base => [ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
229 'IMPL::Object' => undef, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
230 'IMPL::Object::Autofill' => '@_' |
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 props => [ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
233 map => PROP_GET | PROP_OWNERSET |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
234 ] |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
235 } |
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 sub CreateResource { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
238 my ($this,%args) = @_; |
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 my $type = ref $args{model} || '_default'; |
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 my $contract = $this->map->{$type}; |
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 die ForbiddenException->new() |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
245 unless $contract; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
246 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
247 return $contract->CreateResource(%args); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
248 } |
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 =end code |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
251 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
252 =head1 MEMBERS |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
253 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
254 =head2 C<CTOR(%args)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
255 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
256 =over |
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<resourceFactory> |
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 Фабрика объектов C<IMPL::Object::Factory> которая будет использоваться при |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
261 создании новых ресурсов. По-умолчанию C<IMPL::Web::Application::Resource>. |
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 =item * C<operations> |
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 Хеш с доступными действиями над C<HTTP> ресурсом, ключом является имя ресурса, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
266 значением C<IMPL::Web::Application::OperationContract>. |
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 =item * C<resources> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
269 |
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 =over |
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 =item * C<name> |
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
279 =item * C<match> |
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 Регулярное выражение, которому должно удовлетворять имя дочернего ресурса. |
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 =item * C<bind> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
284 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
285 Делегат, получающий модель для дочернего ресурса. Первым параметром ему |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
286 передается родительский объект, далее передаются граппы из регулярного |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
287 выражения, если это ресурс с именем удовлетворяющим регулярному выражению из |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
288 элемента C<match>, либо имя ресурса, если это ресурс с именем, указанным в |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
289 элементе C<name>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
290 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
291 =item * C<contract> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
292 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
293 Ссылка на C<IMPL::Web::Application::ResourceContract> для дочернего ресурса. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
294 У данного контракта используется только метод C<CreateContract>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
295 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
296 Для реализации отложенной загрузки контракта (чтобы снизить ресурсоемкость |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
297 запуска приложения) вместо ссылки на контракт может быть либо ссылка на |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
298 процедуру, либо объект имеющий метод C<Invoke>. |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
299 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
300 =back |
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 По крайней мере C<name> или C<match> должны присутсвовать. |
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 =back |
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 =head2 C<CreateResource(%args)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
307 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
308 Создает ресурс, параметры C<%args> будут переданы напрямую констркутору |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
309 ресурса, для создания ресурса используется фабрика C<resourceFactory>. |
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 |
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 =head2 C<FindChildResourceInfo($childId)> |
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 Используется для поиска информации о дочернем ресурсе, возвращает список из двух |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
317 элементов. C<($info,$childIdParts)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
318 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
319 =over |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
320 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
321 =item * C<$info> |
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 Информация о контракте дочернего ресурса, как правило это ссылка на хеш, похожий |
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
326 =back |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
327 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
328 =head2 C<[get]verbs> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
329 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
330 Хеш с доступными действиями над C<HTTP> ресурсом, все имена операций приведены |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
331 к нижнему регистру. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
332 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
333 =begin code |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
334 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
335 my $result = $contract->verbs->{get}->Invoke($resource,$action); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
336 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
337 =end code |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
338 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
339 =cut |