Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/CustomResourceContract.pm @ 250:129e48bb5afb
DOM refactoring
ObjectToDOM methods are virtual
QueryToDOM uses inflators
Fixed transform for the complex values in the ObjectToDOM
QueryToDOM doesn't allow to use complex values (HASHes) as values for nodes (overpost problem)
author | sergey |
---|---|
date | Wed, 07 Nov 2012 04:17:53 +0400 |
parents | 6d8092d8ce1b |
children | 4abda21186cd |
rev | line source |
---|---|
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
1 package IMPL::Web::Application::CustomResourceContract; |
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 | 4 use IMPL::Const qw(:prop); |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
5 use IMPL::declare { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
6 require => { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
7 NotAllowedException => 'IMPL::Web::NotAllowedException', |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
8 OperationContract => 'IMPL::Web::Application::OperationContract' |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
9 }, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
10 base => [ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
11 'IMPL::Web::Application::ResourceContract' => '@_' |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
12 ] |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
13 }; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
14 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
15 our %RESOURCE_BINDINGS = ( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
16 GET => 'HttpGet', |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
17 POST => 'HttpPost', |
230 | 18 PUT => 'HttpPut', |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
19 DELETE => 'HttpDelete', |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
20 HEAD => 'HttpHead' |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
21 ); |
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 sub CTOR { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
24 my ($this) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
25 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
26 $this->verbs->{options} = OperationContract->new( binding => \&_HttpOptionsBinding ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
27 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
28 while(my ($verb,$methodName) = each %RESOURCE_BINDINGS) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
29 $this->verbs->{lc($verb)} = OperationContract->new ( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
30 binding => sub { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
31 my ($resource,$action) = @_; |
230 | 32 |
33 if (eval { $resource->can($methodName) }) { | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
34 return $resource->$methodName($action); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
35 } else { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
36 die NotAllowedException->new(allow => join(',', _GetAllowedHttpMethods($resource))); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
37 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
38 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
39 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
40 ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
41 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
42 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
43 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
44 sub _HttpOptionsBinding { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
45 my ($resource) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
46 |
230 | 47 my @allow = _GetAllowedHttpMethods($resource); |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
48 retrun HttpResponse->new( |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
49 status => '200 OK', |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
50 headers => { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
51 allow => join ( ',', @allow ) |
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 ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
54 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
55 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
56 sub _GetAllowedHttpMethods { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
57 my ($resource) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
58 return grep $resource->can($RESOURCE_BINDINGS{$_}), values %RESOURCE_BINDINGS; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
59 } |
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 1; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
62 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
63 __END__ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
64 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
65 =pod |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
66 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
67 =head1 NAME |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
68 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
69 C<IMPL::Web::Application::CustomResourceContract> - контракт для веб-ресурсов, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
70 реальзуемых в коде см. C<IMPL::Web::Application::CustomResource}>. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
71 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
72 =head1 DESCRIPTION |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
73 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
74 Данный класс не используется напрямую. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
75 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
diff
changeset
|
76 =cut |