Mercurial > pub > Impl
annotate Lib/IMPL/Web/Application/RestBaseResource.pm @ 202:5146e17a7b76
IMPL::Web::Application::RestResource fixes, documentation
author | sergey |
---|---|
date | Wed, 25 Apr 2012 02:49:23 +0400 |
parents | 0c018a247c8a |
children | c8fe3f84feba |
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', | |
11 TTransform => '-IMPL::Transform', | |
12 TResolve => '-IMPL::Config::Resolve' | |
13 }, | |
14 base => { | |
15 'IMPL::Object' => undef, | |
16 'IMPL::Object::Autofill' => '@_' | |
17 } | |
18 }; | |
19 | |
20 | |
21 BEGIN { | |
22 public property id => PROP_GET | PROP_OWNERSET; | |
23 public property parent => PROP_GET | PROP_OWNERSET; | |
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 | 26 } |
27 | |
28 sub target { | |
29 shift; | |
30 } | |
31 | |
32 sub CTOR { | |
33 my ($this) = @_; | |
34 | |
35 die ArgumentException->new("id","Identifier is required for non-root resources") if $this->id and not length $this->id; | |
36 die ArgumentException->new("A contract is required") unless $this->contract; | |
37 } | |
38 | |
39 sub GetHttpImpl { | |
40 my($this,$method) = @_; | |
41 | |
42 my %map = ( | |
43 GET => 'GetImpl', | |
44 PUT => 'PutImpl', | |
45 POST => 'PostImpl', | |
46 DELETE => 'DeleteImpl' | |
47 ); | |
48 | |
49 return $map{$method}; | |
50 } | |
51 | |
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 | 54 |
55 my $impl = $this->GetHttpImpl($method) || 'HttpFallbackImpl'; | |
56 | |
201
0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
sergey
parents:
200
diff
changeset
|
57 return $this->$impl($action); |
200 | 58 } |
59 | |
60 sub GetImpl { | |
61 die NotImplException->new(); | |
62 } | |
63 | |
64 sub PutImpl { | |
65 die NotImplException->new(); | |
66 } | |
67 | |
68 sub PostImpl { | |
69 die NotImplException->new(); | |
70 } | |
71 | |
72 sub DeleteImpl { | |
73 die NotImplException->new(); | |
74 } | |
75 | |
76 sub HttpFallbackImpl { | |
77 die ForbiddenException->new(); | |
78 } | |
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 | 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 |