1 package DBIx::Class::Serialize::Storable;
7 my ($self, $cloning) = @_;
8 my $to_serialize = { %$self };
10 # The source is either derived from _source_handle or is
11 # reattached in the thaw handler below
12 delete $to_serialize->{result_source};
14 # If the parser is cached there is a chance that the interpeter
15 # which receives the ice will not have the parser loaded
16 # A re-determination will force an implicit load
17 delete $to_serialize->{__datetime_parser};
19 # Dynamic values, easy to recalculate
20 delete $to_serialize->{$_} for qw/related_resultsets _inflated_column/;
22 return (Storable::freeze($to_serialize));
26 my ($self, $cloning, $serialized) = @_;
28 %$self = %{ Storable::thaw($serialized) };
30 # if the handle went missing somehow, reattach
31 $self->result_source($self->result_source_instance)
32 if !$self->_source_handle && $self->can('result_source_instance');
41 DBIx::Class::Serialize::Storable - hooks for Storable freeze/thaw
45 # in a table class definition
46 __PACKAGE__->load_components(qw/Serialize::Storable/);
48 # meanwhile, in a nearby piece of code
49 my $cd = $schema->resultset('CD')->find(12);
50 # if the cache uses Storable, this will work automatically
51 $cache->set($cd->ID, $cd);
55 This component adds hooks for Storable so that row objects can be
56 serialized. It assumes that your row object class (C<result_class>) is
57 the same as your table class, which is the normal situation.
61 The following hooks are defined for L<Storable> - see the
62 documentation for L<Storable/Hooks> for detailed information on these
65 =head2 STORABLE_freeze
67 The serializing hook, called on the object during serialization. It
68 can be inherited, or defined in the class itself, like any other
73 The deserializing hook called on the object during deserialization.
77 David Kamholz <dkamholz@cpan.org>
81 You may distribute this code under the same terms as Perl itself.