Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/Resource.pm @ 334:71221d79e6b4
removing web resources contracts
| author | cin |
|---|---|
| date | Thu, 13 Jun 2013 02:24:57 +0400 |
| parents | cd6409f66a5f |
| children | e8be9062ecf2 |
| 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', |
| 16 Loader => 'IMPL::Code::Loader' | |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
17 }, |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
18 base => [ |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
19 'IMPL::Object' => undef, |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
20 'IMPL::Web::Application::ResourceInterface' => undef |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
21 ], |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
22 props => [ |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
23 request => PROP_RO, |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
24 application => PROP_RO, |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
25 parent => PROP_RO, |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
26 model => PROP_RO, |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
27 id => PROP_RO, |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
28 location => PROP_RO, |
| 334 | 29 resources => PROP_RO, |
| 30 verbs => PROP_RO, | |
| 31 namedResources => PROP_RO, | |
| 32 regexResources => PROP_RO | |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
33 ] |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
34 }; |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
35 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
36 sub CTOR { |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
37 my ( $this, %args ) = @_; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
38 |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
39 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
|
40 unless $args{id}; |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
41 |
| 334 | 42 |
| 43 die ArgumentException->new(request => 'A request object must be specified') | |
| 44 unless $args{request}; | |
| 45 | |
| 46 $this->request( $args{request} ); | |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
47 $this->parent( $args{parent} ); |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
48 $this->model( $args{model} ); |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
49 $this->id( $args{id} ); |
| 333 | 50 $this->application( $args{request}->application ); |
| 334 | 51 $this->verbs( $args{verbs} || {} ); |
| 52 $this->resources($args{resources} || []); | |
| 53 | |
| 54 $this->PrepareResourcesCache(); | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
55 |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
56 # если расположение явно не указано, то оно вычисляется автоматически, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
57 # либо остается не заданным |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
58 $this->location( $args{location} |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
59 || eval { $this->parent->location->Child( $this->id ) } ); |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
60 } |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
61 |
| 334 | 62 sub PrepareResourcesCache { |
| 63 my ($this,$resources) = @_; | |
| 64 my %nameMap; | |
| 65 my @rxMap; | |
| 66 | |
| 67 foreach my $res (@{$this->resources}) { | |
| 68 #skip resources without contract | |
| 69 next unless $res->{contract}; | |
| 70 | |
| 71 if ( my $name = $res->{name} ) { | |
| 72 $nameMap{$name} = $res; | |
| 73 } | |
| 74 if ( $res->{match} ) { | |
| 75 push @rxMap,$res; | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 $this->regexResources(\@rxMap); | |
| 80 $this->namedResources(\%nameMap); | |
| 81 } | |
| 82 | |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
83 sub InvokeHttpVerb { |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
84 my ( $this, $verb ) = @_; |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
85 |
| 334 | 86 my $operation = $this->verbs->{ lc($verb) }; |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
87 |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
88 die NotAllowedException->new( |
| 334 | 89 allow => join( ',', map( uc, keys %{ $this->verbs } ) ) ) |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
90 unless $operation; |
|
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 $this->AccessCheck($verb); |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
93 my $request = $this->request; |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
94 |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
95 # в случае, когда один ресурс вызывает HTTP метод другого ресурса, нужно |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
96 # сохранить оригинальный resourceLocation |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
97 $request->context->{resourceLocation} ||= $this->location; |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
98 |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
99 # это свойство специфично только для REST приложений. |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
100 # сохранение текущего ресурса не повлечет за собой существенных расходов, |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
101 # т.к. они просто освободятся несколько позже. |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
102 if ( not $request->context->{resource} ) { |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
103 $request->context->{resource} = $this; |
| 333 | 104 $request->context->{environment} = sub { |
| 105 carp "using request environment is deprecated"; | |
| 106 $this->PrepareEnvironment() | |
| 107 }; | |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
108 } |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
109 |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
110 return _InvokeDelegate( $operation, $this, $request ); |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
111 } |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
112 |
| 330 | 113 sub AccessCheck { |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
114 |
| 330 | 115 } |
| 116 | |
|
285
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
117 sub PrepareEnvironment { |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
118 my ($this) = @_; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
119 |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
120 my @stack; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
121 my $env = {}; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
122 |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
123 for ( my $res = $this ; $res ; $res = $res->parent ) { |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
124 push @stack, $res if $res->can('SetupEnvironment'); |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
125 } |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
126 |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
127 map $_->SetupEnvironment($env), reverse @stack; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
128 |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
129 return $env; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
130 } |
|
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 sub FindChildResourceInfo { |
| 334 | 133 my ( $this, $name ) = @_; |
| 134 | |
| 135 if ( my $info = $this->namedResources->{$name} ) { | |
| 136 return $info, [$name]; | |
| 137 } | |
| 138 else { | |
| 139 foreach my $info ( @{$this->regexResources} ) { | |
| 140 my $rx = $info->{match}; | |
| 141 if(my @childId = $name =~ m/$rx/) { | |
| 142 return $info, \@childId; | |
| 143 } | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 return; | |
|
285
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
148 } |
|
546957c50a36
*IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents:
268
diff
changeset
|
149 |
|
229
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 sub FetchChildResource { |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
153 my ( $this, $childId ) = @_; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
154 |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
155 $this->AccessCheck('FETCH'); |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
156 |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
157 my ( $info, $childIdParts ) = |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
158 $this->FindChildResourceInfo($childId); |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
159 |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
160 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
|
161 |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
162 my %args; |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
163 |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
164 my $binding = $info->{binding}; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
165 my $contract = $info->{contract}; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
166 if (ref($binding) eq 'HASH' ) { |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
167 $args{$_} = _InvokeDelegate( $binding->{$_}, $this, @$childIdParts ) |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
168 foreach keys %$binding; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
169 } else { |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
170 $args{model} = _InvokeDelegate( $binding, $this, @$childIdParts ); |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
171 } |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
172 |
| 334 | 173 # support for dynamic contracts |
| 174 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
|
175 $contract = _InvokeDelegate( $contract, $this, $args{model} ); |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
176 } |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
177 |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
178 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
|
179 $childId ) |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
180 unless $contract; |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
181 |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
182 $args{parent} = $this; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
183 $args{id} = $childId; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
184 $args{request} = $this->request; |
| 334 | 185 |
| 186 my $factory; | |
| 187 | |
| 188 if (ref($contract) eq 'HASH') { | |
| 189 $factory = delete $contract->{class} || __PACKAGE__; | |
| 190 hashApply(\%args,$contract); | |
| 191 | |
| 192 Loader->default->Require($factory) | |
| 193 unless ref($factory); | |
| 194 } else { | |
| 195 die OperationException->new("Unsupported contract for the child resource '$childId'",$contract,$this->location); | |
| 196 } | |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
197 |
| 334 | 198 return $factory->new(%args); |
|
229
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 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
201 sub _InvokeDelegate { |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
202 my $delegate = shift; |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
203 |
|
332
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
204 return $delegate->(@_) if ref $delegate eq 'CODE'; |
|
04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
cin
parents:
330
diff
changeset
|
205 return $delegate->Invoke(@_) if eval { $delegate->can('Invoke') }; |
|
229
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 1; |
|
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 __END__ |
|
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 =pod |
|
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 =head1 NAME |
|
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<IMPL::Web::Application::Resource> - Web-ресурс. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
217 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
218 =head1 SYNOPSIS |
|
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<HTTP> |
|
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 |
|
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 и 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 =head1 DESCRIPTION |
|
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 Весь функционал ресурса, поддерживаемые им C<HTTP> методы определяются |
|
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 C<IMPL::Web::Application::ResourceContract>. |
|
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 Каждый ресурс является контейнером, тоесть позволяет получить дочерний ресурс |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
236 по идентифифкатору, если таковой имеется, тоесть ресурс, у которого нет дочерних |
|
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 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
239 С ресурсом непосредственно взаимодействует котроллер запросов |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
240 C<IMPL::Web::Handler::RestController>, вызывая два метода. |
|
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 =over |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
243 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
244 =item * C<FetchChildResource($childId)> |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
245 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
246 Данный метод возвращает дочерний ресурс, соответствующий C<$childId>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
247 Текущая реализация использует метод C<FindChildResourceInfo> контракта текущего |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
248 ресурса, после чего создает дочерний ресурс. |
|
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 C<IMPL::Web::NotFoundException>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
252 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
253 =item * C<InvokeHttpVerb($verb,$action)> |
|
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 нем выбирается соответсвующий C<IMPL::Web::Application::OperationContract>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
257 Затем найденный контракт для указанной операции используется для обработки |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
258 запроса. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
259 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
260 =back |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
261 |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
262 Если объект реализует два вышеуказанных метода, он является веб-ресурсом, а |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
263 детали его реализации, котнракт и прочее уже не важно, поэтому можно реализовать |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
264 собственный класс ресурса, например унаследованный от |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
265 C<IMPL::Web::Application::CustomResource>. |
|
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
266 |
| 230 | 267 =head1 MEMBERS |
| 268 | |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
269 =head2 C<[get]application> |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
270 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
271 Ссылка на приложение, к которому относится данный ресурс. Его следует задавать |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
272 только для коренвых ресурсов, дочерние ресурсы получают это свойство от |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
273 родителей. |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
274 |
| 230 | 275 =head2 C<[get]contract> |
| 276 | |
| 248 | 277 Обязательное свойство для ресурса, ссылается, на контракт, соответствующий |
| 230 | 278 данному ресурсу, используется для выполнения C<HTTP> методов и получения |
| 279 дочерних ресурсов. | |
| 280 | |
| 281 =head2 C<[get]id> | |
| 282 | |
| 283 Обязательное свойство ресурса, идентифицирует его в родительском контейнере, | |
| 284 для корневого ресурса может иметь произвольное значение. | |
| 285 | |
| 286 =head2 C<[get]parent> | |
| 287 | |
| 288 Ссылка на родительский ресурс, для корневого ресурса не определена. | |
| 289 | |
| 290 =head2 C<[get]model> | |
| 291 | |
| 292 Ссылка на объект предметной области, представляемый данным ресурсом. Данное | |
| 293 свойство не является обязательным и может быть не задано. | |
| 294 | |
| 295 =head2 C<[get]location> | |
| 296 | |
| 297 Объект типа C<IMPL::Web::AutoLocator> или аналогичный описывающий адрес текущего | |
| 298 ресурса, может быть как явно передан при создании ресурса, так и вычислен | |
| 299 автоматически (только для ресурсов имеющих родителя). Следует заметить, что | |
| 300 адрес ресурса не содержит параметров запроса, а только путь. | |
| 301 | |
|
268
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
302 =head2 C<[get]FetchChildResource($id)> |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
303 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
304 Возвращает дочерний ресурс, по его идентификатору. |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
305 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
306 Данная реализация использует контракт текущего ресурса для поиска информации о |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
307 дочернем ресурсе C<< $this->contract->FindChildResourceInfo($id) >>. |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
308 |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
309 Затем осуществляется привязка к моделе, тоесть, выполняется делегат, для |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
310 получения модели дочернего ресурса, а затем осуществляется привязка к контракту, |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
311 при этом в делегат, который должен вернуть контракт дочернего ресурса передаются |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
312 текущий ресурc и модель дочернего ресурса. |
|
4abda21186cd
*refactoring IMPL::Web: added 'application' property to resources
cin
parents:
256
diff
changeset
|
313 |
|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
314 =cut |
