line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::Helper::Row::Types; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Use Types to define rows |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
485556
|
use v5.14; |
|
1
|
|
|
|
|
11
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Ref::Util (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
9
|
1
|
|
|
1
|
|
386
|
use Safe::Isa 1.000008 qw/ $_isa $_can $_call_if_can /; |
|
1
|
|
|
|
|
426
|
|
|
1
|
|
|
|
|
128
|
|
10
|
1
|
|
|
1
|
|
411
|
use Types::SQL::Util v0.3.0 (); |
|
1
|
|
|
|
|
1109
|
|
|
1
|
|
|
|
|
344
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# RECOMMEND PREREQ: Ref::Util::XS |
13
|
|
|
|
|
|
|
# RECOMMEND PREREQ: Type::Tiny::XS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 'v0.4.0'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub add_columns { |
20
|
1
|
|
|
1
|
1
|
3060
|
my ( $self, @args ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
3
|
my @cols = map { $self->_apply_types_to_column_defition($_) } @args; |
|
8
|
|
|
|
|
19
|
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
6
|
$self->next::method(@cols); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _apply_types_to_column_defition { |
28
|
8
|
|
|
8
|
|
16
|
my ( $self, $column_info ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
8
|
100
|
|
|
|
22
|
return $column_info unless Ref::Util::is_ref $column_info; |
31
|
|
|
|
|
|
|
|
32
|
4
|
100
|
|
|
|
10
|
$column_info = { isa => $column_info } |
33
|
|
|
|
|
|
|
if $column_info->$_isa('Type::Tiny'); |
34
|
|
|
|
|
|
|
|
35
|
4
|
50
|
|
|
|
57
|
my $type = $column_info->{isa} or return $column_info; |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
26
|
my %info = Types::SQL::Util::column_info_from_type($type); |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
448
|
@info{ keys %$column_info } = values %$column_info; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
50
|
|
|
23
|
$info{extra} ||= {}; |
42
|
4
|
|
|
|
|
10
|
$info{extra}{type} = {}; |
43
|
4
|
|
|
|
|
18
|
$info{extra}{type}{$_} = delete $info{$_} for qw/ isa strict coerce /; |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
|
|
13
|
return \%info; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub set_column { |
50
|
4
|
|
|
4
|
1
|
528848
|
my ($self, $column, $new_value) = @_; |
51
|
|
|
|
|
|
|
|
52
|
4
|
50
|
|
|
|
17
|
if (my $info = $self->result_source->column_info($column)) { |
53
|
|
|
|
|
|
|
|
54
|
4
|
50
|
|
|
|
99
|
if (my $type_info = $info->{extra}{type}) { |
55
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
8
|
my $type = $type_info->{isa}; |
57
|
|
|
|
|
|
|
|
58
|
4
|
100
|
66
|
|
|
23
|
if ($type_info->{coerce} && $type->$_can('coerce')) { |
59
|
1
|
|
|
|
|
28
|
$new_value = $type->coerce($new_value); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$type->$_call_if_can( assert_valid => $new_value ) |
63
|
4
|
50
|
|
|
|
1341
|
if $type_info->{strict}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
2
|
|
|
|
|
164
|
return $self->next::method( $column => $new_value ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |