line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::InflateColumn::Serializer::Hstore; |
2
|
1
|
|
|
1
|
|
551
|
use 5.008005; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
40
|
|
5
|
1
|
|
|
1
|
|
471
|
use Pg::hstore; |
|
1
|
|
|
|
|
538
|
|
|
1
|
|
|
|
|
155
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub get_freezer { |
10
|
0
|
|
|
0
|
1
|
|
my ( $class, $column, $info, $args ) = @_; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
0
|
|
|
return sub { Pg::hstore::encode($_[0]) }; |
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub get_unfreezer { |
16
|
0
|
|
|
0
|
1
|
|
my ( $class, $column, $info, $args ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
|
|
return sub { Pg::hstore::decode($_[0]) }; |
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
1; |
22
|
|
|
|
|
|
|
__END__ |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=encoding utf-8 |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
DBIx::Class::InflateColumn::Serializer::Hstore - Hstore Inflator |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
package MySchema::Table; |
33
|
|
|
|
|
|
|
use base 'DBIx::Class'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__PACKAGE__->load_components('InflateColumn::Serializer', 'Core'); |
36
|
|
|
|
|
|
|
__PACKAGE__->add_columns( |
37
|
|
|
|
|
|
|
'data_column' => { |
38
|
|
|
|
|
|
|
'data_type' => 'VARCHAR', |
39
|
|
|
|
|
|
|
'size' => 255, |
40
|
|
|
|
|
|
|
'serializer_class' => 'Hstore', |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Then in your code... |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $struct = { 'I' => { 'am' => 'a struct' }; |
47
|
|
|
|
|
|
|
$obj->data_column($struct); |
48
|
|
|
|
|
|
|
$obj->update; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
And you can recover your data structure with: |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $obj = ...->find(...); |
53
|
|
|
|
|
|
|
my $struct = $obj->data_column; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
The data structures you assign to "data_column" will be saved in the database in Hstore format. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=over 4 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item get_freezer |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Called by DBIx::Class::InflateColumn::Serializer to get the routine that serializes |
62
|
|
|
|
|
|
|
the data passed to it. Returns a coderef. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item get_unfreezer |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Called by DBIx::Class::InflateColumn::Serializer to get the routine that deserializes |
67
|
|
|
|
|
|
|
the data stored in the column. Returns a coderef. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=back |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Jeen Lee |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SEE ALSO |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
L<DBIx::Class::InflateColumn::Serializer> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L<Pg::hstore> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 LICENSE |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |