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