File Coverage

blib/lib/DBIx/Class/Serialize/Storable.pm
Criterion Covered Total %
statement 15 22 68.1
branch n/a
condition n/a
subroutine 5 7 71.4
pod 2 2 100.0
total 22 31 70.9


line stmt bran cond sub pod time code
1             package DBIx::Class::Serialize::Storable;
2 2     2   1360 use strict;
  2         5  
  2         48  
3 2     2   10 use warnings;
  2         3  
  2         37  
4              
5 2     2   26 use Storable();
  2         4  
  2         39  
6 2     2   9 use DBIx::Class::Carp;
  2         4  
  2         13  
7 2     2   10 use namespace::clean;
  2         10  
  2         12  
8              
9             carp 'The Serialize::Storable component is now *DEPRECATED*. It has not '
10             .'been providing any useful functionality for quite a while, and in fact '
11             .'destroys prefetched results in its current implementation. Do not use!';
12              
13              
14             sub STORABLE_freeze {
15 0     0 1   my ($self, $cloning) = @_;
16 0           my $to_serialize = { %$self };
17              
18             # Dynamic values, easy to recalculate
19 0           delete $to_serialize->{$_} for qw/related_resultsets _inflated_column/;
20              
21 0           return (Storable::nfreeze($to_serialize));
22             }
23              
24             sub STORABLE_thaw {
25 0     0 1   my ($self, $cloning, $serialized) = @_;
26              
27 0           %$self = %{ Storable::thaw($serialized) };
  0            
28             }
29              
30             1;
31              
32             __END__
33              
34             =head1 NAME
35              
36             DBIx::Class::Serialize::Storable - hooks for Storable nfreeze/thaw
37              
38             =head1 DEPRECATION NOTE
39              
40             This component is now B<DEPRECATED>. It has not been providing any useful
41             functionality for quite a while, and in fact destroys prefetched results
42             in its current implementation. Do not use!
43              
44             =head1 SYNOPSIS
45              
46             # in a table class definition
47             __PACKAGE__->load_components(qw/Serialize::Storable/);
48              
49             # meanwhile, in a nearby piece of code
50             my $cd = $schema->resultset('CD')->find(12);
51             # if the cache uses Storable, this will work automatically
52             $cache->set($cd->ID, $cd);
53              
54             =head1 DESCRIPTION
55              
56             This component adds hooks for Storable so that result objects can be
57             serialized. It assumes that your result object class (C<result_class>) is
58             the same as your table class, which is the normal situation.
59              
60             =head1 HOOKS
61              
62             The following hooks are defined for L<Storable> - see the
63             documentation for L<Storable/Hooks> for detailed information on these
64             hooks.
65              
66             =head2 STORABLE_freeze
67              
68             The serializing hook, called on the object during serialization. It
69             can be inherited, or defined in the class itself, like any other
70             method.
71              
72             =head2 STORABLE_thaw
73              
74             The deserializing hook called on the object during deserialization.
75              
76             =head1 FURTHER QUESTIONS?
77              
78             Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
83             by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
84             redistribute it and/or modify it under the same terms as the
85             L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.