annotate lib/IMPL/Web/Application/ResourceBase.pm @ 417:3ed0c58e9da3 ref20150831

working on di container, tests
author cin
date Mon, 02 Nov 2015 01:56:53 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::Web::Application::ResourceBase;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4 use URI;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use Carp qw(carp);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 use IMPL::lang qw(:hash :base);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 use IMPL::Const qw(:prop);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 use IMPL::declare {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 require => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 Exception => 'IMPL::Exception',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 ArgumentException => '-IMPL::InvalidArgumentException',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 OperationException => '-IMPL::InvalidOperationException',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 NotAllowedException => 'IMPL::Web::NotAllowedException',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 base => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 'IMPL::Object' => undef,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 'IMPL::Web::Application::ResourceInterface' => undef
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 ],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 props => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 request => PROP_RO,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 application => PROP_RO,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 parent => PROP_RO,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 model => PROP_RO,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26 id => PROP_RO,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 location => PROP_RO,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 role => PROP_RO | PROP_LIST
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29 ]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 my ( $this, %args ) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 die ArgumentException->new(request => 'A request object must be specified')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 unless $args{request};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38 $this->request( $args{request} );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 $this->parent( $args{parent} ) if $args{parent};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40 $this->model( $args{model} ) if $args{model};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 $this->id( $args{id} ) if $args{id};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 $this->application( $args{request}->application );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 # если расположение явно не указано, то оно вычисляется автоматически,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 # либо остается не заданным
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46 $this->location( $args{location}
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 || eval { $this->parent->location->Child( $this->id ) } );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49 if (my $role = $args{role}) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 if (ref($role) eq 'ARRAY') {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51 $this->role($role);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 } elsif (not ref($role)) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 $this->role(split(/\s+/, $role));
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 die ArgumentException->new( role => 'A invalid value is provided, expected ARRAY or SCALAR');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 sub InvokeHttpVerb {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61 my ( $this, $verb ) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 my $operation = $this->verbs->{ lc($verb) };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65 die NotAllowedException->new(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 allow => join( ',', $this->GetAllowedMethods ) )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67 unless $operation;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69 $this->AccessCheck($verb);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70 my $request = $this->request;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72 # в случае, когда один ресурс вызывает HTTP метод другого ресурса, нужно
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73 # сохранить оригинальный resourceLocation
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74 $request->context->{resourceLocation} ||= $this->location;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76 # это свойство специфично только для REST приложений.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77 # сохранение текущего ресурса не повлечет за собой существенных расходов,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
78 # т.к. они просто освободятся несколько позже.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
79 if ( not $request->context->{resource} ) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
80 $request->context->{resource} = $this;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
81 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
82
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
83 return _InvokeDelegate( $operation, $this, $request );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
84 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
85
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
86 sub security {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
87 shift->request->security
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
88 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
89
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
90 sub context {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
91 shift->request->context
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
92 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
93
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
94 sub verbs {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
95 {} # возвращаем пстой список операций
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
96 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
97
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
98 sub GetAllowedMethods {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
99 map( uc, keys %{ shift->verbs } );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
100 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
101
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
102 sub AccessCheck {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
103
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
104 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
105
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
106 sub Seek {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
107 my ($this, $role) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
108
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
109 my @roles;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
110
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
111 if (ref($role) eq 'ARRAY') {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
112 @roles = @{$role};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
113 } elsif (not ref($role)) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
114 @roles = split(/\s+/, $role);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
115 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
116 die ArgumentException->new( role => 'A invalid value is provided, expected ARRAY or SCALAR');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
117 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
118
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
119
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
120 for(my $r = $this; $r; $r = $r->parent) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
121 return $r if $r->HasRole(@roles);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
122 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
123 return;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
124 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
125
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
126 sub HasRole {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
127 my ($this, @roles) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
128 my %cache = map { $_, 1 } @{$this->role};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
129 return scalar(grep not($cache{$_}), @roles) ? 0 : 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
130 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
131
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
132 sub _InvokeDelegate {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
133 my $delegate = shift;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
134
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
135 return $delegate->(@_) if ref $delegate eq 'CODE';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
136 return $delegate->Invoke(@_) if eval { $delegate->can('Invoke') };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
137 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
138
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
139 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
140
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
141 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
142
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
143 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
144
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
145 =head1 NAME
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
146
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
147 C<IMPL::Web::Application::Resource> - Web-ресурс.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
148
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
149 =head1 SYNOPSIS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
150
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
151 Класс для внутреннего использования. Объединяет в себе контракт и модель данных.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
152 Основная задача - обработать поступающий от контроллера запрос на вызов C<HTTP>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
153 метода.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
154
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
155 Экземпляры данного класса передаются в качестве параметров делегатам
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
156 осуществляющим привязку к модели в C<IMPL::Web::Application::ResourceContract>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
157 и C<IMPL::Web::Application::OperationContract>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
158
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
159 =head1 DESCRIPTION
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
160
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
161 Весь функционал ресурса, поддерживаемые им C<HTTP> методы определяются
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
162 контрактом. Однако можно реализовывать ресурсы, которые не имеют контракта
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
163 или он отличается от того, что предоставляется стандартно
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
164 C<IMPL::Web::Application::ResourceContract>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
165
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
166 Каждый ресурс является контейнером, тоесть позволяет получить дочерний ресурс
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
167 по идентифифкатору, если таковой имеется, тоесть ресурс, у которого нет дочерних
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
168 ресурсов на самом деле рассматривается как пустой контейнер.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
169
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
170 С ресурсом непосредственно взаимодействует котроллер запросов
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
171 C<IMPL::Web::Handler::RestController>, вызывая два метода.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
172
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
173 =over
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
174
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
175 =item * C<FetchChildResource($childId)>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
176
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
177 Данный метод возвращает дочерний ресурс, соответствующий C<$childId>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
178 Текущая реализация использует метод C<FindChildResourceInfo> контракта текущего
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
179 ресурса, после чего создает дочерний ресурс.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
180
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
181 Если дочерний ресурс не найден, вызывается исключение
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
182 C<IMPL::Web::NotFoundException>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
183
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
184 =item * C<InvokeHttpVerb($verb,$action)>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
185
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
186 Обрабатывает запрос к ресурсу. Для этого используется контракт ресурса, в
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
187 нем выбирается соответсвующий C<IMPL::Web::Application::OperationContract>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
188 Затем найденный контракт для указанной операции используется для обработки
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
189 запроса.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
190
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
191 =back
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
192
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
193 Если объект реализует два вышеуказанных метода, он является веб-ресурсом, а
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
194 детали его реализации, котнракт и прочее уже не важно, поэтому можно реализовать
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
195 собственный класс ресурса, например унаследованный от
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
196 C<IMPL::Web::Application::CustomResource>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
197
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
198 =head1 MEMBERS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
199
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
200 =head2 C<[get]request>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
201
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
202 Объект C<IMPL::Web::Application::Action> представляющий запрос к серверу.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
203
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
204 =head2 C<[get]application>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
205
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
206 Ссылка на приложение, к которому относится данный ресурс. Получается
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
207 автоматически из объекта запроса.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
208
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
209 =head2 C<[get]contract>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
210
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
211 Обязательное свойство для ресурса, ссылается, на контракт, соответствующий
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
212 данному ресурсу, используется для выполнения C<HTTP> методов и получения
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
213 дочерних ресурсов.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
214
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
215 =head2 C<[get]id>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
216
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
217 Обязательное свойство ресурса, идентифицирует его в родительском контейнере,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
218 для корневого ресурса может иметь произвольное значение.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
219
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
220 =head2 C<[get]parent>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
221
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
222 Ссылка на родительский ресурс, для корневого ресурса не определена.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
223
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
224 =head2 C<[get]model>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
225
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
226 Ссылка на объект предметной области, представляемый данным ресурсом. Данное
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
227 свойство не является обязательным и может быть не задано.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
228
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
229 =head2 C<[get]location>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
230
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
231 Объект типа C<IMPL::Web::AutoLocator> или аналогичный описывающий адрес текущего
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
232 ресурса, может быть как явно передан при создании ресурса, так и вычислен
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
233 автоматически (только для ресурсов имеющих родителя). Следует заметить, что
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
234 адрес ресурса не содержит параметров запроса, а только путь.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
235
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
236 =head2 C<[get,list]role>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
237
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
238 Список ролей ресурса. Роль это условный маркер, который позволяет определить
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
239 функции выполняемые ресурсом, например контейнер, профиль пользователя и т.п.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
240
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
241 Используется при построении цепочек навигации, а также при поиске с использованием
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
242 метода C<seek>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
243
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
244 =head2 C<seek($role)>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
245
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
246 Ищет ресурс в цепочке родителей (включая сам ресурс) с подходящими ролями.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
247
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
248 Роли могут быть переданы в виде массива или строки, где роли разделены пробелами
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
249
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
250 =head2 C<[get]FetchChildResource($id)>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
251
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
252 Возвращает дочерний ресурс, по его идентификатору.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
253
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
254 Данная реализация использует контракт текущего ресурса для поиска информации о
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
255 дочернем ресурсе C<< $this->contract->FindChildResourceInfo($id) >>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
256
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
257 Затем осуществляется привязка к моделе, тоесть, выполняется делегат, для
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
258 получения модели дочернего ресурса, а затем осуществляется привязка к контракту,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
259 при этом в делегат, который должен вернуть контракт дочернего ресурса передаются
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
260 текущий ресурc и модель дочернего ресурса.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
261
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
262 =cut