X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSourceHandle.pm;h=7531954ad9c27ba784563caeeeb37bb667b3773f;hb=e8b32a6d045b4d04ba023d48be1c8e32065fcec6;hp=ae11ce6b148b49edd4eba525d58de63784050e21;hpb=5f94607105ef995064a59fe814d89a6d7e63eab5;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/ResultSourceHandle.pm b/lib/DBIx/Class/ResultSourceHandle.pm index ae11ce6..7531954 100644 --- a/lib/DBIx/Class/ResultSourceHandle.pm +++ b/lib/DBIx/Class/ResultSourceHandle.pm @@ -3,6 +3,7 @@ package DBIx::Class::ResultSourceHandle; use strict; use warnings; use Storable; +use Carp; use base qw/DBIx::Class/; @@ -14,9 +15,12 @@ use overload __PACKAGE__->mk_group_accessors('simple' => qw/schema source_moniker/); +# Schema to use when thawing. +our $thaw_schema; + =head1 NAME -DBIx::Class::ResultSourceHandle +DBIx::Class::ResultSourceHandle - Decouple Rows/ResultSets objects from their Source objects =head1 DESCRIPTION @@ -71,20 +75,43 @@ Freezes a handle. sub STORABLE_freeze { my ($self, $cloning) = @_; + my $to_serialize = { %$self }; - delete $to_serialize->{schema}; + + my $class = $self->schema->class($self->source_moniker); + $to_serialize->{schema} = $class; return (Storable::freeze($to_serialize)); } =head2 STORABLE_thaw -Thaws frozen handle. +Thaws frozen handle. Resets the internal schema reference to the package +variable C<$thaw_schema>. The recomened way of setting this is to use +C<< $schema->thaw($ice) >> which handles this for you. =cut + sub STORABLE_thaw { my ($self, $cloning,$ice) = @_; %$self = %{ Storable::thaw($ice) }; + + my $class = delete $self->{schema}; + if( $thaw_schema ) { + $self->{schema} = $thaw_schema; + } + else { + my $rs = $class->result_source_instance; + $self->{schema} = $rs->schema if $rs; + } + + carp "Unable to restore schema" unless $self->{schema}; } +=head1 AUTHOR + +Ash Berlin C<< >> + +=cut + 1;