1 package Catalyst::Controller::DBIC::API::StaticArguments;
3 #ABSTRACT: Provides controller level configuration arguments
5 use MooseX::Types::Moose(':all');
6 use namespace::autoclean;
8 requires 'check_column_relation';
10 =attribute_public create_requires create_allows update_requires update_allows
12 These attributes control requirements and limits to columns when creating or
15 Each provides a number of handles:
17 "get_${var}_column" => 'get'
18 "set_${var}_column" => 'set'
19 "delete_${var}_column" => 'delete'
20 "insert_${var}_column" => 'insert'
21 "count_${var}_column" => 'count'
22 "all_${var}_columns" => 'elements'
27 qw( create_requires create_allows update_requires update_allows ))
31 isa => ArrayRef [ Str | HashRef ],
33 default => sub { [] },
35 my ( $self, $new ) = @_;
36 $self->check_column_relation( $_, 1 ) for @$new;
39 "get_${var}_column" => 'get',
40 "set_${var}_column" => 'set',
41 "delete_${var}_column" => 'delete',
42 "insert_${var}_column" => 'insert',
43 "count_${var}_column" => 'count',
44 "all_${var}_columns" => 'elements',
48 before "set_${var}_column" =>
49 sub { $_[0]->check_column_relation( $_[2], 1 ) };
50 before "insert_${var}_column" =>
51 sub { $_[0]->check_column_relation( $_[2], 1 ) };
54 =attribute_public prefetch_allows
56 prefetch_allows limits what relations may be prefetched when executing searches
57 with joins. This is necessary to avoid denial of service attacks in form of
58 queries which would return a large number of data and unwanted disclosure of
61 Like the synopsis in DBIC::API shows, you can declare a "template" of what is
62 allowed (by using an '*'). Each element passed in, will be converted into a
63 Data::DPath and added to the validator.
65 prefetch_allows => [ 'cds', { cds => tracks }, { cds => producers } ] # to be explicit
66 prefetch_allows => [ 'cds', { cds => '*' } ] # wildcard means the same thing
70 has 'prefetch_allows' => (
72 writer => '_set_prefetch_allows',
73 isa => ArrayRef [ ArrayRef | Str | HashRef ],
74 default => sub { [] },
75 predicate => 'has_prefetch_allows',
77 handles => { all_prefetch_allows => 'elements', },
80 has 'prefetch_validator' => (
82 isa => 'Catalyst::Controller::DBIC::API::Validator',
86 sub _build_prefetch_validator {
90 my ( $self, $rel, $static, $validator ) = @_;
91 if ( ArrayRef->check($rel) ) {
92 foreach my $rel_sub (@$rel) {
93 _check_rel( $self, $rel_sub, $static, $validator );
96 elsif ( HashRef->check($rel) ) {
97 while ( my ( $k, $v ) = each %$rel ) {
98 $self->check_has_relation( $k, $v, undef, $static );
100 $validator->load($rel);
103 $self->check_has_relation( $rel, undef, undef, $static );
104 $validator->load($rel);
108 my $validator = Catalyst::Controller::DBIC::API::Validator->new;
110 foreach my $rel ( $self->all_prefetch_allows ) {
111 _check_rel( $self, $rel, 1, $validator );
117 =attribute_public count_arg
119 Controls how to reference 'count' in the the request_data, defaults to
124 has 'count_arg' => ( is => 'ro', isa => Str, default => 'list_count' );
126 =attribute_public page_arg
128 Controls how to reference 'page' in the the request_data, defaults to
133 has 'page_arg' => ( is => 'ro', isa => Str, default => 'list_page' );
135 =attribute_public offset_arg
137 Controls how to reference 'offset' in the the request_data, defaults to
142 has 'offset_arg' => ( is => 'ro', isa => Str, default => 'list_offset' );
144 =attribute_public select_arg
146 Controls how to reference 'select' in the the request_data, defaults to
151 has 'select_arg' => ( is => 'ro', isa => Str, default => 'list_returns' );
153 =attribute_public as_arg
155 Controls how to reference 'as' in the the request_data, defaults to 'as'.
159 has 'as_arg' => ( is => 'ro', isa => Str, default => 'as' );
161 =attribute_public search_arg
163 Controls how to reference 'search' in the the request_data, defaults to
168 has 'search_arg' => ( is => 'ro', isa => Str, default => 'search' );
170 =attribute_public grouped_by_arg
172 Controls how to reference 'grouped_by' in the the request_data, defaults to
177 has 'grouped_by_arg' =>
178 ( is => 'ro', isa => Str, default => 'list_grouped_by' );
180 =attribute_public ordered_by_arg
182 Controls how to reference 'ordered_by' in the the request_data, defaults to
187 has 'ordered_by_arg' =>
188 ( is => 'ro', isa => Str, default => 'list_ordered_by' );
190 =attribute_public prefetch_arg
192 Controls how to reference 'prefetch' in the the request_data, defaults to
197 has 'prefetch_arg' => ( is => 'ro', isa => Str, default => 'list_prefetch' );
199 =attribute_public stash_key
201 Controls where in the stash the request_data should be stored, defaults to
206 has 'stash_key' => ( is => 'ro', isa => Str, default => 'response' );
208 =attribute_public data_root
210 Controls how to reference where the data is in the the request_data, defaults to
215 has 'data_root' => ( is => 'ro', isa => Str, default => 'list' );
217 =attribute_public item_root
219 Controls how to reference where the data for single object requests is in the
220 the request_data, defaults to 'data'.
224 has 'item_root' => ( is => 'ro', isa => Str, default => 'data' );
226 =attribute_public total_entries_arg
228 Controls how to reference 'total_entries' in the the request_data, defaults to
233 has 'total_entries_arg' =>
234 ( is => 'ro', isa => Str, default => 'totalcount' );
236 =attribute_public use_json_boolean
238 Controls whether JSON boolean types are used in the success parameter of the
239 response or if raw strings are used, defaults to false.
243 has 'use_json_boolean' => ( is => 'ro', isa => Bool, default => 0 );
245 =attribute_public return_object
247 Controls whether the results of create/update are serialized and returned in
248 the response, defaults to false.
252 has 'return_object' => ( is => 'ro', isa => Bool, default => 0 );
256 StaticArguments is a role that is composed by the controller to provide
257 configuration parameters such as where to find specific elements in the request
258 data and if to use JSON boolean types.