1 package # hide from PAUSE
2 Catalyst::Model::DBIC::Schema::Types;
4 use MooseX::Types -declare => [qw/
5 ConnectInfo ConnectInfos Replicants SchemaClass CursorClass
9 use Carp::Clan '^Catalyst::Model::DBIC::Schema';
10 use MooseX::Types::Moose qw/ArrayRef HashRef Str ClassName/;
11 use Scalar::Util 'reftype';
12 use List::MoreUtils 'all';
14 use namespace::clean -except => 'meta';
21 via { Class::MOP::load_class($_); $_ };
28 via { Class::MOP::load_class($_); $_ };
32 where { exists $_->{dsn} },
33 message { 'Does not look like a valid connect_info' };
37 via(\&_coerce_connect_info_from_str),
39 via(\&_coerce_connect_info_from_arrayref);
41 # { connect_info => [ ... ] } coercion would be nice, but no chained coercions
43 # Also no coercion from base type (yet,) but in Moose git already.
45 # via { $_->{connect_info} },
48 as ArrayRef[ConnectInfo],
49 message { "Not a valid array of connect_info's" };
53 via { [ _coerce_connect_info_from_str() ] },
56 !ref $_ ? _coerce_connect_info_from_str()
57 : reftype $_ eq 'HASH' ? $_
58 : reftype $_ eq 'ARRAY' ? _coerce_connect_info_from_arrayref()
59 : die 'invalid connect_info'
66 where { /^(?:static|dynamic)\z/ },
67 message { "Invalid create option, must be one of 'static' or 'dynamic'" };
69 sub _coerce_connect_info_from_arrayref {
75 if (!ref $_->[0]) { # array style
76 $connect_info{dsn} = shift @$_;
77 $connect_info{user} = shift @$_ if !ref $_->[0];
78 $connect_info{password} = shift @$_ if !ref $_->[0];
81 my $extra = shift @$_;
83 die "invalid connect_info" unless reftype $extra eq 'HASH';
85 %connect_info = (%connect_info, %$extra);
88 die "invalid connect_info" if @$_;
89 } elsif (@$_ == 1 && reftype $_->[0] eq 'HASH') {
92 die "invalid connect_info";
95 for my $key (qw/user password/) {
96 $connect_info{$key} = ''
97 if not defined $connect_info{$key};
103 sub _coerce_connect_info_from_str {
104 +{ dsn => $_, user => '', password => '' }