use JSON instead of JSON::Any to get rid of the CPAN Testers failures when only JSON...
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / StaticArguments.pm
1 package Catalyst::Controller::DBIC::API::StaticArguments;
2
3 #ABSTRACT: Provides controller level configuration arguments
4 use Moose::Role;
5 use MooseX::Types::Moose(':all');
6 use namespace::autoclean;
7
8 requires 'check_column_relation';
9
10 =attribute_public create_requires create_allows update_requires update_allows
11
12 These attributes control requirements and limits to columns when creating or updating objects.
13
14 Each provides a number of handles:
15
16     "get_${var}_column" => 'get'
17     "set_${var}_column" => 'set'
18     "delete_${var}_column" => 'delete'
19     "insert_${var}_column" => 'insert'
20     "count_${var}_column" => 'count'
21     "all_${var}_columns" => 'elements'
22
23 =cut
24
25 foreach my $var (qw/create_requires create_allows update_requires update_allows/)
26 {
27     has $var =>
28     (
29         is => 'ro',
30         isa => ArrayRef[Str|HashRef],
31         traits => ['Array'],
32         default => sub { [] },
33         trigger => sub
34         {
35             my ($self, $new) = @_;
36             $self->check_column_relation($_, 1) for @$new;
37         },
38         handles =>
39         {
40             "get_${var}_column" => 'get',
41             "set_${var}_column" => 'set',
42             "delete_${var}_column" => 'delete',
43             "insert_${var}_column" => 'insert',
44             "count_${var}_column" => 'count',
45             "all_${var}_columns" => 'elements',
46         }
47     );
48
49     before "set_${var}_column" => sub { $_[0]->check_column_relation($_[2], 1) }; #"
50     before "insert_${var}_column" => sub { $_[0]->check_column_relation($_[2], 1) }; #"
51 }
52
53 =attribute_public count_arg is: ro, isa: Str, default: 'list_count'
54
55 count_arg controls how to reference 'count' in the the request_data
56
57 =cut
58
59 has 'count_arg' => ( is => 'ro', isa => Str, default => 'list_count' );
60
61 =attribute_public page_arg is: ro, isa: Str, default: 'list_page'
62
63 page_arg controls how to reference 'page' in the the request_data
64
65 =cut
66
67 has 'page_arg' => ( is => 'ro', isa => Str, default => 'list_page' );
68
69 =attribute_public offset_arg is: ro, isa: Str, default: 'offset'
70
71 offset_arg controls how to reference 'offset' in the the request_data
72
73 =cut
74
75 has 'offset_arg' => ( is => 'ro', isa => Str, default => 'list_offset' );
76
77 =attribute_public select_arg is: ro, isa: Str, default: 'list_returns'
78
79 select_arg controls how to reference 'select' in the the request_data
80
81 =cut
82
83 has 'select_arg' => ( is => 'ro', isa => Str, default => 'list_returns' );
84
85 =attribute_public as_arg is: ro, isa: Str, default: 'as'
86
87 as_arg controls how to reference 'as' in the the request_data
88
89 =cut
90
91 has 'as_arg' => ( is => 'ro', isa => Str, default => 'as' );
92
93 =attribute_public search_arg is: ro, isa: Str, default: 'search'
94
95 search_arg controls how to reference 'search' in the the request_data
96
97 =cut
98
99 has 'search_arg' => ( is => 'ro', isa => Str, default => 'search' );
100
101 =attribute_public grouped_by_arg is: ro, isa: Str, default: 'list_grouped_by'
102
103 grouped_by_arg controls how to reference 'grouped_by' in the the request_data
104
105 =cut
106
107 has 'grouped_by_arg' => ( is => 'ro', isa => Str, default => 'list_grouped_by' );
108
109 =attribute_public ordered_by_arg is: ro, isa: Str, default: 'list_ordered_by'
110
111 ordered_by_arg controls how to reference 'ordered_by' in the the request_data
112
113 =cut
114
115 has 'ordered_by_arg' => ( is => 'ro', isa => Str, default => 'list_ordered_by' );
116
117 =attribute_public prefetch_arg is: ro, isa: Str, default: 'list_prefetch'
118
119 prefetch_arg controls how to reference 'prefetch' in the the request_data
120
121 =cut
122
123 has 'prefetch_arg' => ( is => 'ro', isa => Str, default => 'list_prefetch' );
124
125 =attribute_public stash_key is: ro, isa: Str, default: 'response'
126
127 stash_key controls where in stash request_data should be stored
128
129 =cut
130
131 has 'stash_key' => ( is => 'ro', isa => Str, default => 'response');
132
133 =attribute_public data_root is: ro, isa: Str, default: 'list'
134
135 data_root controls how to reference where the data is in the the request_data
136
137 =cut
138
139 has 'data_root' => ( is => 'ro', isa => Str, default => 'list');
140
141 =attribute_public item_root is: ro, isa: Str, default: 'data'
142
143 item_root controls how to reference where the data for single object
144 requests is in the the request_data
145
146 =cut
147
148 has 'item_root' => ( is => 'ro', isa => Str, default => 'data');
149
150 =attribute_public total_entries_arg is: ro, isa: Str, default: 'totalcount'
151
152 total_entries_arg controls how to reference 'total_entries' in the the request_data
153
154 =cut
155
156 has 'total_entries_arg' => ( is => 'ro', isa => Str, default => 'totalcount' );
157
158 =attribute_public use_json_boolean is: ro, isa: Bool, default: 0
159
160 use_json_boolean controls whether JSON boolean types are used in the success parameter of the response or if raw strings are used
161
162 =cut
163
164 has 'use_json_boolean' => ( is => 'ro', isa => Bool, default => 0 );
165
166 =attribute_public return_object is: ro, isa: Bool, default: 0
167
168 return_object controls whether the results of create/update are serialized and returned in the response
169
170 =cut
171
172 has 'return_object' => ( is => 'ro', isa => Bool, default => 0 );
173
174 =head1 DESCRIPTION
175
176 StaticArguments is a Role that is composed by the controller to provide configuration parameters such as how where in the request data to find specific elements, and if to use JSON boolean types.
177
178 =cut
179
180 1;