perltidy all classes
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / RPC.pm
1 package Catalyst::Controller::DBIC::API::RPC;
2
3 #ABSTRACT: Provides an RPC interface to DBIx::Class
4
5 use Moose;
6 BEGIN { extends 'Catalyst::Controller::DBIC::API'; }
7
8 __PACKAGE__->config(
9     'action'    => { object_with_id => { PathPart => 'id' } },
10     'default'   => 'application/json',
11     'stash_key' => 'response',
12     'map'       => {
13         'application/x-www-form-urlencoded' => 'JSON',
14         'application/json'                  => 'JSON',
15     },
16 );
17
18 =head1 DESCRIPTION
19
20 Provides an RPC API interface to the functionality described in L<Catalyst::Controller::DBIC::API>.
21
22 By default provides the following endpoints:
23
24   $base/create
25   $base/list
26   $base/id/[identifier]
27   $base/id/[identifier]/delete
28   $base/id/[identifier]/update
29
30 Where $base is the URI described by L</setup>, the chain root of the controller.
31
32 =method_protected setup
33
34 Chained: override
35 PathPart: override
36 CaptureArgs: 0
37
38 As described in L<Catalyst::Controller::DBIC::API/setup>, this action is the chain root of the controller but has no pathpart or chain parent defined by default, so these must be defined in order for the controller to function. The neatest way is normally to define these using the controller's config.
39
40   __PACKAGE__->config
41     ( action => { setup => { PathPart => 'track', Chained => '/api/rpc/rpc_base' } },
42         ...
43   );
44
45 =cut
46
47 =method_protected create
48
49 Chained: L</objects_no_id>
50 PathPart: create
51 CaptureArgs: 0
52
53 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
54
55 =cut
56
57 sub create : Chained('objects_no_id') : PathPart('create') : Args(0) {
58     my ( $self, $c ) = @_;
59     $self->update_or_create($c);
60 }
61
62 =method_protected list
63
64 Chained: L</deserialize>
65 PathPart: list
66 CaptureArgs: 0
67
68 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/list>.
69
70 =cut
71
72 sub list : Chained('deserialize') : PathPart('list') : Args(0) {
73     my ( $self, $c ) = @_;
74     $self->next::method($c);
75 }
76
77 =method_protected item
78
79 Chained: L</object_with_id>
80 PathPart: ''
81 Args: 0
82
83 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/item>.
84
85 =cut
86
87 sub item : Chained('object_with_id') : PathPart('') : Args(0) {
88     my ( $self, $c ) = @_;
89     $self->next::method($c);
90 }
91
92 =method_protected update
93
94 Chained: L</object_with_id>
95 PathPart: update
96 Args: 0
97
98 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
99
100 =cut
101
102 sub update : Chained('object_with_id') : PathPart('update') : Args(0) {
103     my ( $self, $c ) = @_;
104     $self->update_or_create($c);
105 }
106
107 =method_protected delete
108
109 Chained: L</object_with_id>
110 PathPart: delete
111 Args: 0
112
113 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete>.
114
115 =cut
116
117 sub delete : Chained('object_with_id') : PathPart('delete') : Args(0) {
118     my ( $self, $c ) = @_;
119     $self->next::method($c);
120 }
121
122 =method_protected update_bulk
123
124 Chained: L</objects_no_id>
125 PathPart: update
126 Args: 0
127
128 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create> for multiple objects.
129
130 =cut
131
132 sub update_bulk : Chained('objects_no_id') : PathPart('update') : Args(0) {
133     my ( $self, $c ) = @_;
134     $self->update_or_create($c);
135 }
136
137 =method_protected delete_bulk
138
139 Chained: L</objects_no_id>
140 PathPart: delete
141 Args: 0
142
143 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete> for multiple objects.
144
145 =cut
146
147 sub delete_bulk : Chained('objects_no_id') : PathPart('delete') : Args(0) {
148     my ( $self, $c ) = @_;
149     $self->delete($c);
150 }
151
152 1;