Merge 'trunk' into 'cdbicompat_integration'
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Serialize / Storable.pm
CommitLineData
69ac22ee 1package DBIx::Class::Serialize::Storable;
ed28f830 2use strict;
bf5ecff9 3use warnings;
69ac22ee 4use Storable;
ed28f830 5
6sub STORABLE_freeze {
e60dc79f 7 my ($self, $cloning) = @_;
ed28f830 8 my $to_serialize = { %$self };
e60dc79f 9
ed28f830 10 delete $to_serialize->{result_source};
e60dc79f 11 delete $to_serialize->{related_resultsets};
12 delete $to_serialize->{_inflated_column};
13
14 return('', $to_serialize);
ed28f830 15}
16
17sub STORABLE_thaw {
e60dc79f 18 my ($self, $cloning, $junk, $obj) = @_;
19
20 %$self = %{ $obj };
24d67825 21 $self->result_source($self->result_source_instance)
22 if $self->can('result_source_instance');
ed28f830 23}
24
19345968 251;
26
27__END__
28
75d07914 29=head1 NAME
19345968 30
24d67825 31 DBIx::Class::Serialize::Storable - hooks for Storable freeze/thaw
19345968 32
33=head1 SYNOPSIS
34
35 # in a table class definition
69ac22ee 36 __PACKAGE__->load_components(qw/Serialize::Storable/);
9b83fccd 37
19345968 38 # meanwhile, in a nearby piece of code
24d67825 39 my $cd = $schema->resultset('CD')->find(12);
2053ab2a 40 # if the cache uses Storable, this will work automatically
41 $cache->set($cd->ID, $cd);
19345968 42
43=head1 DESCRIPTION
44
24d67825 45This component adds hooks for Storable so that row objects can be
46serialized. It assumes that your row object class (C<result_class>) is
2053ab2a 47the same as your table class, which is the normal situation.
19345968 48
9b83fccd 49=head1 HOOKS
50
51The following hooks are defined for L<Storable> - see the
52documentation for L<Storable/Hooks> for detailed information on these
53hooks.
54
55=head2 STORABLE_freeze
56
57The serializing hook, called on the object during serialization. It
58can be inherited, or defined in the class itself, like any other
59method.
60
61=head2 STORABLE_thaw
62
63The deserializing hook called on the object during deserialization.
64
19345968 65=head1 AUTHORS
66
67David Kamholz <dkamholz@cpan.org>
68
69=head1 LICENSE
70
71You may distribute this code under the same terms as Perl itself.
72
73=cut