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