1 package Catalyst::Model::DBIC::Schema::Types;
3 use MooseX::Types -declare => [qw/
4 ConnectInfo ConnectInfos Replicants SchemaClass CursorClass
8 use Carp::Clan '^Catalyst::Model::DBIC::Schema';
9 use MooseX::Types::Moose qw/ArrayRef HashRef Str ClassName/;
10 use Scalar::Util 'reftype';
11 use List::MoreUtils 'all';
13 use namespace::clean -except => 'meta';
20 via { Class::MOP::load_class($_); $_ };
27 via { Class::MOP::load_class($_); $_ };
31 where { exists $_->{dsn} },
32 message { 'Does not look like a valid connect_info' };
36 via(\&_coerce_connect_info_from_str),
38 via(\&_coerce_connect_info_from_arrayref);
40 # { connect_info => [ ... ] } coercion would be nice, but no chained coercions
42 # Also no coercion from base type (yet,) but in Moose git already.
44 # via { $_->{connect_info} },
47 as ArrayRef[ConnectInfo],
48 message { "Not a valid array of connect_info's" };
52 via { [ _coerce_connect_info_from_str() ] },
55 !ref $_ ? _coerce_connect_info_from_str()
56 : reftype $_ eq 'HASH' ? $_
57 : reftype $_ eq 'ARRAY' ? _coerce_connect_info_from_arrayref()
58 : die 'invalid connect_info'
65 where { /^(?:static|dynamic)\z/ },
66 message { "Invalid create option, must be one of 'static' or 'dynamic'" };
68 sub _coerce_connect_info_from_arrayref {
74 if (!ref $_->[0]) { # array style
75 $connect_info{dsn} = shift @$_;
76 $connect_info{user} = shift @$_ if !ref $_->[0];
77 $connect_info{password} = shift @$_ if !ref $_->[0];
80 my $extra = shift @$_;
82 die "invalid connect_info" unless reftype $extra eq 'HASH';
84 %connect_info = (%connect_info, %$extra);
87 die "invalid connect_info" if @$_;
88 } elsif (@$_ == 1 && reftype $_->[0] eq 'HASH') {
91 die "invalid connect_info";
94 for my $key (qw/user password/) {
95 $connect_info{$key} = ''
96 if not defined $connect_info{$key};
102 sub _coerce_connect_info_from_str {
103 +{ dsn => $_, user => '', password => '' }