A couple of typos, and general whitespace cleanup (ick)
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSourceHandle.pm
index c1a5070..4a402e9 100644 (file)
@@ -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,9 @@ 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));
 }
 
@@ -85,7 +87,7 @@ 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
 
@@ -93,7 +95,17 @@ C<$schema->thaw($ice)> which handles this for you.
 sub STORABLE_thaw {
     my ($self, $cloning,$ice) = @_;
     %$self = %{ Storable::thaw($ice) };
-    $self->{schema} = $thaw_schema;
+
+    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