1 package Catalyst::Model::DBIC::Schema::Types;
4 -declare => [qw/ConnectInfo ConnectInfos Replicants SchemaClass CursorClass/];
6 use Carp::Clan '^Catalyst::Model::DBIC::Schema';
7 use MooseX::Types::Moose qw/ArrayRef HashRef Str ClassName/;
8 use Scalar::Util 'reftype';
9 use List::MoreUtils 'all';
11 use namespace::clean -except => 'meta';
18 via { Class::MOP::load_class($_); $_ };
25 via { Class::MOP::load_class($_); $_ };
29 where { exists $_->{dsn} },
30 message { 'Does not look like a valid connect_info' };
34 via(\&_coerce_connect_info_from_str),
36 via(\&_coerce_connect_info_from_arrayref);
38 # { connect_info => [ ... ] } coercion would be nice, but no chained coercions
40 # Also no coercion from base type (yet,) but in Moose git already.
42 # via { $_->{connect_info} },
45 as ArrayRef[ConnectInfo],
46 message { "Not a valid array of connect_info's" };
50 via { [ _coerce_connect_info_from_str() ] },
53 !ref $_ ? _coerce_connect_info_from_str()
54 : reftype $_ eq 'HASH' ? $_
55 : reftype $_ eq 'ARRAY' ? _coerce_connect_info_from_arrayref()
56 : die 'invalid connect_info'
59 sub _coerce_connect_info_from_arrayref {
65 if (!ref $_->[0]) { # array style
66 $connect_info{dsn} = shift @$_;
67 $connect_info{user} = shift @$_ if !ref $_->[0];
68 $connect_info{password} = shift @$_ if !ref $_->[0];
71 my $extra = shift @$_;
73 die "invalid connect_info" unless reftype $extra eq 'HASH';
75 %connect_info = (%connect_info, %$extra);
78 die "invalid connect_info" if @$_;
79 } elsif (@$_ == 1 && reftype $_->[0] eq 'HASH') {
82 die "invalid connect_info";
85 for my $key (qw/user password/) {
86 $connect_info{$key} = ''
87 if not defined $connect_info{$key};
93 sub _coerce_connect_info_from_str {
94 +{ dsn => $_, user => '', password => '' }