X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSourceHandle.pm;h=935431820682c785797cc668360e068ef178558f;hb=96eab6f8adc4e23f4212aa6b6bf681137aa5f654;hp=2621610030e07d102b29218671236606b04272c2;hpb=aec3eff1a3bba3ee46eaadabf496e9a369b8638a;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSourceHandle.pm b/lib/DBIx/Class/ResultSourceHandle.pm index 2621610..9354318 100644 --- a/lib/DBIx/Class/ResultSourceHandle.pm +++ b/lib/DBIx/Class/ResultSourceHandle.pm @@ -3,14 +3,20 @@ package DBIx::Class::ResultSourceHandle; use strict; use warnings; use Storable; +use Carp; use base qw/DBIx::Class/; use overload - q/""/ => sub { __PACKAGE__ . ":" . shift->source_monkier; }, + # 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_monkier/); +__PACKAGE__->mk_group_accessors('simple' => qw/schema source_moniker/); + +# Schema to use when thawing. +our $thaw_schema; =head1 NAME @@ -35,7 +41,7 @@ stringify to almost nothing =item * -Closer to being aboe to do a Serialize::Storable that doesn't require class-based connections +Closer to being able to do a Serialize::Storable that doesn't require class-based connections =back @@ -55,22 +61,57 @@ sub new { =head2 resolve -Resolve the monkier into the actual ResultSource object +Resolve the moniker into the actual ResultSource object =cut -sub resolve { return $_[0]->schema->source($_[0]->source_monkier) } +sub resolve { return $_[0]->schema->source($_[0]->source_moniker) } + +=head2 STORABLE_freeze + +Freezes a handle. + +=cut 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. 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;