line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::EncodedColumn; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1553
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
50
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
6
|
use base qw/DBIx::Class/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
133
|
|
7
|
2
|
|
|
2
|
|
8
|
use Sub::Name; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
418
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata( '_column_encoders' ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.00013'; |
12
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub register_column { |
15
|
9
|
|
|
9
|
1
|
137948
|
my $self = shift; |
16
|
9
|
|
|
|
|
11
|
my ($column, $info) = @_; |
17
|
9
|
|
|
|
|
31
|
$self->next::method(@_); |
18
|
|
|
|
|
|
|
|
19
|
9
|
100
|
100
|
|
|
3787
|
return unless exists $info->{encode_column} && $info->{encode_column} == 1; |
20
|
7
|
50
|
33
|
|
|
35
|
$self->throw_exception("'encode_class' is a required argument.") |
21
|
|
|
|
|
|
|
unless exists $info->{encode_class} && defined $info->{encode_class}; |
22
|
7
|
|
|
|
|
9
|
my $class = $info->{encode_class}; |
23
|
|
|
|
|
|
|
|
24
|
7
|
100
|
|
|
|
15
|
my $args = exists $info->{encode_args} ? $info->{encode_args} : {}; |
25
|
7
|
50
|
|
|
|
17
|
$self->throw_exception("'encode_args' must be a hashref") |
26
|
|
|
|
|
|
|
unless ref $args eq 'HASH'; |
27
|
|
|
|
|
|
|
|
28
|
7
|
|
|
|
|
13
|
$class = join("::", 'DBIx::Class::EncodedColumn', $class); |
29
|
7
|
|
|
|
|
354
|
eval "require ${class};"; |
30
|
7
|
50
|
|
|
|
24
|
$self->throw_exception("Failed to use encode_class '${class}': $@") if $@; |
31
|
|
|
|
|
|
|
|
32
|
7
|
50
|
|
|
|
9
|
defined( my $encode_sub = eval{ $class->make_encode_sub($column, $args) }) || |
|
7
|
|
|
|
|
27
|
|
33
|
|
|
|
|
|
|
$self->throw_exception("Failed to create encoder with class '$class': $@"); |
34
|
7
|
100
|
|
|
|
9
|
$self->_column_encoders({$column => $encode_sub, %{$self->_column_encoders || {}}}); |
|
7
|
|
|
|
|
176
|
|
35
|
|
|
|
|
|
|
|
36
|
7
|
100
|
66
|
|
|
712
|
if ( exists $info->{encode_check_method} && $info->{encode_check_method} ){ |
37
|
2
|
|
|
2
|
|
14
|
no strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
545
|
|
38
|
5
|
50
|
|
|
|
6
|
defined( my $check_sub = eval{ $class->make_check_sub($column, $args) }) || |
|
5
|
|
|
|
|
14
|
|
39
|
|
|
|
|
|
|
$self->throw_exception("Failed to create checker with class '$class': $@"); |
40
|
5
|
|
|
|
|
151
|
my $name = join '::', $self->result_class, $info->{encode_check_method}; |
41
|
5
|
|
|
|
|
1228
|
*$name = subname $name, $check_sub; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub set_column { |
46
|
7
|
|
|
7
|
1
|
20913
|
my $self = shift; |
47
|
7
|
100
|
|
|
|
28
|
return $self->next::method(@_) unless defined $_[1]; |
48
|
6
|
|
|
|
|
164
|
my $encs = $self->_column_encoders; |
49
|
6
|
100
|
66
|
|
|
150
|
if(exists $encs->{$_[0]} && defined(my $encoder = $encs->{$_[0]})){ |
50
|
5
|
|
|
|
|
18
|
return $self->next::method($_[0], $encoder->($_[1])); |
51
|
|
|
|
|
|
|
} |
52
|
1
|
|
|
|
|
5
|
$self->next::method(@_); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
56
|
2
|
|
|
2
|
1
|
161724
|
my($self, $attr, @rest) = @_; |
57
|
2
|
|
|
|
|
76
|
my $encoders = $self->_column_encoders; |
58
|
2
|
|
|
|
|
80
|
for my $col (grep { defined $encoders->{$_} } keys %$encoders ) { |
|
10
|
|
|
|
|
23
|
|
59
|
10
|
50
|
33
|
|
|
63
|
next unless exists $attr->{$col} && defined $attr->{$col}; |
60
|
10
|
|
|
|
|
41
|
$attr->{$col} = $encoders->{$col}->( $attr->{$col} ); |
61
|
|
|
|
|
|
|
} |
62
|
2
|
|
|
|
|
15
|
return $self->next::method($attr, @rest); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__; |