62eecba9eb92b2e1de663cab7c24e0797067068f
[dbsrgits/SQL-Abstract-2.0-ish.git] / lib / SQL / Abstract / Types.pm
1 use MooseX::Declare;
2 class SQL::Abstract::Types {
3   use Moose::Util::TypeConstraints;
4   use MooseX::Types -declare => [qw/NameSeparator QuoteChars AST ArrayAST HashAST/];
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,
18     as Str,
19     where { length($_) == 1 };
20
21
22   subtype QuoteChars,
23     as ArrayRef[Str];
24     where { @$_ == 1 || @$_ == 2 },
25     message { "Quote characters must be one or two elements" };
26
27   coerce QuoteChars, from Str, via { [ split //, $_ ] };
28
29 }
30
31 1;