| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
253112
|
use 5.008001; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
34
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
49
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Types::DBI; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
|
8
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
216543
|
use DBI (); |
|
|
1
|
|
|
|
|
44466
|
|
|
|
1
|
|
|
|
|
50
|
|
|
11
|
1
|
|
|
1
|
|
1110
|
use Type::Library -base; |
|
|
1
|
|
|
|
|
20562
|
|
|
|
1
|
|
|
|
|
10
|
|
|
12
|
1
|
|
|
1
|
|
1303
|
use Types::Standard qw( InstanceOf ArrayRef Str ); |
|
|
1
|
|
|
|
|
46019
|
|
|
|
1
|
|
|
|
|
17
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT = 'Dbh'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $meta = __PACKAGE__->meta; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $dbh = $meta->add_type( |
|
19
|
|
|
|
|
|
|
name => 'Dbh', |
|
20
|
|
|
|
|
|
|
parent => InstanceOf['DBI::db'], |
|
21
|
|
|
|
|
|
|
constraint_generator => sub { |
|
22
|
|
|
|
|
|
|
my @allowed = @_; |
|
23
|
|
|
|
|
|
|
return sub { |
|
24
|
|
|
|
|
|
|
my $type = $_->get_info(17); |
|
25
|
|
|
|
|
|
|
!!grep($_ eq $type, @allowed); |
|
26
|
|
|
|
|
|
|
}; |
|
27
|
|
|
|
|
|
|
}, |
|
28
|
|
|
|
|
|
|
coercion_generator => sub { |
|
29
|
|
|
|
|
|
|
my $parent = shift; |
|
30
|
|
|
|
|
|
|
my $child = shift; |
|
31
|
|
|
|
|
|
|
my @allowed = @_; |
|
32
|
|
|
|
|
|
|
'Type::Coercion'->new( |
|
33
|
|
|
|
|
|
|
type_constraint => $child, |
|
34
|
|
|
|
|
|
|
type_coercion_map => [@{ $parent->coercion->type_coercion_map }], |
|
35
|
|
|
|
|
|
|
)->freeze; |
|
36
|
|
|
|
|
|
|
}, |
|
37
|
|
|
|
|
|
|
inline_generator => sub { |
|
38
|
|
|
|
|
|
|
my @allowed = @_; |
|
39
|
|
|
|
|
|
|
return sub { |
|
40
|
|
|
|
|
|
|
return ( |
|
41
|
|
|
|
|
|
|
undef, |
|
42
|
|
|
|
|
|
|
sprintf( |
|
43
|
|
|
|
|
|
|
'%s->get_info(17) eq %s', |
|
44
|
|
|
|
|
|
|
$_[1], |
|
45
|
|
|
|
|
|
|
B::perlstring($allowed[0]), |
|
46
|
|
|
|
|
|
|
), |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
} if @allowed == 1; |
|
49
|
|
|
|
|
|
|
return sub { |
|
50
|
|
|
|
|
|
|
return ( |
|
51
|
|
|
|
|
|
|
undef, |
|
52
|
|
|
|
|
|
|
sprintf( |
|
53
|
|
|
|
|
|
|
'do { my $t = %s->get_info(17); %s }', |
|
54
|
|
|
|
|
|
|
$_[1], |
|
55
|
|
|
|
|
|
|
join(' or ', map { my $x = B::perlstring($_); "\$t eq $x" } @allowed), |
|
56
|
|
|
|
|
|
|
), |
|
57
|
|
|
|
|
|
|
); |
|
58
|
|
|
|
|
|
|
}; |
|
59
|
|
|
|
|
|
|
}, |
|
60
|
|
|
|
|
|
|
); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $sth = $meta->add_type( |
|
63
|
|
|
|
|
|
|
name => 'Sth', |
|
64
|
|
|
|
|
|
|
parent => InstanceOf['DBI::st'], |
|
65
|
|
|
|
|
|
|
); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$dbh->coercion->add_type_coercions( |
|
68
|
|
|
|
|
|
|
Str ,=> q{ 'DBI'->connect($_, '', '', { RaiseError => 1 }) }, |
|
69
|
|
|
|
|
|
|
ArrayRef ,=> q{ 'DBI'->connect(@$_) }, |
|
70
|
|
|
|
|
|
|
); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$_->coercion->freeze for $dbh, $sth; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |