Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/Resource.pm @ 357:ec58c47edb52
web security: code cleanup, refactoring
author | cin |
---|---|
date | Fri, 18 Oct 2013 15:10:10 +0400 |
parents | e8be9062ecf2 |
children | 833e663796c4 |
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; |
334 | 5 use Carp qw(carp); |
6 use IMPL::lang qw(:hash :base); | |
230 | 7 use IMPL::Const qw(:prop); |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
8 use IMPL::declare { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
9 require => { |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
10 ViewResult => 'IMPL::Web::ViewResult', |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
11 Exception => 'IMPL::Exception', |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
12 ArgumentException => '-IMPL::InvalidArgumentException', |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
13 OperationException => '-IMPL::InvalidOperationException', |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
14 NotAllowedException => 'IMPL::Web::NotAllowedException', |
334 | 15 NotFoundException => 'IMPL::Web::NotFoundException', |
335 | 16 Loader => 'IMPL::Code::Loader', |
17 CustomResource => '-IMPL::Web::Application::CustomResource' | |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
18 }, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
19 base => [ |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
20 'IMPL::Object' => undef, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
21 'IMPL::Web::Application::ResourceInterface' => undef |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
22 ], |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
23 props => [ |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
24 request => PROP_RO, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
25 application => PROP_RO, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
26 parent => PROP_RO, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
27 model => PROP_RO, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
28 id => PROP_RO, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
29 location => PROP_RO, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
30 ] |
229
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
33 sub CTOR { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
34 my ( $this, %args ) = @_; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
35 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
36 die ArgumentException->new( id => 'A resource identifier is required' ) |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
37 unless $args{id}; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
38 |
334 | 39 |
40 die ArgumentException->new(request => 'A request object must be specified') | |
41 unless $args{request}; | |
42 | |
43 $this->request( $args{request} ); | |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
44 $this->parent( $args{parent} ); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
45 $this->model( $args{model} ); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
46 $this->id( $args{id} ); |
333 | 47 $this->application( $args{request}->application ); |
334 | 48 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
49 # если расположение явно не указано, то оно вычисляется автоматически, |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
50 # либо остается не заданным |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
51 $this->location( $args{location} |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
52 || eval { $this->parent->location->Child( $this->id ) } ); |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
53 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
54 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
55 sub InvokeHttpVerb { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
56 my ( $this, $verb ) = @_; |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
57 |
334 | 58 my $operation = $this->verbs->{ lc($verb) }; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
59 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
60 die NotAllowedException->new( |
335 | 61 allow => join( ',', $this->GetAllowedMethods ) ) |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
62 unless $operation; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
63 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
64 $this->AccessCheck($verb); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
65 my $request = $this->request; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
66 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
67 # в случае, когда один ресурс вызывает HTTP метод другого ресурса, нужно |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
68 # сохранить оригинальный resourceLocation |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
69 $request->context->{resourceLocation} ||= $this->location; |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
70 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
71 # это свойство специфично только для REST приложений. |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
72 # сохранение текущего ресурса не повлечет за собой существенных расходов, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
73 # т.к. они просто освободятся несколько позже. |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
74 if ( not $request->context->{resource} ) { |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
75 $request->context->{resource} = $this; |
333 | 76 $request->context->{environment} = sub { |
77 carp "using request environment is deprecated"; | |
78 $this->PrepareEnvironment() | |
79 }; | |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
80 } |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
81 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
82 return _InvokeDelegate( $operation, $this, $request ); |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
83 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
84 |
357 | 85 sub security { |
86 shift->request->security | |
87 } | |
88 | |
89 sub verbs { | |
90 {} # возвращаем пстой список операций | |
91 } | |
92 | |
335 | 93 sub GetAllowedMethods { |
357 | 94 # возвращаем пустой список доступных операций |
335 | 95 } |
96 | |
97 sub FindChildResourceInfo { | |
98 | |
99 } | |
100 | |
330 | 101 sub AccessCheck { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
102 |
330 | 103 } |
104 | |
285
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
105 sub PrepareEnvironment { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
106 my ($this) = @_; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
107 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
108 my @stack; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
109 my $env = {}; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
110 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
111 for ( my $res = $this ; $res ; $res = $res->parent ) { |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
112 push @stack, $res if $res->can('SetupEnvironment'); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
113 } |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
114 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
115 map $_->SetupEnvironment($env), reverse @stack; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
116 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
117 return $env; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
118 } |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
119 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
120 # это реализация по умолчанию, базируется информации о ресурсах, содержащийся |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
121 # в контракте. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
122 sub FetchChildResource { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
123 my ( $this, $childId ) = @_; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
124 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
125 $this->AccessCheck('FETCH'); |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
126 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
127 my ( $info, $childIdParts ) = |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
128 $this->FindChildResourceInfo($childId); |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
129 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
130 die NotFoundException->new( $this->location->url, $childId ) unless $info; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
131 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
132 my %args; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
133 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
134 my $binding = $info->{binding}; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
135 my $contract = $info->{contract}; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
136 if (ref($binding) eq 'HASH' ) { |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
137 $args{$_} = _InvokeDelegate( $binding->{$_}, $this, @$childIdParts ) |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
138 foreach keys %$binding; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
139 } else { |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
140 $args{model} = _InvokeDelegate( $binding, $this, @$childIdParts ); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
141 } |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
142 |
334 | 143 # support for dynamic contracts |
144 if ( ref $contract eq 'CODE' || eval { $contract->can('Invoke') } ) { | |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
145 $contract = _InvokeDelegate( $contract, $this, $args{model} ); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
146 } |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
147 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
148 die OperationException->new( "Can't fetch a contract for the resource", |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
149 $childId ) |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
150 unless $contract; |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
151 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
152 $args{parent} = $this; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
153 $args{id} = $childId; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
154 $args{request} = $this->request; |
334 | 155 |
156 my $factory; | |
157 | |
158 if (ref($contract) eq 'HASH') { | |
335 | 159 $factory = delete $contract->{class} || CustomResource; |
334 | 160 hashApply(\%args,$contract); |
161 | |
162 Loader->default->Require($factory) | |
163 unless ref($factory); | |
164 } else { | |
165 die OperationException->new("Unsupported contract for the child resource '$childId'",$contract,$this->location); | |
166 } | |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
167 |
334 | 168 return $factory->new(%args); |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
169 } |
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 sub _InvokeDelegate { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
172 my $delegate = shift; |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
173 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
174 return $delegate->(@_) if ref $delegate eq 'CODE'; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
175 return $delegate->Invoke(@_) if eval { $delegate->can('Invoke') }; |
229
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 1; |
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 __END__ |
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 =pod |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
183 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
184 =head1 NAME |
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 C<IMPL::Web::Application::Resource> - Web-ресурс. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
187 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
188 =head1 SYNOPSIS |
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 Основная задача - обработать поступающий от контроллера запрос на вызов C<HTTP> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
192 метода. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
193 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
194 Экземпляры данного класса передаются в качестве параметров делегатам |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
195 осуществляющим привязку к модели в C<IMPL::Web::Application::ResourceContract> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
196 и C<IMPL::Web::Application::OperationContract>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
197 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
198 =head1 DESCRIPTION |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
199 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
200 Весь функционал ресурса, поддерживаемые им C<HTTP> методы определяются |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
201 контрактом. Однако можно реализовывать ресурсы, которые не имеют контракта |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
202 или он отличается от того, что предоставляется стандартно |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
203 C<IMPL::Web::Application::ResourceContract>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
204 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
205 Каждый ресурс является контейнером, тоесть позволяет получить дочерний ресурс |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
206 по идентифифкатору, если таковой имеется, тоесть ресурс, у которого нет дочерних |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
207 ресурсов на самом деле рассматривается как пустой контейнер. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
208 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
209 С ресурсом непосредственно взаимодействует котроллер запросов |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
210 C<IMPL::Web::Handler::RestController>, вызывая два метода. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
211 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
212 =over |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
213 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
214 =item * C<FetchChildResource($childId)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
215 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
216 Данный метод возвращает дочерний ресурс, соответствующий C<$childId>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
217 Текущая реализация использует метод C<FindChildResourceInfo> контракта текущего |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
218 ресурса, после чего создает дочерний ресурс. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
219 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
220 Если дочерний ресурс не найден, вызывается исключение |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
221 C<IMPL::Web::NotFoundException>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
222 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
223 =item * C<InvokeHttpVerb($verb,$action)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
224 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
225 Обрабатывает запрос к ресурсу. Для этого используется контракт ресурса, в |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
226 нем выбирается соответсвующий C<IMPL::Web::Application::OperationContract>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
227 Затем найденный контракт для указанной операции используется для обработки |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
228 запроса. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
229 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
230 =back |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
231 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
232 Если объект реализует два вышеуказанных метода, он является веб-ресурсом, а |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
233 детали его реализации, котнракт и прочее уже не важно, поэтому можно реализовать |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
234 собственный класс ресурса, например унаследованный от |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
235 C<IMPL::Web::Application::CustomResource>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
236 |
230 | 237 =head1 MEMBERS |
238 | |
357 | 239 =head2 C<[get]request> |
240 | |
241 Объект C<IMPL::Web::Application::Action> представляющий запрос к серверу. | |
242 | |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
243 =head2 C<[get]application> |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
244 |
357 | 245 Ссылка на приложение, к которому относится данный ресурс. Получается |
246 автоматически из объекта запроса. | |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
247 |
230 | 248 =head2 C<[get]contract> |
249 | |
248 | 250 Обязательное свойство для ресурса, ссылается, на контракт, соответствующий |
230 | 251 данному ресурсу, используется для выполнения C<HTTP> методов и получения |
252 дочерних ресурсов. | |
253 | |
254 =head2 C<[get]id> | |
255 | |
256 Обязательное свойство ресурса, идентифицирует его в родительском контейнере, | |
257 для корневого ресурса может иметь произвольное значение. | |
258 | |
259 =head2 C<[get]parent> | |
260 | |
261 Ссылка на родительский ресурс, для корневого ресурса не определена. | |
262 | |
263 =head2 C<[get]model> | |
264 | |
265 Ссылка на объект предметной области, представляемый данным ресурсом. Данное | |
266 свойство не является обязательным и может быть не задано. | |
267 | |
268 =head2 C<[get]location> | |
269 | |
270 Объект типа C<IMPL::Web::AutoLocator> или аналогичный описывающий адрес текущего | |
271 ресурса, может быть как явно передан при создании ресурса, так и вычислен | |
272 автоматически (только для ресурсов имеющих родителя). Следует заметить, что | |
273 адрес ресурса не содержит параметров запроса, а только путь. | |
274 | |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
275 =head2 C<[get]FetchChildResource($id)> |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
276 |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
277 Возвращает дочерний ресурс, по его идентификатору. |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
278 |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
279 Данная реализация использует контракт текущего ресурса для поиска информации о |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
280 дочернем ресурсе C<< $this->contract->FindChildResourceInfo($id) >>. |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
281 |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
282 Затем осуществляется привязка к моделе, тоесть, выполняется делегат, для |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
283 получения модели дочернего ресурса, а затем осуществляется привязка к контракту, |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
284 при этом в делегат, который должен вернуть контракт дочернего ресурса передаются |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
285 текущий ресурc и модель дочернего ресурса. |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
286 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
287 =cut |