Deprecate DBIx::Class::Serialize::Storable (all functionality is in ResultSourceHandle)
[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 use Carp::Clan qw/^DBIx::Class/;
7
8 carp 'The Serialize::Storable component is now *DEPRECATED*. It has not '
9     .'been providing any useful functionality for quite a while, and in fact '
10     .'destroys prefetched results in its current implementation. Do not use!';
11
12
13 sub STORABLE_freeze {
14     my ($self, $cloning) = @_;
15     my $to_serialize = { %$self };
16
17     # The source is either derived from _source_handle or is
18     # reattached in the thaw handler below
19     delete $to_serialize->{result_source};
20
21     # Dynamic values, easy to recalculate
22     delete $to_serialize->{$_} for qw/related_resultsets _inflated_column/;
23
24     return (Storable::nfreeze($to_serialize));
25 }
26
27 sub STORABLE_thaw {
28     my ($self, $cloning, $serialized) = @_;
29
30     %$self = %{ Storable::thaw($serialized) };
31
32     # if the handle went missing somehow, reattach
33     $self->result_source($self->result_source_instance)
34       if !$self->_source_handle && $self->can('result_source_instance');
35 }
36
37 1;
38
39 __END__
40
41 =head1 NAME
42
43     DBIx::Class::Serialize::Storable - hooks for Storable nfreeze/thaw
44
45 =head1 DEPRECATION NOTE
46
47 This component is now B<DEPRECATED>. It has not been providing any useful
48 functionality for quite a while, and in fact destroys prefetched results
49 in its current implementation. Do not use!
50
51 =head1 SYNOPSIS
52
53     # in a table class definition
54     __PACKAGE__->load_components(qw/Serialize::Storable/);
55
56     # meanwhile, in a nearby piece of code
57     my $cd = $schema->resultset('CD')->find(12);
58     # if the cache uses Storable, this will work automatically
59     $cache->set($cd->ID, $cd);
60
61 =head1 DESCRIPTION
62
63 This component adds hooks for Storable so that row objects can be
64 serialized. It assumes that your row object class (C<result_class>) is
65 the same as your table class, which is the normal situation.
66
67 =head1 HOOKS
68
69 The following hooks are defined for L<Storable> - see the
70 documentation for L<Storable/Hooks> for detailed information on these
71 hooks.
72
73 =head2 STORABLE_freeze
74
75 The serializing hook, called on the object during serialization. It
76 can be inherited, or defined in the class itself, like any other
77 method.
78
79 =head2 STORABLE_thaw
80
81 The deserializing hook called on the object during deserialization.
82
83 =head1 AUTHORS
84
85 David Kamholz <dkamholz@cpan.org>
86
87 =head1 LICENSE
88
89 You may distribute this code under the same terms as Perl itself.
90
91 =cut