annotate Lib/IMPL/Web/Application/RestBaseResource.pm @ 203:68a59c3358ff

Implemented templates selection mechanism
author sergey
date Wed, 25 Apr 2012 18:06:11 +0400
parents 5146e17a7b76
children c8fe3f84feba
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',
sergey
parents:
diff changeset
11 TTransform => '-IMPL::Transform',
sergey
parents:
diff changeset
12 TResolve => '-IMPL::Config::Resolve'
sergey
parents:
diff changeset
13 },
sergey
parents:
diff changeset
14 base => {
sergey
parents:
diff changeset
15 'IMPL::Object' => undef,
sergey
parents:
diff changeset
16 'IMPL::Object::Autofill' => '@_'
sergey
parents:
diff changeset
17 }
sergey
parents:
diff changeset
18 };
sergey
parents:
diff changeset
19
sergey
parents:
diff changeset
20
sergey
parents:
diff changeset
21 BEGIN {
sergey
parents:
diff changeset
22 public property id => PROP_GET | PROP_OWNERSET;
sergey
parents:
diff changeset
23 public property parent => PROP_GET | PROP_OWNERSET;
sergey
parents:
diff changeset
24 public property contract => PROP_GET | PROP_OWNERSET;
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
25 protected property final => PROP_ALL;
200
sergey
parents:
diff changeset
26 }
sergey
parents:
diff changeset
27
sergey
parents:
diff changeset
28 sub target {
sergey
parents:
diff changeset
29 shift;
sergey
parents:
diff changeset
30 }
sergey
parents:
diff changeset
31
sergey
parents:
diff changeset
32 sub CTOR {
sergey
parents:
diff changeset
33 my ($this) = @_;
sergey
parents:
diff changeset
34
sergey
parents:
diff changeset
35 die ArgumentException->new("id","Identifier is required for non-root resources") if $this->id and not length $this->id;
sergey
parents:
diff changeset
36 die ArgumentException->new("A contract is required") unless $this->contract;
sergey
parents:
diff changeset
37 }
sergey
parents:
diff changeset
38
sergey
parents:
diff changeset
39 sub GetHttpImpl {
sergey
parents:
diff changeset
40 my($this,$method) = @_;
sergey
parents:
diff changeset
41
sergey
parents:
diff changeset
42 my %map = (
sergey
parents:
diff changeset
43 GET => 'GetImpl',
sergey
parents:
diff changeset
44 PUT => 'PutImpl',
sergey
parents:
diff changeset
45 POST => 'PostImpl',
sergey
parents:
diff changeset
46 DELETE => 'DeleteImpl'
sergey
parents:
diff changeset
47 );
sergey
parents:
diff changeset
48
sergey
parents:
diff changeset
49 return $map{$method};
sergey
parents:
diff changeset
50 }
sergey
parents:
diff changeset
51
sergey
parents:
diff changeset
52 sub InvokeHttpMethod {
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
53 my ($this,$method,$action) = @_;
200
sergey
parents:
diff changeset
54
sergey
parents:
diff changeset
55 my $impl = $this->GetHttpImpl($method) || 'HttpFallbackImpl';
sergey
parents:
diff changeset
56
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
57 return $this->$impl($action);
200
sergey
parents:
diff changeset
58 }
sergey
parents:
diff changeset
59
sergey
parents:
diff changeset
60 sub GetImpl {
sergey
parents:
diff changeset
61 die NotImplException->new();
sergey
parents:
diff changeset
62 }
sergey
parents:
diff changeset
63
sergey
parents:
diff changeset
64 sub PutImpl {
sergey
parents:
diff changeset
65 die NotImplException->new();
sergey
parents:
diff changeset
66 }
sergey
parents:
diff changeset
67
sergey
parents:
diff changeset
68 sub PostImpl {
sergey
parents:
diff changeset
69 die NotImplException->new();
sergey
parents:
diff changeset
70 }
sergey
parents:
diff changeset
71
sergey
parents:
diff changeset
72 sub DeleteImpl {
sergey
parents:
diff changeset
73 die NotImplException->new();
sergey
parents:
diff changeset
74 }
sergey
parents:
diff changeset
75
sergey
parents:
diff changeset
76 sub HttpFallbackImpl {
sergey
parents:
diff changeset
77 die ForbiddenException->new();
sergey
parents:
diff changeset
78 }
sergey
parents:
diff changeset
79
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
80 sub FetchChildResource {
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
81 return undef;
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
82 }
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
83
200
sergey
parents:
diff changeset
84
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
85 1;
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
86
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
87 __END__
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
88
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
89 =pod
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
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
93 =cut