Mercurial > pub > Impl
comparison Lib/IMPL/Web/Application/RestBaseResource.pm @ 201:0c018a247c8a
Reworked REST resource classes to be more transparent and intuitive
author | sergey |
---|---|
date | Tue, 24 Apr 2012 19:52:07 +0400 |
parents | a9dbe534d236 |
children | 5146e17a7b76 |
comparison
equal
deleted
inserted
replaced
200:a9dbe534d236 | 201:0c018a247c8a |
---|---|
20 | 20 |
21 BEGIN { | 21 BEGIN { |
22 public property id => PROP_GET | PROP_OWNERSET; | 22 public property id => PROP_GET | PROP_OWNERSET; |
23 public property parent => PROP_GET | PROP_OWNERSET; | 23 public property parent => PROP_GET | PROP_OWNERSET; |
24 public property contract => PROP_GET | PROP_OWNERSET; | 24 public property contract => PROP_GET | PROP_OWNERSET; |
25 protected property final => PROP_ALL; | |
25 } | 26 } |
26 | 27 |
27 sub target { | 28 sub target { |
28 shift; | 29 shift; |
29 } | 30 } |
47 | 48 |
48 return $map{$method}; | 49 return $map{$method}; |
49 } | 50 } |
50 | 51 |
51 sub InvokeHttpMethod { | 52 sub InvokeHttpMethod { |
52 my ($this,$method,$childId,$action) = @_; | 53 my ($this,$method,$action) = @_; |
53 | 54 |
54 my $impl = $this->GetHttpImpl($method) || 'HttpFallbackImpl'; | 55 my $impl = $this->GetHttpImpl($method) || 'HttpFallbackImpl'; |
55 | 56 |
56 return $this->$impl($childId,$action); | 57 return $this->$impl($action); |
57 } | 58 } |
58 | 59 |
59 sub GetImpl { | 60 sub GetImpl { |
60 die NotImplException->new(); | 61 die NotImplException->new(); |
61 } | 62 } |
74 | 75 |
75 sub HttpFallbackImpl { | 76 sub HttpFallbackImpl { |
76 die ForbiddenException->new(); | 77 die ForbiddenException->new(); |
77 } | 78 } |
78 | 79 |
80 sub FetchChildResource { | |
81 return undef; | |
82 } | |
83 | |
79 sub InvokeMember { | 84 sub InvokeMember { |
80 my ($this,$method,$action) = @_; | 85 my ($this,$method,$action) = @_; |
81 | 86 |
82 die ArgumentException->new("method","No method information provided") unless $method; | 87 die ArgumentException->new("method","No method information provided") unless $method; |
83 | 88 |
88 }; | 93 }; |
89 } | 94 } |
90 | 95 |
91 if (ref $method eq 'HASH') { | 96 if (ref $method eq 'HASH') { |
92 my $member = $method->{method} or die InvalidOpException->new("A member name isn't specified"); | 97 my $member = $method->{method} or die InvalidOpException->new("A member name isn't specified"); |
98 | |
93 my @args; | 99 my @args; |
94 | 100 |
95 if (my $params = $method->{parameters}) { | 101 if (my $params = $method->{parameters}) { |
96 if (ref $params eq 'HASH') { | 102 if (ref $params eq 'HASH') { |
97 @args = map { | 103 @args = map { |
106 } | 112 } |
107 return $this->target->$member(@args); | 113 return $this->target->$member(@args); |
108 } elsif (ref $method eq TResolve) { | 114 } elsif (ref $method eq TResolve) { |
109 return $method->Invoke($this->target); | 115 return $method->Invoke($this->target); |
110 } elsif (ref $method eq 'CODE') { | 116 } elsif (ref $method eq 'CODE') { |
111 return $method->($this->target,$action); | 117 return $method->($this,$action); |
112 } else { | 118 } else { |
113 die InvalidOpException->new("Unsupported type of the method information", ref $method); | 119 die InvalidOpException->new("Unsupported type of the method information", ref $method); |
114 } | 120 } |
115 } | 121 } |
116 | 122 |
119 | 125 |
120 if ($param) { | 126 if ($param) { |
121 if (is $param, TTransform ) { | 127 if (is $param, TTransform ) { |
122 return $param->Transform($this,$action->query); | 128 return $param->Transform($this,$action->query); |
123 } elsif ($param and not ref $param) { | 129 } elsif ($param and not ref $param) { |
124 my %std = ( | 130 return $action->query->param($param); |
125 id => $this->id, | 131 } else { |
126 action => $action, | 132 die new InvalidOpException->new("Unsupported parameter mapping", $param); |
127 query => $action->query | |
128 ); | |
129 | |
130 return $std{$param} || $action->query->param($param); | |
131 } | 133 } |
132 } else { | 134 } else { |
133 return undef; | 135 return undef; |
134 } | 136 } |
135 } | 137 } |
136 | 138 |
137 | 139 |
138 1; | 140 1; |
141 | |
142 __END__ | |
143 | |
144 =pod | |
145 | |
146 | |
147 | |
148 =cut |