Make tests pass for new definitive chaining
[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(
533075c7 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
19Provides an RPC API interface to the functionality described in L<Catalyst::Controller::DBIC::API>.
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
40 ( action => { setup => { PathPart => 'track', Chained => '/api/rpc/rpc_base' } },
41 ...
42 );
43
d2739840 44=cut
45
46sub index : Chained('setup') PathPart('') Args(0) {
47 my ( $self, $c ) = @_;
48
49 $self->push_error($c, { message => 'Not implemented' });
50 $c->res->status( '404' );
51}
52
53=method_protected create
54
533075c7 55Chained: L</objects_no_id>
d2739840 56PathPart: create
57CaptureArgs: 0
58
59Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
60
61=cut
62
533075c7 63sub create :Chained('objects_no_id') :PathPart('create')
d2739840 64{
65 my ($self, $c) = @_;
d2739840 66 $c->forward('update_or_create');
67}
68
69=method_protected list
70
609916e5 71Chained: L</deserialize>
d2739840 72PathPart: list
73CaptureArgs: 0
74
75Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/list>.
76
77=cut
78
533075c7 79sub list :Chained('deserialize') :PathPart('list')
80{
d2739840 81 my ($self, $c) = @_;
533075c7 82 $self->next::method($c);
d2739840 83}
84
609916e5 85=method_protected item
86
87Chained: L</object_with_id>
88PathPart: ''
89Args: 0
90
91Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/item>.
92
93=cut
94
533075c7 95sub item :Chained('object_with_id') :PathPart('')
96{
609916e5 97 my ($self, $c) = @_;
533075c7 98 $self->next::method($c);
609916e5 99}
100
d2739840 101=method_protected update
102
609916e5 103Chained: L</object_with_id>
d2739840 104PathPart: update
609916e5 105Args: 0
d2739840 106
107Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
108
109=cut
110
533075c7 111sub update :Chained('object_with_id') :PathPart('update')
112{
609916e5 113 my ($self, $c) = @_;
d2739840 114 $c->forward('update_or_create');
115}
116
117=method_protected delete
118
609916e5 119Chained: L</object_with_id>
d2739840 120PathPart: delete
609916e5 121Args: 0
d2739840 122
123Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete>.
124
125=cut
126
533075c7 127sub delete :Chained('object_with_id') :PathPart('delete')
609916e5 128{
129 my ($self, $c) = @_;
130 $self->next::method($c);
131}
d2739840 132
609916e5 133=method_protected update_bulk
134
533075c7 135Chained: L</objects_no_id>
609916e5 136PathPart: update
137Args: 0
138
139Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create> for multiple objects.
140
141=cut
142
533075c7 143sub update_bulk :Chained('objects_no_id') :PathPart('update')
609916e5 144{
145 my ($self, $c) = @_;
146 $c->forward('update_or_create');
147}
148
149=method_protected delete_bulk
150
533075c7 151Chained: L</objects_no_id>
609916e5 152PathPart: delete
153Args: 0
154
155Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete> for multiple objects.
156
157=cut
158
533075c7 159sub delete_bulk :Chained('objects_no_id') :PathPart('delete')
609916e5 160{
161 my ($self, $c) = @_;
162 $self->next::method($c);
d2739840 163}
164
1651;