Added possibility to tweak resultset class after searching
[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 data_root is: ro, isa: Str, default: 'list'
126
127 data_root controls how to reference where the data is in the the request_data
128
129 =cut
130
131 has 'data_root' => ( is => 'ro', isa => Str, default => 'list');
132
133 =attribute_public item_root is: ro, isa: Str, default: 'data'
134
135 item_root controls how to reference where the data for single object
136 requests is in the the request_data
137
138 =cut
139
140 has 'item_root' => ( is => 'ro', isa => Str, default => 'data');
141
142 =attribute_public total_entries_arg is: ro, isa: Str, default: 'totalcount'
143
144 total_entries_arg controls how to reference 'total_entries' in the the request_data
145
146 =cut
147
148 has 'total_entries_arg' => ( is => 'ro', isa => Str, default => 'totalcount' );
149
150 =attribute_public use_json_boolean is: ro, isa: Bool, default: 0
151
152 use_json_boolean controls whether JSON::Any boolean types are used in the success parameter of the response or if raw strings are used
153
154 =cut
155
156 has 'use_json_boolean' => ( is => 'ro', isa => Bool, default => 0 );
157
158 =attribute_public return_object is: ro, isa: Bool, default: 0
159
160 return_object controls whether the results of create/update are serialized and returned in the response
161
162 =cut
163
164 has 'return_object' => ( is => 'ro', isa => Bool, default => 0 );
165
166 =head1 DESCRIPTION
167
168 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.
169
170 =cut
171
172 1;