Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/ResourceContract.pm @ 330:fe725fad2d90
Added access checking to web resources
| author | sergey |
|---|---|
| date | Tue, 04 Jun 2013 19:25:54 +0400 |
| parents | 673581380e79 |
| children | 2ff1726c066c |
| 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') { |
| 47 $res->{contract} = __PACKAGE__->new(%{$res->{contract}}); | |
| 48 } | |
| 49 | |
| 228 | 50 next unless $res->{contract}; |
| 302 | 51 |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
52 if ( my $name = $res->{name} ) { |
| 228 | 53 $nameMap{$name} = $res; |
| 54 } | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
55 if ( $res->{match} ) { |
| 228 | 56 $this->_regexpResources->Append($res); |
| 57 } | |
| 58 } | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
59 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
60 $this->_namedResources( \%nameMap ); |
| 330 | 61 |
| 62 $this->resourceFactory( %args ? Factory->new($factory,\%args) : $factory ); | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
63 } |
|
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 sub AddChildResourceContract { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
66 my ($this,$res) = @_; |
|
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 die ArgumentException->new(res => "A valid child resource definition") |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
69 unless ref $res eq 'HASH'; |
|
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 $this->_namedResources->{$res->{name}} = $res if $res->{name}; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
72 $this->_regexpResources->Append($res) if $res->{match}; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
73 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
74 return; |
| 227 | 75 } |
| 76 | |
| 77 sub CreateResource { | |
| 228 | 78 my $this = shift; |
| 79 my %args = @_; | |
| 80 | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
81 return $this->resourceFactory->new( %args, contract => $this ); |
| 228 | 82 } |
| 83 | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
84 sub FindChildResourceInfo { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
85 my ( $this, $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 if ( my $info = $this->_namedResources->{$name} ) { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
88 return $info, [$name]; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
89 } |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
90 else { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
91 foreach my $info ( $this->_regexpResources ) { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
92 my $rx = $info->{match}; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
93 if(my @childId = $name =~ m/$rx/) { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
94 return $info, \@childId; |
|
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 } |
|
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 return; |
| 227 | 100 } |
| 101 | |
| 226 | 102 1; |
| 103 | |
| 104 __END__ | |
| 105 | |
| 106 =pod | |
| 107 | |
| 108 =head1 NAME | |
| 109 | |
| 110 C<IMPL::Web::Application::ResourceContract> - описание ресурса | |
| 111 | |
| 112 =head1 SYNIOSIS | |
| 113 | |
| 114 =begin code | |
| 115 | |
| 116 use IMPL::require { | |
| 117 ResourceContract => 'IMPL::Web::Application::ResourceContract', | |
| 118 OperationContract => 'IMPL::Web::Application::OperationContract' | |
| 119 }; | |
| 120 | |
| 121 my $contract = ResourceContract->new( | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
122 verbs => { |
| 226 | 123 get => OperationContract->new( |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
124 binding => sub { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
125 my ($resource,$action) = @_; |
| 226 | 126 return "Hello!"; |
| 127 } | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
128 ), |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
129 post => OperationContract->new( |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
130 parameters => [ |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
131 IMPL::Transform::DataToModel->new() # создаем преобразование для формы |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
132 ], |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
133 binding => sub { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
134 my ($resource,$action,$data) = @_; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
135 return $resource->model->AddItem($data); |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
136 }, |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
137 success => sub { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
138 my ($resource,$action,$result) = @_; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
139 return IMPL::Web::HttpResponse->Redirect( |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
140 location => $resource->location->Child($result->id) |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
141 ) |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
142 }, |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
143 error => sub { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
144 my ($resource,$action,$error) = @_; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
145 $action->errors->Append($error); |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
146 return $resource->model; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
147 } |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
148 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
149 ), |
| 226 | 150 }, |
| 151 resources => [ | |
| 152 { | |
| 153 name => 'info', | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
154 binding => sub { |
| 226 | 155 return $_[0]->model->info; |
| 156 }, | |
| 157 contract => ResourceContract->new( | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
158 verbs => { |
|
285
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
159 # using method references is also possible |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
160 get => sub { |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
161 my ($resource,$action) = @_; |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
162 return $resource->model; |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
163 } |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
164 |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
165 } |
| 226 | 166 ) |
| 167 } | |
| 168 ] | |
| 169 ) | |
| 170 | |
| 227 | 171 my $obj = My::App::Data->fetch('something'); |
| 172 | |
| 173 my $resource = $contract->CreateResource( | |
| 174 model => $obj, | |
| 175 parent => $prentResource, | |
| 176 id => 'item-something' | |
| 177 ); | |
| 178 | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
179 my $child = $contract->FetchChildResource('info'); |
| 228 | 180 |
| 226 | 181 =end code |
| 182 | |
| 183 =head1 DESCRIPTION | |
| 184 | |
|
229
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 |
|
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 C<HTTP> которые доступны у данного ресурса. Кроме операций ресурс состоит из |
|
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 иметь фиксированные имена. |
|
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 Каждая операция над ресурсом C<IMPL::Web::Application::OperationContract> |
|
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 исключения, если привязку не удалось выполнить. |
|
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 контроллер запросов C<HTTP> сможет выполнить операцию. Контракт может создавать |
|
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 =head2 Динамический контракт |
|
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 Основная функция контракта - превращать данные модели предметной области в |
|
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 реализовывать метод C<CreateResource(%args)>. |
|
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 Результатом выполнения этого метода должен быть Web-ресурс, см. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
214 C<IMPL::Web::Application::Resource>. Другими словами не существует жесткого |
|
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 ниже приведен пример, который выбирает нужный контракт на основе типа модели |
|
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 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
222 =begin code |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
223 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
224 package My::Web::Application::ContractMapper; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
225 use strict; |
| 230 | 226 use IMPL::Const qw(:prop); |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
227 use IMPL::declare { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
228 require => { |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
229 ForbiddenException => 'IMPL::Web::ForbiddenException' |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
230 }, |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
231 base => [ |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
232 'IMPL::Object' => undef, |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
233 'IMPL::Object::Autofill' => '@_' |
|
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 props => [ |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
236 map => PROP_GET | PROP_OWNERSET |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
237 ] |
|
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 sub CreateResource { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
241 my ($this,%args) = @_; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
242 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
243 my $type = ref $args{model} || '_default'; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
244 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
245 my $contract = $this->map->{$type}; |
|
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 die ForbiddenException->new() |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
248 unless $contract; |
|
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 return $contract->CreateResource(%args); |
|
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 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
253 =end code |
|
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 =head1 MEMBERS |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
256 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
257 =head2 C<CTOR(%args)> |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
258 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
259 =over |
|
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 =item * C<resourceFactory> |
|
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 Фабрика объектов C<IMPL::Object::Factory> которая будет использоваться при |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
264 создании новых ресурсов. По-умолчанию C<IMPL::Web::Application::Resource>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
265 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
266 =item * C<operations> |
|
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 Хеш с доступными действиями над C<HTTP> ресурсом, ключом является имя ресурса, |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
269 значением C<IMPL::Web::Application::OperationContract>. |
|
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 =item * C<resources> |
|
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 Ссылка на массив хешей, каждый хеш описывает правила, как получить дочерний |
|
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 =over |
|
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 =item * C<name> |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
279 |
|
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 =item * C<match> |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
283 |
|
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 =item * C<bind> |
|
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 Делегат, получающий модель для дочернего ресурса. Первым параметром ему |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
289 передается родительский объект, далее передаются граппы из регулярного |
|
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 элемента C<match>, либо имя ресурса, если это ресурс с именем, указанным в |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
292 элементе C<name>. |
|
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 =item * C<contract> |
|
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 Ссылка на C<IMPL::Web::Application::ResourceContract> для дочернего ресурса. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
297 У данного контракта используется только метод C<CreateContract>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
298 |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
299 Для реализации отложенной загрузки контракта (чтобы снизить ресурсоемкость |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
300 запуска приложения) вместо ссылки на контракт может быть либо ссылка на |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
301 процедуру, либо объект имеющий метод C<Invoke>. |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
248
diff
changeset
|
302 |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
303 =back |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
304 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
305 По крайней мере C<name> или C<match> должны присутсвовать. |
|
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 =back |
|
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 =head2 C<CreateResource(%args)> |
|
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 Создает ресурс, параметры C<%args> будут переданы напрямую констркутору |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
312 ресурса, для создания ресурса используется фабрика C<resourceFactory>. |
|
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 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
317 =head2 C<FindChildResourceInfo($childId)> |
|
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 Используется для поиска информации о дочернем ресурсе, возвращает список из двух |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
320 элементов. C<($info,$childIdParts)> |
|
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 =over |
|
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 =item * C<$info> |
|
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 Информация о контракте дочернего ресурса, как правило это ссылка на хеш, похожий |
|
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 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
329 =back |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
330 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
331 =head2 C<[get]verbs> |
|
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 Хеш с доступными действиями над C<HTTP> ресурсом, все имена операций приведены |
|
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 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
336 =begin code |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
337 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
338 my $result = $contract->verbs->{get}->Invoke($resource,$action); |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
339 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
340 =end code |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
341 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
228
diff
changeset
|
342 =cut |
