From: Peter Rabbitson Date: Thu, 3 Sep 2009 09:11:50 +0000 (+0000) Subject: Storable sanification X-Git-Tag: v0.08111~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7cfda9a6b80a051ffd5b180c4d34b66eae0de38d;p=dbsrgits%2FDBIx-Class.git Storable sanification --- diff --git a/Changes b/Changes index 4a8e98e..c0f6226 100644 --- a/Changes +++ b/Changes @@ -5,9 +5,13 @@ Revision history for DBIx::Class - Fixed a complex prefetch + regular join regression introduced in 0.08108 - Fixed insert_bulk rebless handling + - Fixed Storable roundtrip regression, and general serialization + cleanup - SQLT related fixes: - sqlt_type is now called on the correct storage object - hooks can now see the correct producer_type + - optional SQLT requirements for e.g. deploy() bumped to 0.11002 + - Automatically detect MySQL v3 and use INNER JOIN instead of JOIN - POD improvements 0.08109 2009-08-18 08:35:00 (UTC) diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index eee5e3d..2162597 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -6,7 +6,6 @@ use warnings; use DBIx::Class::ResultSet; use DBIx::Class::ResultSourceHandle; use Carp::Clan qw/^DBIx::Class/; -use Storable; use base qw/DBIx::Class/; diff --git a/lib/DBIx/Class/ResultSourceHandle.pm b/lib/DBIx/Class/ResultSourceHandle.pm index 4a402e9..d7d0190 100644 --- a/lib/DBIx/Class/ResultSourceHandle.pm +++ b/lib/DBIx/Class/ResultSourceHandle.pm @@ -78,8 +78,9 @@ sub STORABLE_freeze { my $to_serialize = { %$self }; - my $class = $self->schema->class($self->source_moniker); - $to_serialize->{schema} = $class; + delete $to_serialize->{schema}; + $to_serialize->{_frozen_from_class} = $self->schema->class($self->source_moniker); + return (Storable::freeze($to_serialize)); } @@ -93,10 +94,10 @@ C<< $schema->thaw($ice) >> which handles this for you. sub STORABLE_thaw { - my ($self, $cloning,$ice) = @_; + my ($self, $cloning, $ice) = @_; %$self = %{ Storable::thaw($ice) }; - my $class = delete $self->{schema}; + my $class = delete $self->{_frozen_from_class}; if( $thaw_schema ) { $self->{schema} = $thaw_schema; } diff --git a/lib/DBIx/Class/Serialize/Storable.pm b/lib/DBIx/Class/Serialize/Storable.pm index d904c0b..d165862 100644 --- a/lib/DBIx/Class/Serialize/Storable.pm +++ b/lib/DBIx/Class/Serialize/Storable.pm @@ -7,9 +7,17 @@ sub STORABLE_freeze { my ($self, $cloning) = @_; my $to_serialize = { %$self }; + # The source is either derived from _source_handle or is + # reattached in the thaw handler below delete $to_serialize->{result_source}; - delete $to_serialize->{related_resultsets}; - delete $to_serialize->{_inflated_column}; + + # If the parser is cached there is a chance that the interpeter + # which receives the ice will not have the parser loaded + # A re-determination will force an implicit load + delete $to_serialize->{__datetime_parser}; + + # Dynamic values, easy to recalculate + delete $to_serialize->{$_} for qw/related_resultsets _inflated_column/; return (Storable::freeze($to_serialize)); } @@ -18,8 +26,10 @@ sub STORABLE_thaw { my ($self, $cloning, $serialized) = @_; %$self = %{ Storable::thaw($serialized) }; + + # if the handle went missing somehow, reattach $self->result_source($self->result_source_instance) - if $self->can('result_source_instance'); + if !$self->_source_handle && $self->can('result_source_instance'); } 1; diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index c3a8e49..a8390a7 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -2515,8 +2515,7 @@ See L sub build_datetime_parser { my $self = shift; my $type = $self->datetime_parser_type(@_); - eval "use ${type}"; - $self->throw_exception("Couldn't load ${type}: $@") if $@; + $self->ensure_class_loaded ($type); return $type; }