annotate Lib/IMPL/Web/Application/CustomResource.pm @ 373:3ca44e23fd1f

implemented new web resource
author cin
date Wed, 25 Dec 2013 17:29:38 +0400
parents e12c14177848
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
1 package IMPL::Web::Application::CustomResource;
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
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
4 use IMPL::Const qw(:prop);
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
5 use IMPL::lang qw(:hash :base);
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
6 use IMPL::declare {
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
7 require => {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
8 Exception => 'IMPL::Exception',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
9 OperationException => '-IMPL::InvalidOperationException',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
10 NotFoundException => 'IMPL::Web::NotFoundException',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
11 HttpResponse => 'IMPL::Web::HttpResponse',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
12 Loader => 'IMPL::Code::Loader'
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
13 },
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
14 base => [ 'IMPL::Web::Application::ResourceBase' => '@_' ],
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
15 props => [
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
16 accessCheck => PROP_RW,
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
17 resources => PROP_RO,
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
18 verbs => PROP_RO,
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
19 namedResources => PROP_RO,
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
20 regexResources => PROP_RO
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
21 ]
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
22 };
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
23
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
24 use constant { CustomResource => __PACKAGE__ };
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
25
334
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
26 our %RESOURCE_BINDINGS = (
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
27 GET => 'HttpGet',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
28 POST => 'HttpPost',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
29 PUT => 'HttpPut',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
30 DELETE => 'HttpDelete',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
31 HEAD => 'HttpHead',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
32 OPTIONS => 'HttpOptions',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
33 TRACE => 'HttpTrace'
334
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
34 );
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
35
330
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
36 sub CTOR {
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
37 my ( $this, %args ) = @_;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
38
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
39 $this->verbs( $args{verbs} || {} );
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
40 $this->resources( $args{resources} || [] );
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
41
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
42 $this->accessCheck( $args{accessCheck} )
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
43 if $args{accessCheck};
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
44
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
45 while ( my ( $verb, $methodName ) = each %RESOURCE_BINDINGS ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
46 if ( my $method = $this->can($methodName) ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
47 $this->verbs->{ lc($verb) } ||= $method;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
48 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
49 }
330
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
50 }
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
51
334
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
52 sub FindChildResourceInfo {
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
53 my ( $this, $name ) = @_;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
54
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
55 $this->PrepareResourcesCache()
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
56 unless $this->namedResources;
335
e8be9062ecf2 improved resource classes, contracts are deprecated
cin
parents: 334
diff changeset
57
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
58 if ( my $info = $this->namedResources->{$name} ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
59 return $info, [$name];
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
60 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
61 else {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
62 foreach my $info ( @{ $this->regexResources } ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
63 my $rx = $info->{match};
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
64 if ( my @childId = $name =~ m/$rx/ ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
65 return $info, \@childId;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
66 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
67 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
68 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
69
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
70 return;
335
e8be9062ecf2 improved resource classes, contracts are deprecated
cin
parents: 334
diff changeset
71 }
e8be9062ecf2 improved resource classes, contracts are deprecated
cin
parents: 334
diff changeset
72
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
73 # это реализация по умолчанию, базируется информации о ресурсах, содержащийся
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
74 # в контракте.
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
75 sub FetchChildResource {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
76 my ( $this, $childId ) = @_;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
77
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
78 $this->AccessCheck('FETCH');
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
79
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
80 my ( $info, $childIdParts ) = $this->FindChildResourceInfo($childId);
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
81
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
82 die NotFoundException->new( $this->location->url, $childId ) unless $info;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
83
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
84 my %args;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
85
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
86 my $binding = $info->{binding};
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
87 my $contract = $info->{contract};
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
88 if ( ref($binding) eq 'HASH' ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
89 $args{$_} = _InvokeDelegate( $binding->{$_}, $this, @$childIdParts )
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
90 foreach keys %$binding;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
91 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
92 else {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
93 $args{model} = _InvokeDelegate( $binding, $this, @$childIdParts );
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
94 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
95
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
96 # support for dynamic contracts
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
97 if ( ref $contract eq 'CODE' || eval { $contract->can('Invoke') } ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
98 $contract = _InvokeDelegate( $contract, $this, $args{model} );
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
99 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
100
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
101 die OperationException->new( "Can't fetch a contract for the resource",
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
102 $childId )
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
103 unless $contract;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
104
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
105 $args{parent} = $this;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
106 $args{id} = $childId;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
107 $args{request} = $this->request;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
108
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
109 my $factory;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
110
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
111 if ( ref($contract) eq 'HASH' ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
112 $factory = delete $contract->{class} || CustomResource;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
113 hashApply( \%args, $contract );
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
114
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
115 Loader->default->Require($factory)
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
116 unless ref($factory);
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
117 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
118 else {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
119 die OperationException->new(
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
120 "Unsupported contract for the child resource '$childId'",
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
121 $contract, $this->location );
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
122 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
123
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
124 return $factory->new(%args);
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
125 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
126
334
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
127 sub PrepareResourcesCache {
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
128 my ($this) = @_;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
129
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
130 my @resources = ( $this->GetChildResources(), @{ $this->resources } );
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
131
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
132 my %nameMap;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
133 my @rxMap;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
134
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
135 foreach my $res (@resources) {
248
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
136
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
137 #skip resources without contract
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
138 next unless $res->{contract};
334
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
139
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
140 if ( my $name = $res->{name} ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
141 $nameMap{$name} = $res;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
142 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
143 if ( $res->{match} ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
144 push @rxMap, $res;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
145 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
146 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
147
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
148 $this->regexResources( \@rxMap );
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
149 $this->namedResources( \%nameMap );
295
cin
parents: 248
diff changeset
150 }
cin
parents: 248
diff changeset
151
330
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
152 sub AccessCheck {
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
153 my ( $this, $verb ) = @_;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
154
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
155 my $handler = $this->accessCheck;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
156
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
157 if ( ref($handler) eq 'CODE' ) {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
158 return &$handler( $this, $verb );
330
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
159 }
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
160 }
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
161
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
162 sub GetChildResources {
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
163
229
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
335
e8be9062ecf2 improved resource classes, contracts are deprecated
cin
parents: 334
diff changeset
166 sub HttpOptions {
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
167 my ($this) = @_;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
168
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
169 my @allow = $this->GetAllowedMethods();
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
170 return HttpResponse->new(
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
171 status => '200 OK',
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
172 headers => {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
173 allow => join( ',', @allow )
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
174 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
175 );
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
176 }
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
177
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
178 sub _InvokeDelegate {
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
179 my $delegate = shift;
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
180
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
181 return $delegate->(@_) if ref $delegate eq 'CODE';
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
182 return $delegate->Invoke(@_) if eval { $delegate->can('Invoke') };
334
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
183 }
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
184
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
185 1;
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 __END__
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 =pod
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 =head1 NAME
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
192
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
193 C<IMPL::Web::Application::CustomResource> - базовый класс для ресурсов,
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 =head1 SYNOPSIS
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 =begin code
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 package MyApp::Web::Resources::ProfileResource;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
201 use IMPL::declare {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
202 base => [
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
203 'IMPL::Web::Application::CustomResource' => '@_'
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
204 ]
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
205 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
206
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
207 sub HttpGet {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
208 my ($this) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
209 return $this->model;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
210 }
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 sub HttpPut {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
213 my ($this,$action) = @_;
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 my $form = MyApp::Web::Schema::UpdateUser->new();
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 $this->model->update( $form->Bind($action) );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
218 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
219
334
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
220 sub GetChildResources {
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
221 return {
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
222 name => 'create',
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
223 contract => {
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
224 class => 'My::Web::FormResource',
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
225 formName => 'create',
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
226 schema => 'profile.schema'
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
227 }
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
228 },
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
229 {
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
230 match => qr/^(.*)$/,
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
231 contract => {
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
232 class => 'My::Web::ItemResource'
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
233 }
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
234 }
71221d79e6b4 removing web resources contracts
cin
parents: 332
diff changeset
235 }
332
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
236
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
237 =end code
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 =head1 MEMBERS
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 =head2 C<[static]contractFactory>
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 Фабрика, используемая для получения контракта ресурса. По умолчанию
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
244 C<IMPL::Web::Application::CustomResourceContract>.
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 =head2 C<[static]contractInstance>
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 Экземпляр контракта для ресурса. Создается при первом обращении при помощи
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
249 метода C<InitContract()>.
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 =head2 C<[static]InitContract()>
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 Создает новый экземпляр контракта, используя фабрику из свойства C<contractFactory>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
254
248
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
255 =head2 C<[static]CreateContract(%args)>
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
256
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
257 Создает новый контракт, который при создании ресурсов будет передавать им в
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
258 конструкторе параметры C<%args>. Реализуется при помощи C<IMPL::Object::Factory>
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
259 которой задается параметр ссылка на C<%args>, т.о. при создании ресурса, ему в
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
260 конструкторе будет передан список из ключей и значений хеша C<%args>, а затем
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
261 остальные аргументы.
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
262
295
cin
parents: 248
diff changeset
263 =head2 C<[static]CreateResource(%args)>
cin
parents: 248
diff changeset
264
cin
parents: 248
diff changeset
265 Создает контракт по-умолчанию и вызывает у него метод C<CreateResource(%args)>.
cin
parents: 248
diff changeset
266
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
267 =head2 C<[static]GetChildResources()>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
268
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
269 Статический метод, который должны переопределять новые классы ресурсов, у
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
270 которых есть дочерние ресурсы.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
271
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
272 =begin code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
273
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
274 package MyApp::Web::MyResource
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
275
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
276 sub GetChildResources {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
277 my $self = shift;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
278 return
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
279 $self->SUPER::GetChildResources(),
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
280 {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
281 name => 'info',
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
282 contract => $contractInfo
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
283 };
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
284 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
285
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
286 =end code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
287
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
288 Метод возвращает список из хешей, которые будут переданы в качестве параметра
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
289 C<resources> контракту данного ресурса.
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
290
372
e12c14177848 refactoring web resources model, implementing new simplified model
cin
parents: 335
diff changeset
291 =cut