1 package Catalyst::Model::DBIC::Schema::Types;
4 -declare => [qw/ConnectInfo ConnectInfos Replicants SchemaClass/];
6 use MooseX::Types::Moose qw/ArrayRef HashRef Str ClassName/;
7 use Scalar::Util 'reftype';
8 use List::MoreUtils 'all';
11 use namespace::clean -except => 'meta';
18 via { Class::MOP::load_class($_); $_ };
22 where { exists $_->{dsn} },
23 message { 'Does not look like a valid connect_info' };
27 via { +{ dsn => $_ } },
29 via \&_coerce_connect_info_from_arrayref;
31 # { connect_info => [ ... ] } coercion would be nice, but no chained coercions
33 # Also no coercion from base type (yet,) but in Moose git already.
35 # via { $_->{connect_info} },
38 as ArrayRef[ConnectInfo],
39 message { "Not a valid array of connect_info's" };
43 via { [ { dsn => $_ } ] },
45 via { [ map +{ dsn => $_ }, @$_ ] },
46 from ArrayRef[ArrayRef],
47 via { [ map \&_coerce_connect_info_from_arrayref, @$_ ] };
49 sub _coerce_connect_info_from_arrayref {
52 if (!ref $_->[0]) { # array style
53 $connect_info{dsn} = shift @$_;
54 $connect_info{user} = shift @$_ if !ref $_->[0];
55 $connect_info{password} = shift @$_ if !ref $_->[0];
58 my $extra = shift @$_;
60 croak "invalid connect_info" unless reftype $extra eq 'HASH';
62 %connect_info = (%connect_info, %$extra);
65 croak "invalid connect_info" if @$_;
66 } elsif (@$_ == 1 && reftype $_->[0] eq 'HASH') {
69 croak "invalid connect_info";