Add more coercions to some types so we can specify more complex sorting behavior
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / Types.pm
1 package Catalyst::Controller::DBIC::API::Types;
2
3 #ABSTRACT: Provides shortcut types and coercions for DBIC::API
4 use warnings;
5 use strict;
6
7 use MooseX::Types -declare => [qw/OrderedBy GroupedBy Prefetch SelectColumns AsAliases ResultSource ResultSet Model SearchParameters JoinBuilder/];
8 use MooseX::Types::Moose(':all');
9
10 =type Prefetch as Maybe[ArrayRef[Str|HashRef]]
11
12 Represents the structure of the prefetch argument.
13
14 Coerces Str and HashRef.
15
16 =cut
17
18 subtype Prefetch, as Maybe[ArrayRef[Str|HashRef]];
19 coerce Prefetch, from Str, via { [$_] }, from HashRef, via { [$_] };
20
21 =type GroupedBy as Maybe[ArrayRef[Str]]
22
23 Represents the structure of the grouped_by argument.
24
25 Coerces Str.
26
27 =cut
28
29 subtype GroupedBy, as Maybe[ArrayRef[Str]];
30 coerce GroupedBy, from Str, via { [$_] };
31
32 =type OrderedBy as Maybe[ArrayRef[Str|HashRef|ScalarRef]]
33
34 Represents the structure of the ordered_by argument
35
36 Coerces Str.
37
38 =cut
39
40 subtype OrderedBy, as Maybe[ArrayRef[Str|HashRef|ScalarRef]];
41 coerce OrderedBy, from Str, via { [$_] }, from HashRef, via { [$_] };
42
43 =type SelectColumns as Maybe[ArrayRef[Str|HashRef]]
44
45 Represents the structure of the select argument
46
47 Coerces Str.
48
49 =cut
50
51 subtype SelectColumns, as Maybe[ArrayRef[Str|HashRef]];
52 coerce SelectColumns, from Str, via { [$_] }, from HashRef, via { [$_] };
53
54 =type SearchParameters as Maybe[ArrayRef[HashRef]]
55
56 Represents the structure of the search argument
57
58 Coerces HashRef.
59
60 =cut
61
62 subtype SearchParameters, as Maybe[ArrayRef[HashRef]];
63 coerce SearchParameters, from HashRef, via { [$_] };
64
65 =type AsAliases as Maybe[ArrayRef[Str]]
66
67 Represents the structure of the as argument
68
69 =cut
70
71 subtype AsAliases, as Maybe[ArrayRef[Str]];
72
73 =type ResultSet as class_type('DBIx::Class::ResultSet')
74
75 Shortcut for DBIx::Class::ResultSet
76
77 =cut
78
79 subtype ResultSet, as class_type('DBIx::Class::ResultSet');
80
81 =type ResultSource as class_type('DBIx::Class::ResultSource')
82
83 Shortcut for DBIx::Class::ResultSource
84
85 =cut
86
87 subtype ResultSource, as class_type('DBIx::Class::ResultSource');
88
89 =type JoinBuilder as class_type('Catalyst::Controller::DBIC::API::JoinBuilder')
90
91 Shortcut for Catalyst::Controller::DBIC::API::JoinBuilder
92
93 =cut
94
95 subtype JoinBuilder, as class_type('Catalyst::Controller::DBIC::API::JoinBuilder');
96
97 =type Model as class_type('DBIx::Class')
98
99 Shortcut for model objects
100
101 =cut
102
103 subtype Model, as class_type('DBIx::Class');
104
105 1;