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