Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/RestBaseResource.pm @ 215:77a9934a44af
sync, migrating to XML::Compile
author | cin |
---|---|
date | Sun, 19 Aug 2012 22:27:43 +0400 |
parents | c8fe3f84feba |
children |
rev | line source |
---|---|
200 | 1 package IMPL::Web::Application::RestBaseResource; |
2 use strict; | |
3 | |
4 use IMPL::lang qw(:declare :constants); | |
5 use IMPL::declare { | |
6 require => { | |
7 Exception => 'IMPL::Exception', | |
8 ArgumentException => '-IMPL::InvalidArgumentException', | |
9 NotImplException => '-IMPL::NotImplementedException', | |
10 ForbiddenException => 'IMPL::Web::ForbiddenException', | |
206 | 11 TTransform => '-IMPL::Transform' |
200 | 12 }, |
13 base => { | |
14 'IMPL::Object' => undef, | |
15 'IMPL::Object::Autofill' => '@_' | |
16 } | |
17 }; | |
18 | |
19 | |
20 BEGIN { | |
21 public property id => PROP_GET | PROP_OWNERSET; | |
22 public property parent => PROP_GET | PROP_OWNERSET; | |
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 | 25 } |
26 | |
27 sub target { | |
28 shift; | |
29 } | |
30 | |
31 sub CTOR { | |
32 my ($this) = @_; | |
33 | |
34 die ArgumentException->new("id","Identifier is required for non-root resources") if $this->id and not length $this->id; | |
35 die ArgumentException->new("A contract is required") unless $this->contract; | |
36 } | |
37 | |
38 sub GetHttpImpl { | |
39 my($this,$method) = @_; | |
40 | |
41 my %map = ( | |
42 GET => 'GetImpl', | |
43 PUT => 'PutImpl', | |
44 POST => 'PostImpl', | |
45 DELETE => 'DeleteImpl' | |
46 ); | |
47 | |
48 return $map{$method}; | |
49 } | |
50 | |
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 | 53 |
54 my $impl = $this->GetHttpImpl($method) || 'HttpFallbackImpl'; | |
55 | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
56 return $this->$impl($action); |
200 | 57 } |
58 | |
59 sub GetImpl { | |
60 die NotImplException->new(); | |
61 } | |
62 | |
63 sub PutImpl { | |
64 die NotImplException->new(); | |
65 } | |
66 | |
67 sub PostImpl { | |
68 die NotImplException->new(); | |
69 } | |
70 | |
71 sub DeleteImpl { | |
72 die NotImplException->new(); | |
73 } | |
74 | |
75 sub HttpFallbackImpl { | |
76 die ForbiddenException->new(); | |
77 } | |
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 | 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 |