X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSourceHandle.pm;h=d7d0190a45cccfee57f2208eac4c57e02fdb1467;hb=7cfda9a6b80a051ffd5b180c4d34b66eae0de38d;hp=e6ad2034a1ae4211855d7c4594f6a57e5fe380e2;hpb=7137528d41287502d7d39c24ef1032f73e288297;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSourceHandle.pm b/lib/DBIx/Class/ResultSourceHandle.pm index e6ad203..d7d0190 100644 --- a/lib/DBIx/Class/ResultSourceHandle.pm +++ b/lib/DBIx/Class/ResultSourceHandle.pm @@ -3,18 +3,24 @@ package DBIx::Class::ResultSourceHandle; use strict; use warnings; use Storable; +use Carp; use base qw/DBIx::Class/; use overload + # on some RH perls the following line causes serious performance problem + # see https://bugzilla.redhat.com/show_bug.cgi?id=196836 q/""/ => sub { __PACKAGE__ . ":" . shift->source_moniker; }, fallback => 1; __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 @@ -69,20 +75,44 @@ Freezes a handle. 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)); } =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) = @_; + my ($self, $cloning, $ice) = @_; %$self = %{ Storable::thaw($ice) }; + + 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" unless $self->{schema}; } +=head1 AUTHOR + +Ash Berlin C<< >> + +=cut + 1;