Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/Resource.pm @ 330:fe725fad2d90
Added access checking to web resources
| author | sergey |
|---|---|
| date | Tue, 04 Jun 2013 19:25:54 +0400 |
| parents | 546957c50a36 |
| children | 04a093f0a5a6 |
| rev | line source |
|---|---|
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
1 package IMPL::Web::Application::Resource; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
2 use strict; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
3 |
|
256
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
255
diff
changeset
|
4 use URI; |
| 230 | 5 use IMPL::Const qw(:prop); |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
6 use IMPL::declare { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
7 require => { |
| 244 | 8 ViewResult => 'IMPL::Web::ViewResult', |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
9 Exception => 'IMPL::Exception', |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
10 ArgumentException => '-IMPL::InvalidArgumentException', |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
11 OperationException => '-IMPL::InvalidOperationException', |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
12 NotAllowedException => 'IMPL::Web::NotAllowedException', |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
13 NotFoundException => 'IMPL::Web::NotFoundException' |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
14 }, |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
15 base => [ |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
16 'IMPL::Object' => undef, |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
17 'IMPL::Web::Application::ResourceInterface' => undef |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
18 ], |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
19 props => [ |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
20 application => PROP_RO, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
21 parent => PROP_RO, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
22 model => PROP_RO, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
23 id => PROP_RO, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
24 contract => PROP_RO, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
25 location => PROP_RO, |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
26 ] |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
27 }; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
28 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
29 sub CTOR { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
30 my ( $this, %args ) = @_; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
31 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
32 die ArgumentException->new( id => 'A resource identifier is required' ) |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
33 unless $args{id}; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
34 die ArgumentException->new( contract => 'A contract is required' ) |
| 255 | 35 unless $args{contract}; |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
36 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
37 $this->parent( $args{parent} ); |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
38 $this->model( $args{model} ); |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
39 $this->id( $args{id} ); |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
40 $this->contract( $args{contract} ); |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
41 $this->application( $args{application} || ($args{parent} && $args{parent}->application) ); |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
42 |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
43 # если расположение явно не указано, то оно вычисляется автоматически, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
44 # либо остается не заданным |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
45 $this->location( $args{location} |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
46 || eval { $this->parent->location->Child( $this->id ) } ); |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
47 } |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
48 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
49 sub InvokeHttpVerb { |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
50 my ( $this, $verb, $action ) = @_; |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
51 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
52 my $operation = $this->contract->verbs->{ lc($verb) }; |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
53 |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
54 die NotAllowedException->new( |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
55 allow => join( ',', map( uc, keys %{ $this->contract->verbs } ) ) ) |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
56 unless $operation; |
| 330 | 57 |
| 58 $this->AccessCheck($verb); | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
59 |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
60 # в случае, когда один ресурс вызывает HTTP метод другого ресурса, нужно |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
61 # сохранить оригинальный resourceLocation |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
62 $action->context->{resourceLocation} ||= $this->location; |
|
285
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
63 |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
64 # это свойство специфично только для REST приложений. |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
65 # сохранение текущего ресурса не повлечет за собой существенных расходов, |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
66 # т.к. они просто освободятся несколько позже. |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
67 if(not $action->context->{resource}) { |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
68 $action->context->{resource} = $this; |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
69 $action->context->{environment} = sub { $this->PrepareEnvironment() }; |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
70 } |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
71 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
72 return _InvokeDelegate($operation, $this, $action ); |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
73 } |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
74 |
| 330 | 75 sub AccessCheck { |
| 76 | |
| 77 } | |
| 78 | |
|
285
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
79 sub PrepareEnvironment { |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
80 my ($this) = @_; |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
81 |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
82 my @stack; |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
83 my $env = {}; |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
84 |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
85 for(my $res = $this; $res; $res = $res->parent) { |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
86 push @stack,$res if $res->can('SetupEnvironment'); |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
87 } |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
88 |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
89 map $_->SetupEnvironment($env), reverse @stack; |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
90 |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
91 return $env; |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
92 } |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
93 |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
94 # это реализация по умолчанию, базируется информации о ресурсах, содержащийся |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
95 # в контракте. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
96 sub FetchChildResource { |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
97 my ( $this, $childId ) = @_; |
| 330 | 98 |
| 99 $this->AccessCheck('FETCH'); | |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
100 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
101 my ( $info, $childIdParts ) = |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
102 $this->contract->FindChildResourceInfo($childId); |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
103 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
104 die NotFoundException->new( $this->location->url, $childId ) unless $info; |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
105 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
106 my $binding = $info->{binding}; |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
107 my $contract = $info->{contract}; |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
108 my $model = _InvokeDelegate( $binding, $this, @$childIdParts ); |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
109 |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
110 if ( ref $contract eq 'CODE' || $contract->can('Invoke')) { |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
111 $contract = _InvokeDelegate($contract,$this,$model); |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
112 $info->{contract} = $contract; |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
113 } |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
114 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
115 die OperationException->new( "Can't fetch a contract for the resource", |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
116 $childId ) |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
117 unless $contract; |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
118 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
119 my %args = ( |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
120 parent => $this, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
121 id => $childId, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
122 model => $model |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
123 ); |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
124 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
125 return $contract->CreateResource(%args); |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
126 } |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
127 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
128 sub _InvokeDelegate { |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
129 my $delegate = shift; |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
130 |
| 230 | 131 return $delegate->(@_) if ref $delegate eq 'CODE'; |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
132 return $delegate->Invoke(@_) if eval { $delegate->can('Invoke') }; |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
133 } |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
134 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
135 1; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
136 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
137 __END__ |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
138 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
139 =pod |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
140 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
141 =head1 NAME |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
142 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
143 C<IMPL::Web::Application::Resource> - Web-ресурс. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
144 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
145 =head1 SYNOPSIS |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
146 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
147 Класс для внутреннего использования. Объединяет в себе контракт и модель данных. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
148 Основная задача - обработать поступающий от контроллера запрос на вызов C<HTTP> |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
149 метода. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
150 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
151 Экземпляры данного класса передаются в качестве параметров делегатам |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
152 осуществляющим привязку к модели в C<IMPL::Web::Application::ResourceContract> |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
153 и C<IMPL::Web::Application::OperationContract>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
154 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
155 =head1 DESCRIPTION |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
156 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
157 Весь функционал ресурса, поддерживаемые им C<HTTP> методы определяются |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
158 контрактом. Однако можно реализовывать ресурсы, которые не имеют контракта |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
159 или он отличается от того, что предоставляется стандартно |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
160 C<IMPL::Web::Application::ResourceContract>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
161 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
162 Каждый ресурс является контейнером, тоесть позволяет получить дочерний ресурс |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
163 по идентифифкатору, если таковой имеется, тоесть ресурс, у которого нет дочерних |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
164 ресурсов на самом деле рассматривается как пустой контейнер. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
165 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
166 С ресурсом непосредственно взаимодействует котроллер запросов |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
167 C<IMPL::Web::Handler::RestController>, вызывая два метода. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
168 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
169 =over |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
170 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
171 =item * C<FetchChildResource($childId)> |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
172 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
173 Данный метод возвращает дочерний ресурс, соответствующий C<$childId>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
174 Текущая реализация использует метод C<FindChildResourceInfo> контракта текущего |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
175 ресурса, после чего создает дочерний ресурс. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
176 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
177 Если дочерний ресурс не найден, вызывается исключение |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
178 C<IMPL::Web::NotFoundException>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
179 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
180 =item * C<InvokeHttpVerb($verb,$action)> |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
181 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
182 Обрабатывает запрос к ресурсу. Для этого используется контракт ресурса, в |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
183 нем выбирается соответсвующий C<IMPL::Web::Application::OperationContract>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
184 Затем найденный контракт для указанной операции используется для обработки |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
185 запроса. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
186 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
187 =back |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
188 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
189 Если объект реализует два вышеуказанных метода, он является веб-ресурсом, а |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
190 детали его реализации, котнракт и прочее уже не важно, поэтому можно реализовать |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
191 собственный класс ресурса, например унаследованный от |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
192 C<IMPL::Web::Application::CustomResource>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
193 |
| 230 | 194 =head1 MEMBERS |
| 195 | |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
196 =head2 C<[get]application> |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
197 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
198 Ссылка на приложение, к которому относится данный ресурс. Его следует задавать |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
199 только для коренвых ресурсов, дочерние ресурсы получают это свойство от |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
200 родителей. |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
201 |
| 230 | 202 =head2 C<[get]contract> |
| 203 | |
| 248 | 204 Обязательное свойство для ресурса, ссылается, на контракт, соответствующий |
| 230 | 205 данному ресурсу, используется для выполнения C<HTTP> методов и получения |
| 206 дочерних ресурсов. | |
| 207 | |
| 208 =head2 C<[get]id> | |
| 209 | |
| 210 Обязательное свойство ресурса, идентифицирует его в родительском контейнере, | |
| 211 для корневого ресурса может иметь произвольное значение. | |
| 212 | |
| 213 =head2 C<[get]parent> | |
| 214 | |
| 215 Ссылка на родительский ресурс, для корневого ресурса не определена. | |
| 216 | |
| 217 =head2 C<[get]model> | |
| 218 | |
| 219 Ссылка на объект предметной области, представляемый данным ресурсом. Данное | |
| 220 свойство не является обязательным и может быть не задано. | |
| 221 | |
| 222 =head2 C<[get]location> | |
| 223 | |
| 224 Объект типа C<IMPL::Web::AutoLocator> или аналогичный описывающий адрес текущего | |
| 225 ресурса, может быть как явно передан при создании ресурса, так и вычислен | |
| 226 автоматически (только для ресурсов имеющих родителя). Следует заметить, что | |
| 227 адрес ресурса не содержит параметров запроса, а только путь. | |
| 228 | |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
229 =head2 C<[get]FetchChildResource($id)> |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
230 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
231 Возвращает дочерний ресурс, по его идентификатору. |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
232 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
233 Данная реализация использует контракт текущего ресурса для поиска информации о |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
234 дочернем ресурсе C<< $this->contract->FindChildResourceInfo($id) >>. |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
235 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
236 Затем осуществляется привязка к моделе, тоесть, выполняется делегат, для |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
237 получения модели дочернего ресурса, а затем осуществляется привязка к контракту, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
238 при этом в делегат, который должен вернуть контракт дочернего ресурса передаются |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
239 текущий ресурc и модель дочернего ресурса. |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
240 |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
241 =cut |
