Fixed pod coverage and added a test for it
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / RPC.pm
CommitLineData
d2739840 1package Catalyst::Controller::DBIC::API::RPC;
2#ABSTRACT: Provides an RPC interface to DBIx::Class
3
4use Moose;
5BEGIN { extends 'Catalyst::Controller::DBIC::API'; }
6
7__PACKAGE__->config(
406086f3 8 'action' => { object_with_id => { PathPart => 'id' } },
d2739840 9 'default' => 'application/json',
10 'stash_key' => 'response',
11 'map' => {
12 'application/x-www-form-urlencoded' => 'JSON',
13 'application/json' => 'JSON',
14 },
15);
16
17=head1 DESCRIPTION
18
406086f3 19Provides an RPC API interface to the functionality described in L<Catalyst::Controller::DBIC::API>.
d2739840 20
21By default provides the following endpoints:
22
23 $base/create
24 $base/list
609916e5 25 $base/id/[identifier]
d2739840 26 $base/id/[identifier]/delete
27 $base/id/[identifier]/update
28
29Where $base is the URI described by L</setup>, the chain root of the controller.
30
31=method_protected setup
32
33Chained: override
34PathPart: override
35CaptureArgs: 0
36
37As 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.
38
39 __PACKAGE__->config
406086f3 40 ( action => { setup => { PathPart => 'track', Chained => '/api/rpc/rpc_base' } },
d2739840 41 ...
42 );
43
d2739840 44=cut
45
b66d4310 46=method_protected index
47
48Chained: L</setup>
49PathPart: ''
50Args: 0
51
52Returns http status code 404 by default.
53
54=cut
55
d2739840 56sub index : Chained('setup') PathPart('') Args(0) {
57 my ( $self, $c ) = @_;
58
59 $self->push_error($c, { message => 'Not implemented' });
60 $c->res->status( '404' );
61}
62
63=method_protected create
64
533075c7 65Chained: L</objects_no_id>
d2739840 66PathPart: create
67CaptureArgs: 0
68
69Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
70
71=cut
72
406086f3 73sub create :Chained('objects_no_id') :PathPart('create') :Args(0)
d2739840 74{
75 my ($self, $c) = @_;
3d85db11 76 $self->update_or_create($c);
d2739840 77}
78
79=method_protected list
80
609916e5 81Chained: L</deserialize>
d2739840 82PathPart: list
83CaptureArgs: 0
84
85Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/list>.
86
87=cut
88
406086f3 89sub list :Chained('deserialize') :PathPart('list') :Args(0)
533075c7 90{
d2739840 91 my ($self, $c) = @_;
533075c7 92 $self->next::method($c);
d2739840 93}
94
609916e5 95=method_protected item
96
97Chained: L</object_with_id>
98PathPart: ''
99Args: 0
100
101Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/item>.
102
103=cut
104
406086f3 105sub item :Chained('object_with_id') :PathPart('') :Args(0)
533075c7 106{
609916e5 107 my ($self, $c) = @_;
533075c7 108 $self->next::method($c);
609916e5 109}
110
d2739840 111=method_protected update
112
609916e5 113Chained: L</object_with_id>
d2739840 114PathPart: update
609916e5 115Args: 0
d2739840 116
117Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
118
119=cut
120
406086f3 121sub update :Chained('object_with_id') :PathPart('update') :Args(0)
533075c7 122{
609916e5 123 my ($self, $c) = @_;
3d85db11 124 $self->update_or_create($c);
d2739840 125}
126
127=method_protected delete
128
609916e5 129Chained: L</object_with_id>
d2739840 130PathPart: delete
609916e5 131Args: 0
d2739840 132
133Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete>.
134
135=cut
136
406086f3 137sub delete :Chained('object_with_id') :PathPart('delete') :Args(0)
609916e5 138{
139 my ($self, $c) = @_;
140 $self->next::method($c);
141}
d2739840 142
609916e5 143=method_protected update_bulk
144
533075c7 145Chained: L</objects_no_id>
609916e5 146PathPart: update
147Args: 0
148
149Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create> for multiple objects.
150
151=cut
152
406086f3 153sub update_bulk :Chained('objects_no_id') :PathPart('update') :Args(0)
609916e5 154{
155 my ($self, $c) = @_;
3d85db11 156 $self->update_or_create($c);
609916e5 157}
158
159=method_protected delete_bulk
160
533075c7 161Chained: L</objects_no_id>
609916e5 162PathPart: delete
163Args: 0
164
165Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete> for multiple objects.
166
167=cut
168
406086f3 169sub delete_bulk :Chained('objects_no_id') :PathPart('delete') :Args(0)
609916e5 170{
171 my ($self, $c) = @_;
172 $self->next::method($c);
d2739840 173}
174
1751;