line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::DBIx::Class::Types; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1188
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
239
|
use Class::MOP; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Scalar::Util qw(reftype); |
8
|
|
|
|
|
|
|
use MooseX::Types::Moose qw(Str Int ClassName ArrayRef HashRef); |
9
|
|
|
|
|
|
|
use MooseX::Types -declare => [qw/ |
10
|
|
|
|
|
|
|
TestBuilder SchemaManagerClass ConnectInfo FixtureClass |
11
|
|
|
|
|
|
|
ReplicantsConnectInfo |
12
|
|
|
|
|
|
|
/]; |
13
|
|
|
|
|
|
|
use Module::Runtime qw(use_module); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
subtype TestBuilder, |
16
|
|
|
|
|
|
|
as class_type('Test::Builder'); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
subtype SchemaManagerClass, |
19
|
|
|
|
|
|
|
as ClassName; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
coerce SchemaManagerClass, |
22
|
|
|
|
|
|
|
from Str, |
23
|
|
|
|
|
|
|
via { |
24
|
|
|
|
|
|
|
my $type = $_; |
25
|
|
|
|
|
|
|
return use_module($type); |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
subtype FixtureClass, |
29
|
|
|
|
|
|
|
as ClassName; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
coerce FixtureClass, |
32
|
|
|
|
|
|
|
from Str, |
33
|
|
|
|
|
|
|
via { |
34
|
|
|
|
|
|
|
my $type = $_; |
35
|
|
|
|
|
|
|
$type = "Test::DBIx::Class::FixtureCommand".$type if $type =~m/^::/; |
36
|
|
|
|
|
|
|
return use_module($type); |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
## ConnectInfo cargo culted from "Catalyst::Model::DBIC::Schema::Types" |
40
|
|
|
|
|
|
|
subtype ConnectInfo, |
41
|
|
|
|
|
|
|
as HashRef, |
42
|
|
|
|
|
|
|
where { exists $_->{dsn} }, |
43
|
|
|
|
|
|
|
message { 'Does not look like a valid connect_info' }; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
coerce ConnectInfo, |
46
|
|
|
|
|
|
|
from Str, |
47
|
|
|
|
|
|
|
via(\&_coerce_connect_info_from_str), |
48
|
|
|
|
|
|
|
from ArrayRef, |
49
|
|
|
|
|
|
|
via(\&_coerce_connect_info_from_arrayref); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _coerce_connect_info_from_arrayref { |
53
|
|
|
|
|
|
|
my %connect_info; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# make a copy |
56
|
|
|
|
|
|
|
$_ = [ @$_ ]; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if (!ref $_->[0]) { # array style |
59
|
|
|
|
|
|
|
$connect_info{dsn} = shift @$_; |
60
|
|
|
|
|
|
|
$connect_info{user} = shift @$_ if !ref $_->[0]; |
61
|
|
|
|
|
|
|
$connect_info{password} = shift @$_ if !ref $_->[0]; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
for my $i (0..1) { |
64
|
|
|
|
|
|
|
my $extra = shift @$_; |
65
|
|
|
|
|
|
|
last unless $extra; |
66
|
|
|
|
|
|
|
die "invalid connect_info" unless reftype $extra eq 'HASH'; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
%connect_info = (%connect_info, %$extra); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
die "invalid connect_info" if @$_; |
72
|
|
|
|
|
|
|
} elsif (@$_ == 1 && reftype $_->[0] eq 'HASH') { |
73
|
|
|
|
|
|
|
return $_->[0]; |
74
|
|
|
|
|
|
|
} else { |
75
|
|
|
|
|
|
|
die "invalid connect_info"; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
for my $key (qw/user password/) { |
79
|
|
|
|
|
|
|
$connect_info{$key} = '' |
80
|
|
|
|
|
|
|
if not defined $connect_info{$key}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
\%connect_info; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _coerce_connect_info_from_str { |
87
|
|
|
|
|
|
|
+{ dsn => $_, user => '', password => '' } |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
subtype ReplicantsConnectInfo, |
92
|
|
|
|
|
|
|
as ArrayRef[ConnectInfo]; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
coerce ReplicantsConnectInfo, |
95
|
|
|
|
|
|
|
from Int, |
96
|
|
|
|
|
|
|
via { [map { +{dsn=>'', user=>'', password=>''} } (1..$_)] }, |
97
|
|
|
|
|
|
|
from ArrayRef[Str], |
98
|
|
|
|
|
|
|
via { |
99
|
|
|
|
|
|
|
[map { &_coerce_connect_info_from_str($_) } @$_]; |
100
|
|
|
|
|
|
|
}, |
101
|
|
|
|
|
|
|
from ArrayRef[ArrayRef], |
102
|
|
|
|
|
|
|
via { |
103
|
|
|
|
|
|
|
[map { &_coerce_connect_info_from_arrayref($_) } @$_]; |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Test::DBIx::Class::Types - Type Constraint Library |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L based type constraint library |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
John Napiorkowski C<< >> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Code gratuitously cargo culted from L |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Copyright 2009, John Napiorkowski C<< >> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
127
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|