annotate Lib/IMPL/Web/Application/CustomResourceContract.pm @ 322:cca158327c47

added OutOfRangeException
author cin
date Tue, 21 May 2013 10:04:11 +0400
parents 4abda21186cd
children fe725fad2d90
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::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
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
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
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
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
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
32
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
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
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
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) = @_;
268
4abda21186cd *refactoring IMPL::Web: added 'application' property to resources
cin
parents: 230
diff changeset
58 return grep $resource->can($RESOURCE_BINDINGS{$_}), keys %RESOURCE_BINDINGS;
229
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