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 updating objects.
14 Each provides a number of handles:
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'
26 qw( create_requires create_allows update_requires update_allows ))
30 isa => ArrayRef [ Str | HashRef ],
32 default => sub { [] },
34 my ( $self, $new ) = @_;
35 $self->check_column_relation( $_, 1 ) for @$new;
38 "get_${var}_column" => 'get',
39 "set_${var}_column" => 'set',
40 "delete_${var}_column" => 'delete',
41 "insert_${var}_column" => 'insert',
42 "count_${var}_column" => 'count',
43 "all_${var}_columns" => 'elements',
47 before "set_${var}_column" =>
48 sub { $_[0]->check_column_relation( $_[2], 1 ) };
49 before "insert_${var}_column" =>
50 sub { $_[0]->check_column_relation( $_[2], 1 ) };
53 =attribute_public prefetch_allows is: ro, isa: ArrayRef[ArrayRef|Str|HashRef]
55 prefetch_allows limits what relations may be prefetched when executing searches with joins. This is necessary to avoid denial of service attacks in form of queries which would return a large number of data and unwanted disclosure of data.
57 Like the synopsis in DBIC::API shows, you can declare a "template" of what is allowed (by using an '*'). Each element passed in, will be converted into a Data::DPath and added to the validator.
59 prefetch_allows => [ 'cds', { cds => tracks }, { cds => producers } ] # to be explicit
60 prefetch_allows => [ 'cds', { cds => '*' } ] # wildcard means the same thing
64 has 'prefetch_allows' => (
66 writer => '_set_prefetch_allows',
67 isa => ArrayRef [ ArrayRef | Str | HashRef ],
68 default => sub { [] },
69 predicate => 'has_prefetch_allows',
71 handles => { all_prefetch_allows => 'elements', },
74 has 'prefetch_validator' => (
76 isa => 'Catalyst::Controller::DBIC::API::Validator',
80 sub _build_prefetch_validator {
84 my ( $self, $rel, $static, $validator ) = @_;
85 if ( ArrayRef->check($rel) ) {
86 foreach my $rel_sub (@$rel) {
87 _check_rel( $self, $rel_sub, $static, $validator );
90 elsif ( HashRef->check($rel) ) {
91 while ( my ( $k, $v ) = each %$rel ) {
92 $self->check_has_relation( $k, $v, undef, $static );
94 $validator->load($rel);
97 $self->check_has_relation( $rel, undef, undef, $static );
98 $validator->load($rel);
102 my $validator = Catalyst::Controller::DBIC::API::Validator->new;
104 foreach my $rel ( $self->all_prefetch_allows ) {
105 _check_rel( $self, $rel, 1, $validator );
111 =attribute_public count_arg is: ro, isa: Str, default: 'list_count'
113 count_arg controls how to reference 'count' in the the request_data
117 has 'count_arg' => ( is => 'ro', isa => Str, default => 'list_count' );
119 =attribute_public page_arg is: ro, isa: Str, default: 'list_page'
121 page_arg controls how to reference 'page' in the the request_data
125 has 'page_arg' => ( is => 'ro', isa => Str, default => 'list_page' );
127 =attribute_public offset_arg is: ro, isa: Str, default: 'list_offset'
129 offset_arg controls how to reference 'offset' in the the request_data
133 has 'offset_arg' => ( is => 'ro', isa => Str, default => 'list_offset' );
135 =attribute_public select_arg is: ro, isa: Str, default: 'list_returns'
137 select_arg controls how to reference 'select' in the the request_data
141 has 'select_arg' => ( is => 'ro', isa => Str, default => 'list_returns' );
143 =attribute_public as_arg is: ro, isa: Str, default: 'as'
145 as_arg controls how to reference 'as' in the the request_data
149 has 'as_arg' => ( is => 'ro', isa => Str, default => 'as' );
151 =attribute_public search_arg is: ro, isa: Str, default: 'search'
153 search_arg controls how to reference 'search' in the the request_data
157 has 'search_arg' => ( is => 'ro', isa => Str, default => 'search' );
159 =attribute_public grouped_by_arg is: ro, isa: Str, default: 'list_grouped_by'
161 grouped_by_arg controls how to reference 'grouped_by' in the the request_data
165 has 'grouped_by_arg' =>
166 ( is => 'ro', isa => Str, default => 'list_grouped_by' );
168 =attribute_public ordered_by_arg is: ro, isa: Str, default: 'list_ordered_by'
170 ordered_by_arg controls how to reference 'ordered_by' in the the request_data
174 has 'ordered_by_arg' =>
175 ( is => 'ro', isa => Str, default => 'list_ordered_by' );
177 =attribute_public prefetch_arg is: ro, isa: Str, default: 'list_prefetch'
179 prefetch_arg controls how to reference 'prefetch' in the the request_data
183 has 'prefetch_arg' => ( is => 'ro', isa => Str, default => 'list_prefetch' );
185 =attribute_public stash_key is: ro, isa: Str, default: 'response'
187 stash_key controls where in stash request_data should be stored
191 has 'stash_key' => ( is => 'ro', isa => Str, default => 'response' );
193 =attribute_public data_root is: ro, isa: Str, default: 'list'
195 data_root controls how to reference where the data is in the the request_data
199 has 'data_root' => ( is => 'ro', isa => Str, default => 'list' );
201 =attribute_public item_root is: ro, isa: Str, default: 'data'
203 item_root controls how to reference where the data for single object
204 requests is in the the request_data
208 has 'item_root' => ( is => 'ro', isa => Str, default => 'data' );
210 =attribute_public total_entries_arg is: ro, isa: Str, default: 'totalcount'
212 total_entries_arg controls how to reference 'total_entries' in the the request_data
216 has 'total_entries_arg' =>
217 ( is => 'ro', isa => Str, default => 'totalcount' );
219 =attribute_public use_json_boolean is: ro, isa: Bool, default: 0
221 use_json_boolean controls whether JSON boolean types are used in the success parameter of the response or if raw strings are used
225 has 'use_json_boolean' => ( is => 'ro', isa => Bool, default => 0 );
227 =attribute_public return_object is: ro, isa: Bool, default: 0
229 return_object controls whether the results of create/update are serialized and returned in the response
233 has 'return_object' => ( is => 'ro', isa => Bool, default => 0 );
237 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.