annotate Lib/IMPL/Web/Application/CustomResourceContract.pm @ 331:2ff1726c066c

removed operation contract (due it's useless)
author cin
date Wed, 05 Jun 2013 18:21:11 +0400
parents fe725fad2d90
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::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 => {
331
2ff1726c066c removed operation contract (due it's useless)
cin
parents: 330
diff changeset
7 NotAllowedException => 'IMPL::Web::NotAllowedException'
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
8 },
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
9 base => [
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
10 'IMPL::Web::Application::ResourceContract' => '@_'
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
11 ]
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 our %RESOURCE_BINDINGS = (
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
15 GET => 'HttpGet',
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
16 POST => 'HttpPost',
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
17 PUT => 'HttpPut',
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
18 DELETE => 'HttpDelete',
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
19 HEAD => 'HttpHead'
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
20 );
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 sub CTOR {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
23 my ($this) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
24
331
2ff1726c066c removed operation contract (due it's useless)
cin
parents: 330
diff changeset
25 $this->verbs->{options} ||= \&_HttpOptionsBinding;
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
26
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
27 while(my ($verb,$methodName) = each %RESOURCE_BINDINGS) {
331
2ff1726c066c removed operation contract (due it's useless)
cin
parents: 330
diff changeset
28 $this->verbs->{lc($verb)} ||= sub {
2ff1726c066c removed operation contract (due it's useless)
cin
parents: 330
diff changeset
29 my ($resource,$action) = @_;
2ff1726c066c removed operation contract (due it's useless)
cin
parents: 330
diff changeset
30
2ff1726c066c removed operation contract (due it's useless)
cin
parents: 330
diff changeset
31 if (eval { $resource->can($methodName) }) {
2ff1726c066c removed operation contract (due it's useless)
cin
parents: 330
diff changeset
32 return $resource->$methodName($action);
2ff1726c066c removed operation contract (due it's useless)
cin
parents: 330
diff changeset
33 } else {
2ff1726c066c removed operation contract (due it's useless)
cin
parents: 330
diff changeset
34 die NotAllowedException->new(allow => join(',', _GetAllowedHttpMethods($resource)));
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
35 }
331
2ff1726c066c removed operation contract (due it's useless)
cin
parents: 330
diff changeset
36 }
229
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 sub _HttpOptionsBinding {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
41 my ($resource) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
42
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
43 my @allow = _GetAllowedHttpMethods($resource);
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
44 retrun HttpResponse->new(
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
45 status => '200 OK',
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
46 headers => {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
47 allow => join ( ',', @allow )
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
48 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
49 );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
50 }
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 sub _GetAllowedHttpMethods {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
53 my ($resource) = @_;
268
4abda21186cd *refactoring IMPL::Web: added 'application' property to resources
cin
parents: 230
diff changeset
54 return grep $resource->can($RESOURCE_BINDINGS{$_}), keys %RESOURCE_BINDINGS;
229
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
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
57 1;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
58
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
59 __END__
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 =pod
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 =head1 NAME
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 C<IMPL::Web::Application::CustomResourceContract> - контракт для веб-ресурсов,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
66 реальзуемых в коде см. C<IMPL::Web::Application::CustomResource}>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
67
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
68 =head1 DESCRIPTION
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
69
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
70 Данный класс не используется напрямую.
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 =cut