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