45a82858122f6e37e93f64e2b8854c84e40944e0
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Serialize / Storable.pm
1 package DBIx::Class::Serialize::Storable;
2 use strict;
3 use warnings;
4 use Storable;
5
6 sub STORABLE_freeze {
7     my ($self,$cloning) = @_;
8     my $to_serialize = { %$self };
9     delete $to_serialize->{result_source};
10     return (Storable::freeze($to_serialize));
11 }
12
13 sub STORABLE_thaw {
14     my ($self,$cloning,$serialized) = @_;
15     %$self = %{ Storable::thaw($serialized) };
16     $self->result_source($self->result_source_instance)
17       if $self->can('result_source_instance');
18 }
19
20 1;
21
22 __END__
23
24 =head1 NAME 
25
26     DBIx::Class::Serialize::Storable - hooks for Storable freeze/thaw
27
28 =head1 SYNOPSIS
29
30     # in a table class definition
31     __PACKAGE__->load_components(qw/Serialize::Storable/);
32     
33     # meanwhile, in a nearby piece of code
34     my $cd = $schema->resultset('CD')->find(12);
35     # if the cache uses Storable, this will work automatically
36     $cache->set($cd->ID, $cd);
37
38 =head1 DESCRIPTION
39
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.
43
44 =head1 AUTHORS
45
46 David Kamholz <dkamholz@cpan.org>
47
48 =head1 LICENSE
49
50 You may distribute this code under the same terms as Perl itself.
51
52 =cut