Commit | Line | Data |
69ac22ee |
1 | package DBIx::Class::Serialize::Storable; |
ed28f830 |
2 | use strict; |
69ac22ee |
3 | use Storable; |
ed28f830 |
4 | |
5 | sub STORABLE_freeze { |
6 | my ($self,$cloning) = @_; |
ed28f830 |
7 | my $to_serialize = { %$self }; |
8 | delete $to_serialize->{result_source}; |
69ac22ee |
9 | return (Storable::freeze($to_serialize)); |
ed28f830 |
10 | } |
11 | |
12 | sub STORABLE_thaw { |
13 | my ($self,$cloning,$serialized) = @_; |
69ac22ee |
14 | %$self = %{ Storable::thaw($serialized) }; |
24d67825 |
15 | $self->result_source($self->result_source_instance) |
16 | if $self->can('result_source_instance'); |
ed28f830 |
17 | } |
18 | |
19345968 |
19 | 1; |
20 | |
21 | __END__ |
22 | |
23 | =head1 NAME |
24 | |
24d67825 |
25 | DBIx::Class::Serialize::Storable - hooks for Storable freeze/thaw |
26 | (EXPERIMENTAL) |
19345968 |
27 | |
28 | =head1 SYNOPSIS |
29 | |
30 | # in a table class definition |
69ac22ee |
31 | __PACKAGE__->load_components(qw/Serialize::Storable/); |
19345968 |
32 | |
33 | # meanwhile, in a nearby piece of code |
24d67825 |
34 | my $cd = $schema->resultset('CD')->find(12); |
35 | $cache->set($cd->ID, $cd); # if the cache uses Storable, this |
36 | # will work automatically |
19345968 |
37 | |
38 | =head1 DESCRIPTION |
39 | |
24d67825 |
40 | This component adds hooks for Storable so that row objects can be |
41 | serialized. It assumes that your row object class (C<result_class>) is |
42 | the same as your table class, which is the normal situation. However, |
43 | this code is not yet well tested, and so should be considered |
44 | experimental. |
19345968 |
45 | |
46 | =head1 AUTHORS |
47 | |
48 | David Kamholz <dkamholz@cpan.org> |
49 | |
50 | =head1 LICENSE |
51 | |
52 | You may distribute this code under the same terms as Perl itself. |
53 | |
54 | =cut |