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