| 1 | package # hide from PAUSE | ||||||||||||||||||||||||||||||||||
| 2 | Catalyst::Model::DBIC::Schema::Types; | ||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use MooseX::Types -declare => [qw/ | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | ConnectInfo ConnectInfos Replicants SchemaClass CreateOption | ||||||||||||||||||||||||||||||||||
| 6 | Schema LoadedClass | ||||||||||||||||||||||||||||||||||
| 7 | 6 | /]; | |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Carp::Clan '^Catalyst::Model::DBIC::Schema'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use MooseX::Types::Moose qw/ArrayRef HashRef CodeRef Str ClassName/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use MooseX::Types::LoadableClass qw/LoadableClass/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Scalar::Util 'reftype'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use List::MoreUtils 'all'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Module::Runtime; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | # So I restored the custom Type LoadedClass because 'LoadableClass' doesn't really | ||||||||||||||||||||||||||||||||||
| 19 | # exactly do the same thing, which busted the Replication trait. Please don't | ||||||||||||||||||||||||||||||||||
| 20 | # "clean this up" -JNAP | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | 6 | subtype LoadedClass, | |||||||||||||||||||||||||||||||||
| 23 | as ClassName; | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | coerce LoadedClass, | ||||||||||||||||||||||||||||||||||
| 26 | from Str, # N.B. deliberate paranoia against $_ clobbering below | ||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | via { my $classname = $_; Module::Runtime::use_module($classname); $classname }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | subtype SchemaClass, | ||||||||||||||||||||||||||||||||||
| 30 | as LoadableClass, | ||||||||||||||||||||||||||||||||||
| 31 | 13 | ▶ | where { $_->isa('DBIx::Class::Schema') }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | 6 | class_type Schema, { class => 'DBIx::Class::Schema' }; | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | subtype ConnectInfo, | ||||||||||||||||||||||||||||||||||
| 36 | as HashRef, | ||||||||||||||||||||||||||||||||||
| 37 | 25 | ▶ | where { exists $_->{dsn} || exists $_->{dbh_maker} }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | message { 'Does not look like a valid connect_info' }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | coerce ConnectInfo, | ||||||||||||||||||||||||||||||||||
| 41 | from Str, | ||||||||||||||||||||||||||||||||||
| 42 | via(\&_coerce_connect_info_from_str), | ||||||||||||||||||||||||||||||||||
| 43 | from ArrayRef, | ||||||||||||||||||||||||||||||||||
| 44 | via(\&_coerce_connect_info_from_arrayref), | ||||||||||||||||||||||||||||||||||
| 45 | from CodeRef, | ||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | via { +{ dbh_maker => $_ } }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 47 | 6 | ; | |||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | # { connect_info => [ ... ] } coercion would be nice, but no chained coercions | ||||||||||||||||||||||||||||||||||
| 50 | # yet. | ||||||||||||||||||||||||||||||||||
| 51 | # Also no coercion from base type (yet,) but in Moose git already. | ||||||||||||||||||||||||||||||||||
| 52 | # from HashRef, | ||||||||||||||||||||||||||||||||||
| 53 | # via { $_->{connect_info} }, | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | subtype ConnectInfos, | ||||||||||||||||||||||||||||||||||
| 56 | as ArrayRef[ConnectInfo], | ||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | message { "Not a valid array of connect_info's" }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | coerce ConnectInfos, | ||||||||||||||||||||||||||||||||||
| 60 | from Str, | ||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | via { [ _coerce_connect_info_from_str() ] }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 62 | from CodeRef, | ||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | via { [ +{ dbh_maker => $_ } ] }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 64 | from HashRef, | ||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | via { [ $_ ] }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 66 | from ArrayRef, | ||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | via { [ map { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.4
| |||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | !ref $_ ? _coerce_connect_info_from_str() | ||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||
| 69 | : reftype $_ eq 'HASH' ? $_ | ||||||||||||||||||||||||||||||||||
| 70 | : reftype $_ eq 'CODE' ? +{ dbh_maker => $_ } | ||||||||||||||||||||||||||||||||||
| 71 | : reftype $_ eq 'ARRAY' ? _coerce_connect_info_from_arrayref() | ||||||||||||||||||||||||||||||||||
| 72 | : croak 'invalid connect_info' | ||||||||||||||||||||||||||||||||||
| 73 | 6 | } @$_ ] }; | |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | # Helper stuff | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | subtype CreateOption, | ||||||||||||||||||||||||||||||||||
| 78 | as Str, | ||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | where { /^(?:static|dynamic)\z/ }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | message { "Invalid create option, must be one of 'static' or 'dynamic'" }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | 21 | ▶ | sub _coerce_connect_info_from_arrayref { | ||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_connect_info_from_arrayref: called CC=14 SCAR=27.9
| |||||||||||||||||||||||||||||||||||
| 83 | 21 | my %connect_info; | |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | # make a copy | ||||||||||||||||||||||||||||||||||
| 86 | 21 | $_ = [ @$_ ]; | |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | 18 | ▶ | my $slurp_hashes = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||||||||
| 89 | 18 | for my $i (0..1) { | |||||||||||||||||||||||||||||||||
| 90 | 25 | my $extra = shift @$_; | |||||||||||||||||||||||||||||||||
| 91 | 25 | ▶ | last unless $extra; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 92 | 10 | ▶ | croak "invalid connect_info" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $extra and builtin::reftype($extra) eq "HASH"
MC/DC0%0/2
ref $extra and builtin::reftype($extra) eq "HASH"
ref $extra
builtin::reftype($extra) eq "HASH"
Truth table33%1/3
A and B
A= ref $extraB= builtin::reftype($extra) eq "HASH"
| |||||||||||||||||||||||||||||||||||
| 93 | unless ref $extra && reftype $extra eq 'HASH'; | ||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | 10 | %connect_info = (%connect_info, %$extra); | |||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||
| 97 | 21 | }; | |||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 21 | ▶ | if (!ref $_->[0]) { # array style | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 100 | 16 | $connect_info{dsn} = shift @$_; | |||||||||||||||||||||||||||||||||
| 101 | 16 | ▶ | $connect_info{user} = shift @$_ if !ref $_->[0]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | 16 | ▶ | $connect_info{password} = shift @$_ if !ref $_->[0]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 16 | $slurp_hashes->(); | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 16 | ▶ | croak "invalid connect_info" if @$_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 107 | ▶ | } elsif (ref $_->[0] && reftype $_->[0] eq 'CODE') { | |||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $_->[0] and builtin::reftype($_->[0]) eq "CODE"
MC/DC50%1/2
ref $_->[0] and builtin::reftype($_->[0]) eq "CODE"
ref $_->[0]
builtin::reftype($_->[0]) eq "CODE"
Truth table66%2/3
A and B
A= ref $_->[0]B= builtin::reftype($_->[0]) eq "CODE"
| |||||||||||||||||||||||||||||||||||
| 108 | 2 | $connect_info{dbh_maker} = shift @$_; | |||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | 2 | $slurp_hashes->(); | |||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 2 | ▶ | croak "invalid connect_info" if @$_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 113 | ▶ | } elsif (@$_ == 1 && ref $_->[0] && reftype $_->[0] eq 'HASH') { | |||||||||||||||||||||||||||||||||
|
Condition33%2/6
@$_ == 1 and ref $_->[0] and builtin::reftype($_->[0]) eq "HASH"
@$_ == 1 and ref $_->[0]
MC/DC0%0/3
@$_ == 1 and ref $_->[0] and builtin::reftype($_->[0]) eq "HASH"
@$_ == 1
ref $_->[0]
builtin::reftype($_->[0]) eq "HASH"
Truth table25%1/4
A and B and C
A= @$_ == 1B= ref $_->[0]C= builtin::reftype($_->[0]) eq "HASH"
| |||||||||||||||||||||||||||||||||||
| 114 | 3 | return $_->[0]; | |||||||||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||||||||
| 116 | 0 | croak "invalid connect_info"; | |||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | 17 | ▶ | unless ($connect_info{dbh_maker}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 120 | 15 | for my $key (qw/user password/) { | |||||||||||||||||||||||||||||||||
| 121 | $connect_info{$key} = '' | ||||||||||||||||||||||||||||||||||
| 122 | 30 | ▶ | if not defined $connect_info{$key}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | 17 | \%connect_info; | |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | 2 | ▶ | sub _coerce_connect_info_from_str { | ||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_connect_info_from_str: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 130 | 2 | +{ dsn => $_, user => '', password => '' } | |||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | 6 | 1; | |||||||||||||||||||||||||||||||||