X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSourceHandle.pm;h=33204dfb6dea9d22787bd19eb6da3dd000c34fa9;hb=c6e27318d1a83b7474eaea616d47d478746609f2;hp=c1a50705cdbd8ee5f16dcb08221fd121976207b2;hpb=4146e3dae3771b13b83eb1ba124ba74287f83dcd;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSourceHandle.pm b/lib/DBIx/Class/ResultSourceHandle.pm index c1a5070..33204df 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/; @@ -19,7 +20,7 @@ our $thaw_schema; =head1 NAME -DBIx::Class::ResultSourceHandle +DBIx::Class::ResultSourceHandle - Decouple Rows/ResultSets objects from their Source objects =head1 DESCRIPTION @@ -76,8 +77,10 @@ sub STORABLE_freeze { my ($self, $cloning) = @_; my $to_serialize = { %$self }; - + delete $to_serialize->{schema}; + $to_serialize->{_frozen_from_class} = $self->schema->class($self->source_moniker); + return (Storable::freeze($to_serialize)); } @@ -85,15 +88,26 @@ sub STORABLE_freeze { 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. +C<< $schema->thaw($ice) >> which handles this for you. =cut sub STORABLE_thaw { - my ($self, $cloning,$ice) = @_; + my ($self, $cloning, $ice) = @_; %$self = %{ Storable::thaw($ice) }; - $self->{schema} = $thaw_schema; + + my $class = delete $self->{_frozen_from_class}; + 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. Look at 'freeze' and 'thaw' methods in DBIx::Class::Schema." + unless $self->{schema}; } =head1 AUTHOR