annotate Lib/IMPL/Web/Application/RestBaseResource.pm @ 213:d6e2ea24af08

sync
author sergey
date Fri, 03 Aug 2012 01:15:15 +0400
parents c8fe3f84feba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
200
sergey
parents:
diff changeset
1 package IMPL::Web::Application::RestBaseResource;
sergey
parents:
diff changeset
2 use strict;
sergey
parents:
diff changeset
3
sergey
parents:
diff changeset
4 use IMPL::lang qw(:declare :constants);
sergey
parents:
diff changeset
5 use IMPL::declare {
sergey
parents:
diff changeset
6 require => {
sergey
parents:
diff changeset
7 Exception => 'IMPL::Exception',
sergey
parents:
diff changeset
8 ArgumentException => '-IMPL::InvalidArgumentException',
sergey
parents:
diff changeset
9 NotImplException => '-IMPL::NotImplementedException',
sergey
parents:
diff changeset
10 ForbiddenException => 'IMPL::Web::ForbiddenException',
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 202
diff changeset
11 TTransform => '-IMPL::Transform'
200
sergey
parents:
diff changeset
12 },
sergey
parents:
diff changeset
13 base => {
sergey
parents:
diff changeset
14 'IMPL::Object' => undef,
sergey
parents:
diff changeset
15 'IMPL::Object::Autofill' => '@_'
sergey
parents:
diff changeset
16 }
sergey
parents:
diff changeset
17 };
sergey
parents:
diff changeset
18
sergey
parents:
diff changeset
19
sergey
parents:
diff changeset
20 BEGIN {
sergey
parents:
diff changeset
21 public property id => PROP_GET | PROP_OWNERSET;
sergey
parents:
diff changeset
22 public property parent => PROP_GET | PROP_OWNERSET;
sergey
parents:
diff changeset
23 public property contract => PROP_GET | PROP_OWNERSET;
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
24 protected property final => PROP_ALL;
200
sergey
parents:
diff changeset
25 }
sergey
parents:
diff changeset
26
sergey
parents:
diff changeset
27 sub target {
sergey
parents:
diff changeset
28 shift;
sergey
parents:
diff changeset
29 }
sergey
parents:
diff changeset
30
sergey
parents:
diff changeset
31 sub CTOR {
sergey
parents:
diff changeset
32 my ($this) = @_;
sergey
parents:
diff changeset
33
sergey
parents:
diff changeset
34 die ArgumentException->new("id","Identifier is required for non-root resources") if $this->id and not length $this->id;
sergey
parents:
diff changeset
35 die ArgumentException->new("A contract is required") unless $this->contract;
sergey
parents:
diff changeset
36 }
sergey
parents:
diff changeset
37
sergey
parents:
diff changeset
38 sub GetHttpImpl {
sergey
parents:
diff changeset
39 my($this,$method) = @_;
sergey
parents:
diff changeset
40
sergey
parents:
diff changeset
41 my %map = (
sergey
parents:
diff changeset
42 GET => 'GetImpl',
sergey
parents:
diff changeset
43 PUT => 'PutImpl',
sergey
parents:
diff changeset
44 POST => 'PostImpl',
sergey
parents:
diff changeset
45 DELETE => 'DeleteImpl'
sergey
parents:
diff changeset
46 );
sergey
parents:
diff changeset
47
sergey
parents:
diff changeset
48 return $map{$method};
sergey
parents:
diff changeset
49 }
sergey
parents:
diff changeset
50
sergey
parents:
diff changeset
51 sub InvokeHttpMethod {
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
52 my ($this,$method,$action) = @_;
200
sergey
parents:
diff changeset
53
sergey
parents:
diff changeset
54 my $impl = $this->GetHttpImpl($method) || 'HttpFallbackImpl';
sergey
parents:
diff changeset
55
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
56 return $this->$impl($action);
200
sergey
parents:
diff changeset
57 }
sergey
parents:
diff changeset
58
sergey
parents:
diff changeset
59 sub GetImpl {
sergey
parents:
diff changeset
60 die NotImplException->new();
sergey
parents:
diff changeset
61 }
sergey
parents:
diff changeset
62
sergey
parents:
diff changeset
63 sub PutImpl {
sergey
parents:
diff changeset
64 die NotImplException->new();
sergey
parents:
diff changeset
65 }
sergey
parents:
diff changeset
66
sergey
parents:
diff changeset
67 sub PostImpl {
sergey
parents:
diff changeset
68 die NotImplException->new();
sergey
parents:
diff changeset
69 }
sergey
parents:
diff changeset
70
sergey
parents:
diff changeset
71 sub DeleteImpl {
sergey
parents:
diff changeset
72 die NotImplException->new();
sergey
parents:
diff changeset
73 }
sergey
parents:
diff changeset
74
sergey
parents:
diff changeset
75 sub HttpFallbackImpl {
sergey
parents:
diff changeset
76 die ForbiddenException->new();
sergey
parents:
diff changeset
77 }
sergey
parents:
diff changeset
78
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
79 sub FetchChildResource {
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
80 return undef;
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
81 }
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
82
200
sergey
parents:
diff changeset
83
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
84 1;
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
85
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
86 __END__
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
87
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
88 =pod
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
89
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
90
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
91
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
92 =cut