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

Implemented templates selection mechanism
author sergey
date Wed, 25 Apr 2012 18:06:11 +0400
parents 5146e17a7b76
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
200
sergey
parents:
diff changeset
1 package IMPL::Web::Application::RestCustomResource;
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',
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
9 ForbiddenException => 'IMPL::Web::ForbiddenException',
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
10 NotFoundException => 'IMPL::Web::NotFoundException'
200
sergey
parents:
diff changeset
11 },
sergey
parents:
diff changeset
12 base => {
sergey
parents:
diff changeset
13 'IMPL::Web::Application::RestBaseResource' => '@_'
sergey
parents:
diff changeset
14 }
sergey
parents:
diff changeset
15 };
sergey
parents:
diff changeset
16
sergey
parents:
diff changeset
17 BEGIN {
sergey
parents:
diff changeset
18 public property get => PROP_GET | PROP_OWNERSET;
sergey
parents:
diff changeset
19 public property put => PROP_GET | PROP_OWNERSET;
sergey
parents:
diff changeset
20 public property post => PROP_GET | PROP_OWNERSET;
sergey
parents:
diff changeset
21 public property delete => PROP_GET | PROP_OWNERSET;
sergey
parents:
diff changeset
22 }
sergey
parents:
diff changeset
23
sergey
parents:
diff changeset
24 sub FetchChildResource {
sergey
parents:
diff changeset
25 my ($this,$id,$action) = @_;
sergey
parents:
diff changeset
26
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
27 die NotFoundException->new() if $this->final;
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
28
200
sergey
parents:
diff changeset
29 return $this->contract->Transform( $this->GetImpl($action), { parent => $this, id => $id } )->FetchChildResource($id,$action);
sergey
parents:
diff changeset
30 }
sergey
parents:
diff changeset
31
sergey
parents:
diff changeset
32 sub GetImpl {
sergey
parents:
diff changeset
33 my ($this,$action) = @_;
sergey
parents:
diff changeset
34
sergey
parents:
diff changeset
35 my $method = $this->get or die ForbiddenException->new();
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
36 return $this->InvokeMember($method,$action);
200
sergey
parents:
diff changeset
37 }
sergey
parents:
diff changeset
38
sergey
parents:
diff changeset
39 sub PutImpl {
sergey
parents:
diff changeset
40 my ($this,$action) = @_;
sergey
parents:
diff changeset
41 my $method = $this->put or die ForbiddenException->new();
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
42 return $this->InvokeMember($method,$action);
200
sergey
parents:
diff changeset
43 }
sergey
parents:
diff changeset
44
sergey
parents:
diff changeset
45 sub PostImpl {
sergey
parents:
diff changeset
46 my ($this,$action) = @_;
sergey
parents:
diff changeset
47 my $method = $this->post or die ForbiddenException->new();
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
48 return $this->InvokeMember($method,$action);
200
sergey
parents:
diff changeset
49 }
sergey
parents:
diff changeset
50
sergey
parents:
diff changeset
51 sub DeleteImpl {
sergey
parents:
diff changeset
52 my ($this,$action) = @_;
sergey
parents:
diff changeset
53 my $method = $this->delete or die ForbiddenException->new();
201
0c018a247c8a Reworked REST resource classes to be more transparent and intuitive
sergey
parents: 200
diff changeset
54 return $this->InvokeMember($method,$action);
200
sergey
parents:
diff changeset
55 }
sergey
parents:
diff changeset
56
202
5146e17a7b76 IMPL::Web::Application::RestResource fixes, documentation
sergey
parents: 201
diff changeset
57 sub InvokeMember {
5146e17a7b76 IMPL::Web::Application::RestResource fixes, documentation
sergey
parents: 201
diff changeset
58 my ($this,$method,$action) = @_;
5146e17a7b76 IMPL::Web::Application::RestResource fixes, documentation
sergey
parents: 201
diff changeset
59
5146e17a7b76 IMPL::Web::Application::RestResource fixes, documentation
sergey
parents: 201
diff changeset
60 return $this->$method($action);
5146e17a7b76 IMPL::Web::Application::RestResource fixes, documentation
sergey
parents: 201
diff changeset
61 }
5146e17a7b76 IMPL::Web::Application::RestResource fixes, documentation
sergey
parents: 201
diff changeset
62
200
sergey
parents:
diff changeset
63 1;