Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/Resource.pm @ 367:608e74bc309f
form metadata, mostly done
author | cin |
---|---|
date | Tue, 03 Dec 2013 17:55:36 +0400 |
parents | 833e663796c4 |
children |
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 => [ |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
24 request => PROP_RO, |
332
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, |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
30 role => PROP_RO | PROP_LIST |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
31 ] |
229
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
34 sub CTOR { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
35 my ( $this, %args ) = @_; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
36 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
37 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
|
38 unless $args{id}; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
39 |
334 | 40 |
41 die ArgumentException->new(request => 'A request object must be specified') | |
42 unless $args{request}; | |
43 | |
44 $this->request( $args{request} ); | |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
45 $this->parent( $args{parent} ); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
46 $this->model( $args{model} ); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
47 $this->id( $args{id} ); |
333 | 48 $this->application( $args{request}->application ); |
334 | 49 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
50 # если расположение явно не указано, то оно вычисляется автоматически, |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
51 # либо остается не заданным |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
52 $this->location( $args{location} |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
53 || eval { $this->parent->location->Child( $this->id ) } ); |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
54 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
55 if (my $role = $args{role}) { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
56 if (ref($role) eq 'ARRAY') { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
57 $this->role($role); |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
58 } elsif (not ref($role)) { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
59 $this->role(split(/\s+/, $role)); |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
60 } else { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
61 die ArgumentException->new( role => 'A invalid value is provided, expected ARRAY or SCALAR'); |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
62 } |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
63 } |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
64 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
65 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
66 sub InvokeHttpVerb { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
67 my ( $this, $verb ) = @_; |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
68 |
334 | 69 my $operation = $this->verbs->{ lc($verb) }; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
70 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
71 die NotAllowedException->new( |
335 | 72 allow => join( ',', $this->GetAllowedMethods ) ) |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
73 unless $operation; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
74 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
75 $this->AccessCheck($verb); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
76 my $request = $this->request; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
77 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
78 # в случае, когда один ресурс вызывает HTTP метод другого ресурса, нужно |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
79 # сохранить оригинальный resourceLocation |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
80 $request->context->{resourceLocation} ||= $this->location; |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
81 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
82 # это свойство специфично только для REST приложений. |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
83 # сохранение текущего ресурса не повлечет за собой существенных расходов, |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
84 # т.к. они просто освободятся несколько позже. |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
85 if ( not $request->context->{resource} ) { |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
86 $request->context->{resource} = $this; |
333 | 87 $request->context->{environment} = sub { |
88 carp "using request environment is deprecated"; | |
89 $this->PrepareEnvironment() | |
90 }; | |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
91 } |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
92 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
93 return _InvokeDelegate( $operation, $this, $request ); |
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 |
357 | 96 sub security { |
97 shift->request->security | |
98 } | |
99 | |
100 sub verbs { | |
101 {} # возвращаем пстой список операций | |
102 } | |
103 | |
335 | 104 sub GetAllowedMethods { |
357 | 105 # возвращаем пустой список доступных операций |
335 | 106 } |
107 | |
108 sub FindChildResourceInfo { | |
109 | |
110 } | |
111 | |
330 | 112 sub AccessCheck { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
113 |
330 | 114 } |
115 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
116 # это реализация по умолчанию, базируется информации о ресурсах, содержащийся |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
117 # в контракте. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
118 sub FetchChildResource { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
119 my ( $this, $childId ) = @_; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
120 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
121 $this->AccessCheck('FETCH'); |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
122 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
123 my ( $info, $childIdParts ) = |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
124 $this->FindChildResourceInfo($childId); |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
125 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
126 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
|
127 |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
128 my %args; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
129 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
130 my $binding = $info->{binding}; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
131 my $contract = $info->{contract}; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
132 if (ref($binding) eq 'HASH' ) { |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
133 $args{$_} = _InvokeDelegate( $binding->{$_}, $this, @$childIdParts ) |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
134 foreach keys %$binding; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
135 } else { |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
136 $args{model} = _InvokeDelegate( $binding, $this, @$childIdParts ); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
137 } |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
138 |
334 | 139 # support for dynamic contracts |
140 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
|
141 $contract = _InvokeDelegate( $contract, $this, $args{model} ); |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
142 } |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
143 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
144 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
|
145 $childId ) |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
146 unless $contract; |
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 $args{parent} = $this; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
149 $args{id} = $childId; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
150 $args{request} = $this->request; |
334 | 151 |
152 my $factory; | |
153 | |
154 if (ref($contract) eq 'HASH') { | |
335 | 155 $factory = delete $contract->{class} || CustomResource; |
334 | 156 hashApply(\%args,$contract); |
157 | |
158 Loader->default->Require($factory) | |
159 unless ref($factory); | |
160 } else { | |
161 die OperationException->new("Unsupported contract for the child resource '$childId'",$contract,$this->location); | |
162 } | |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
163 |
334 | 164 return $factory->new(%args); |
229
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 sub _InvokeDelegate { |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
168 my $delegate = shift; |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
169 |
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
170 return $delegate->(@_) if ref $delegate eq 'CODE'; |
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
171 return $delegate->Invoke(@_) if eval { $delegate->can('Invoke') }; |
229
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 |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
174 sub Seek { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
175 my ($this, $role) = @_; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
176 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
177 my @roles; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
178 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
179 if (ref($role) eq 'ARRAY') { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
180 @roles = @{$role}; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
181 } elsif (not ref($role)) { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
182 @roles = split(/\s+/, $role); |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
183 } else { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
184 die ArgumentException->new( role => 'A invalid value is provided, expected ARRAY or SCALAR'); |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
185 } |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
186 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
187 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
188 for(my $r = $this; $r; $r = $r->parent) { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
189 return $r if $r->HasRole(@roles); |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
190 } |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
191 return; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
192 } |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
193 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
194 sub HasRole { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
195 my ($this, @roles) = @_; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
196 my %cache = map { $_, 1 } @{$this->role}; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
197 return scalar(grep not($cache{$_}), @roles) ? 0 : 1; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
198 } |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
199 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
200 1; |
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 __END__ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
203 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
204 =pod |
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 =head1 NAME |
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 C<IMPL::Web::Application::Resource> - Web-ресурс. |
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 =head1 SYNOPSIS |
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 Класс для внутреннего использования. Объединяет в себе контракт и модель данных. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
213 Основная задача - обработать поступающий от контроллера запрос на вызов C<HTTP> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
214 метода. |
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 Экземпляры данного класса передаются в качестве параметров делегатам |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
217 осуществляющим привязку к модели в C<IMPL::Web::Application::ResourceContract> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
218 и C<IMPL::Web::Application::OperationContract>. |
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 =head1 DESCRIPTION |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
221 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
222 Весь функционал ресурса, поддерживаемые им C<HTTP> методы определяются |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
223 контрактом. Однако можно реализовывать ресурсы, которые не имеют контракта |
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 C<IMPL::Web::Application::ResourceContract>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
226 |
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 |
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 C<IMPL::Web::Handler::RestController>, вызывая два метода. |
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 =over |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
235 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
236 =item * C<FetchChildResource($childId)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
237 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
238 Данный метод возвращает дочерний ресурс, соответствующий C<$childId>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
239 Текущая реализация использует метод C<FindChildResourceInfo> контракта текущего |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
240 ресурса, после чего создает дочерний ресурс. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
241 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
242 Если дочерний ресурс не найден, вызывается исключение |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
243 C<IMPL::Web::NotFoundException>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
244 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
245 =item * C<InvokeHttpVerb($verb,$action)> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
246 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
247 Обрабатывает запрос к ресурсу. Для этого используется контракт ресурса, в |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
248 нем выбирается соответсвующий C<IMPL::Web::Application::OperationContract>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
249 Затем найденный контракт для указанной операции используется для обработки |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
250 запроса. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
251 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
252 =back |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
253 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
254 Если объект реализует два вышеуказанных метода, он является веб-ресурсом, а |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
255 детали его реализации, котнракт и прочее уже не важно, поэтому можно реализовать |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
256 собственный класс ресурса, например унаследованный от |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
257 C<IMPL::Web::Application::CustomResource>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
258 |
230 | 259 =head1 MEMBERS |
260 | |
357 | 261 =head2 C<[get]request> |
262 | |
263 Объект C<IMPL::Web::Application::Action> представляющий запрос к серверу. | |
264 | |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
265 =head2 C<[get]application> |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
266 |
357 | 267 Ссылка на приложение, к которому относится данный ресурс. Получается |
268 автоматически из объекта запроса. | |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
269 |
230 | 270 =head2 C<[get]contract> |
271 | |
248 | 272 Обязательное свойство для ресурса, ссылается, на контракт, соответствующий |
230 | 273 данному ресурсу, используется для выполнения C<HTTP> методов и получения |
274 дочерних ресурсов. | |
275 | |
276 =head2 C<[get]id> | |
277 | |
278 Обязательное свойство ресурса, идентифицирует его в родительском контейнере, | |
279 для корневого ресурса может иметь произвольное значение. | |
280 | |
281 =head2 C<[get]parent> | |
282 | |
283 Ссылка на родительский ресурс, для корневого ресурса не определена. | |
284 | |
285 =head2 C<[get]model> | |
286 | |
287 Ссылка на объект предметной области, представляемый данным ресурсом. Данное | |
288 свойство не является обязательным и может быть не задано. | |
289 | |
290 =head2 C<[get]location> | |
291 | |
292 Объект типа C<IMPL::Web::AutoLocator> или аналогичный описывающий адрес текущего | |
293 ресурса, может быть как явно передан при создании ресурса, так и вычислен | |
294 автоматически (только для ресурсов имеющих родителя). Следует заметить, что | |
295 адрес ресурса не содержит параметров запроса, а только путь. | |
296 | |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
297 =head2 C<[get,list]role> |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
298 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
299 Список ролей ресурса. Роль это условный маркер, который позволяет определить |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
300 функции выполняемые ресурсом, например контейнер, профиль пользователя и т.п. |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
301 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
302 Используется при построении цепочек навигации, а также при поиске с использованием |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
303 метода C<seek>. |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
304 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
305 =head2 C<seek($role)> |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
306 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
307 Ищет ресурс в цепочке родителей (включая сам ресурс) с подходящими ролями. |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
308 |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
309 Роли могут быть переданы в виде массива или строки, где роли разделены пробелами |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
357
diff
changeset
|
310 |
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
311 =head2 C<[get]FetchChildResource($id)> |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
312 |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
313 Возвращает дочерний ресурс, по его идентификатору. |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
314 |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
315 Данная реализация использует контракт текущего ресурса для поиска информации о |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
316 дочернем ресурсе C<< $this->contract->FindChildResourceInfo($id) >>. |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
317 |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
318 Затем осуществляется привязка к моделе, тоесть, выполняется делегат, для |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
319 получения модели дочернего ресурса, а затем осуществляется привязка к контракту, |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
320 при этом в делегат, который должен вернуть контракт дочернего ресурса передаются |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
321 текущий ресурc и модель дочернего ресурса. |
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
322 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
323 =cut |