initial commit with working tests, docs, and conversion to dzil+podweaver
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / StaticArguments.pm
CommitLineData
d2739840 1package Catalyst::Controller::DBIC::API::StaticArguments;
2
3#ABSTRACT: Provides controller level configuration arguments
4use Moose::Role;
5use MooseX::Types::Moose(':all');
6use namespace::autoclean;
7
8requires 'check_column_relation';
9
10=attribute_public create_requires create_allows update_requires update_allows
11
12These attributes control requirements and limits to columns when creating or updating objects.
13
14Each 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
25foreach 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
55count_arg controls how to reference 'count' in the the request_data
56
57=cut
58
59has 'count_arg' => ( is => 'ro', isa => Str, default => 'list_count' );
60
61=attribute_public page_arg is: ro, isa: Str, default: 'list_page'
62
63page_arg controls how to reference 'page' in the the request_data
64
65=cut
66
67has 'page_arg' => ( is => 'ro', isa => Str, default => 'list_page' );
68
69=attribute_public select_arg is: ro, isa: Str, default: 'list_returns'
70
71select_arg controls how to reference 'select' in the the request_data
72
73=cut
74
75has 'select_arg' => ( is => 'ro', isa => Str, default => 'list_returns' );
76
77=attribute_public as_arg is: ro, isa: Str, default: 'as'
78
79as_arg controls how to reference 'as' in the the request_data
80
81=cut
82
83has 'as_arg' => ( is => 'ro', isa => Str, default => 'as' );
84
85=attribute_public search_arg is: ro, isa: Str, default: 'search'
86
87search_arg controls how to reference 'search' in the the request_data
88
89=cut
90
91has 'search_arg' => ( is => 'ro', isa => Str, default => 'search' );
92
93=attribute_public grouped_by_arg is: ro, isa: Str, default: 'list_grouped_by'
94
95grouped_by_arg controls how to reference 'grouped_by' in the the request_data
96
97=cut
98
99has 'grouped_by_arg' => ( is => 'ro', isa => Str, default => 'list_grouped_by' );
100
101=attribute_public ordered_by_arg is: ro, isa: Str, default: 'list_ordered_by'
102
103ordered_by_arg controls how to reference 'ordered_by' in the the request_data
104
105=cut
106
107has 'ordered_by_arg' => ( is => 'ro', isa => Str, default => 'list_ordered_by' );
108
109=attribute_public prefetch_arg is: ro, isa: Str, default: 'list_prefetch'
110
111prefetch_arg controls how to reference 'prefetch' in the the request_data
112
113=cut
114
115has 'prefetch_arg' => ( is => 'ro', isa => Str, default => 'list_prefetch' );
116
117=attribute_public data_root is: ro, isa: Str, default: 'listt'
118
119data_root controls how to reference where the data is in the the request_data
120
121=cut
122
123has 'data_root' => ( is => 'ro', isa => Str, default => 'list');
124
125=attribute_public total_entries_arg is: ro, isa: Str, default: 'totalcount'
126
127total_entries_arg controls how to reference 'total_entries' in the the request_data
128
129=cut
130
131has 'total_entries_arg' => ( is => 'ro', isa => Str, default => 'totalcount' );
132
133=attribute_public use_json_boolean is: ro, isa: Bool, default: 0
134
135use_json_boolean controls whether JSON::Any boolean types are used in the success parameter of the response or if raw strings are used
136
137=cut
138
139has 'use_json_boolean' => ( is => 'ro', isa => Bool, default => 0 );
140
141=attribute_public return_object is: ro, isa: Bool, default: 0
142
143return_object controls whether the results of create/update are serialized and returned in the response
144
145=cut
146
147has 'return_object' => ( is => 'ro', isa => Bool, default => 0 );
148
149=head1 DESCRIPTION
150
151StaticArguments 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.
152
153=cut
154
1551;