Quoting + simple selects (and tests)
[dbsrgits/SQL-Abstract-2.0-ish.git] / lib / SQL / Abstract / Types.pm
CommitLineData
cbcfedc1 1use MooseX::Declare;
2class SQL::Abstract::Types {
3 use Moose::Util::TypeConstraints;
4ee32f41 4 use MooseX::Types -declare => [qw/NameSeparator QuoteChars AST ArrayAST HashAST/];
cbcfedc1 5 use MooseX::Types::Moose qw/ArrayRef Str Int Ref HashRef/;
6
7 subtype ArrayAST, as ArrayRef,
8 where { is_Str($_->[0]) && substr($_->[0],0,1) eq '-' },
9 message { "First key of arrayref must be a string starting with '-'"; };
10
11 subtype HashAST, as HashRef,
12 where { exists $_->{-type} && is_Str($_->{-type}) },
13 message { "No '-type' key, or it is not a string" };
14
15 subtype AST, as ArrayAST|HashAST;
16
17 subtype NameSeparator,
4ee32f41 18 as Str,
19 where { length($_) == 1 };
20
21
22 subtype QuoteChars,
cbcfedc1 23 as ArrayRef[Str];
4ee32f41 24 where { @$_ == 1 || @$_ == 2 },
25 message { "Quote characters must be one or two elements" };
cbcfedc1 26
4ee32f41 27 coerce QuoteChars, from Str, via { [ split //, $_ ] };
cbcfedc1 28
29}
30
311;