line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::InflateColumn::ClassTypeEnum; |
2
|
|
|
|
|
|
|
# ABSTRACT: Inflate enum-like columns to your Class::Type::Enum classes |
3
|
|
|
|
|
|
|
$DBIx::Class::InflateColumn::ClassTypeEnum::VERSION = '0.013'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1397
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
305
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub register_column { |
13
|
0
|
|
|
0
|
1
|
|
my ($self, $column, $info) = @_; |
14
|
0
|
|
|
|
|
|
$self->next::method($column, $info); |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
0
|
|
|
|
return unless $info->{extra} and my $class = $info->{extra}{enum_class}; |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
unless (eval { $class->isa('Class::Type::Enum') }) { |
|
0
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
Carp::croak "enum_class $class is not loaded or doesn't inherit from Class::Type::Enum"; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# I'd love to DTRT based on the column type but I think they're practically |
23
|
|
|
|
|
|
|
# freeform in DBIC and just match the DB types, so that's a lot of |
24
|
|
|
|
|
|
|
# possibilities... |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
if ($info->{extra}{enum_ordinal_storage}) { |
27
|
|
|
|
|
|
|
$self->inflate_column( |
28
|
|
|
|
|
|
|
$column => { |
29
|
|
|
|
|
|
|
inflate => sub { |
30
|
0
|
|
|
0
|
|
|
my ($ord) = @_; |
31
|
0
|
0
|
|
|
|
|
return unless defined $ord; |
32
|
0
|
|
|
|
|
|
$class->inflate_ordinal($ord); |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
deflate => sub { |
35
|
0
|
|
|
0
|
|
|
my ($enum) = @_; |
36
|
0
|
0
|
|
|
|
|
return unless defined $enum; |
37
|
0
|
|
|
|
|
|
$enum->numify; |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
|
|
|
|
|
|
$self->inflate_column( |
45
|
|
|
|
|
|
|
$column => { |
46
|
|
|
|
|
|
|
inflate => sub { |
47
|
0
|
|
|
0
|
|
|
my ($val) = @_; |
48
|
0
|
0
|
|
|
|
|
return unless defined $val; |
49
|
0
|
|
|
|
|
|
$class->inflate_symbol($val); |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
deflate => sub { |
52
|
0
|
|
|
0
|
|
|
my ($enum) = @_; |
53
|
0
|
0
|
|
|
|
|
return unless defined $enum; |
54
|
0
|
|
|
|
|
|
$enum->stringify; |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |