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 | |
75d07914 |
24 | =head1 NAME |
19345968 |
25 | |
24d67825 |
26 | DBIx::Class::Serialize::Storable - hooks for Storable freeze/thaw |
19345968 |
27 | |
28 | =head1 SYNOPSIS |
29 | |
30 | # in a table class definition |
69ac22ee |
31 | __PACKAGE__->load_components(qw/Serialize::Storable/); |
9b83fccd |
32 | |
19345968 |
33 | # meanwhile, in a nearby piece of code |
24d67825 |
34 | my $cd = $schema->resultset('CD')->find(12); |
2053ab2a |
35 | # if the cache uses Storable, this will work automatically |
36 | $cache->set($cd->ID, $cd); |
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 |
2053ab2a |
42 | the same as your table class, which is the normal situation. |
19345968 |
43 | |
9b83fccd |
44 | =head1 HOOKS |
45 | |
46 | The following hooks are defined for L<Storable> - see the |
47 | documentation for L<Storable/Hooks> for detailed information on these |
48 | hooks. |
49 | |
50 | =head2 STORABLE_freeze |
51 | |
52 | The serializing hook, called on the object during serialization. It |
53 | can be inherited, or defined in the class itself, like any other |
54 | method. |
55 | |
56 | =head2 STORABLE_thaw |
57 | |
58 | The deserializing hook called on the object during deserialization. |
59 | |
19345968 |
60 | =head1 AUTHORS |
61 | |
62 | David Kamholz <dkamholz@cpan.org> |
63 | |
64 | =head1 LICENSE |
65 | |
66 | You may distribute this code under the same terms as Perl itself. |
67 | |
68 | =cut |