Mercurial > pub > Impl
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 201:0c018a247c8a | 202:5146e17a7b76 | 
|---|---|
| 79 | 79 | 
| 80 sub FetchChildResource { | 80 sub FetchChildResource { | 
| 81 return undef; | 81 return undef; | 
| 82 } | 82 } | 
| 83 | 83 | 
| 84 sub InvokeMember { | |
| 85 my ($this,$method,$action) = @_; | |
| 86 | |
| 87 die ArgumentException->new("method","No method information provided") unless $method; | |
| 88 | |
| 89 #normalize method info | |
| 90 if (not ref $method) { | |
| 91 $method = { | |
| 92 method => $method | |
| 93 }; | |
| 94 } | |
| 95 | |
| 96 if (ref $method eq 'HASH') { | |
| 97 my $member = $method->{method} or die InvalidOpException->new("A member name isn't specified"); | |
| 98 | |
| 99 my @args; | |
| 100 | |
| 101 if (my $params = $method->{parameters}) { | |
| 102 if (ref $params eq 'HASH') { | |
| 103 @args = map { | |
| 104 $_, | |
| 105 $this->MakeParameter($params->{$_},$action) | |
| 106 } keys %$params; | |
| 107 } elsif (ref $params eq 'ARRAY') { | |
| 108 @args = map $this->MakeParameter($_,$action), @$params; | |
| 109 } else { | |
| 110 @args = ($this->MakeParameter($params,$action)); | |
| 111 } | |
| 112 } | |
| 113 return $this->target->$member(@args); | |
| 114 } elsif (ref $method eq TResolve) { | |
| 115 return $method->Invoke($this->target); | |
| 116 } elsif (ref $method eq 'CODE') { | |
| 117 return $method->($this,$action); | |
| 118 } else { | |
| 119 die InvalidOpException->new("Unsupported type of the method information", ref $method); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 sub MakeParameter { | |
| 124 my ($this,$param,$action) = @_; | |
| 125 | |
| 126 if ($param) { | |
| 127 if (is $param, TTransform ) { | |
| 128 return $param->Transform($this,$action->query); | |
| 129 } elsif ($param and not ref $param) { | |
| 130 return $action->query->param($param); | |
| 131 } else { | |
| 132 die new InvalidOpException->new("Unsupported parameter mapping", $param); | |
| 133 } | |
| 134 } else { | |
| 135 return undef; | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 | 84 | 
| 140 1; | 85 1; | 
| 141 | 86 | 
| 142 __END__ | 87 __END__ | 
| 143 | 88 | 
