[Dbix-class] Question on change from .08123 => .08124

Bill Moseley moseley at hank.org
Thu Dec 30 01:15:42 GMT 2010


In DBIx::Class::Schema there was this change from .08123 to .08124:

-      $target_class->result_source_instance($source)
-        if $target_class->can('result_source_instance');
+      if ($target_class->can('result_source_instance')) {
+
+        # since the newly created classes are registered only with
+        # the instance of $schema, it should be safe to weaken
+        # the ref (it will GC when $schema is destroyed)
+        $target_class->result_source_instance($source);
+        weaken ${"${target_class}::__cag_result_source_instance"};
+      }

With that weaken I started getting warnings when thawing using Storable's
thaw (not using $schema->thaw) because schema was not found.  The issue is
this bit of code in DBIx::Class::ResultSourceHandle:

 sub STORABLE_thaw {
    my ($self, $cloning, $ice) =3D @_;
    %$self =3D %{ Storable::thaw($ice) };

    my $class =3D delete $self->{_frozen_from_class};
    if( $thaw_schema ) {
        $self->{schema} =3D $thaw_schema;
    }
    else {
        *my $rs =3D $class->result_source_instance;*
*        $self->{schema} =3D $rs->schema if $rs;*
    }

    carp "Unable to restore schema. Look at 'freeze' and 'thaw' methods in
DBIx::Class::Schema."
        unless $self->{schema};
}


With .08124 $rs is true above, but $rs->schema is undefined with the weaken.
 With .08124 (without the weaken) $rs->schema returns a schema object.

Is that expected?

To be honest, I'm surprised that thawing directly with Storable was working
before because I was not calling $schema->thaw or
setting $DBIx::Class::ResultSourceHandle::thaw_schema =3D $schema. (The DBIx
object was part of a larger structure saved in Memcached.) So, I'm not clear
if it was just lucky that it was working before or if this is an unintended
side-effect from adding that weaken.



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20101229/08b=
89ad1/attachment.htm


More information about the DBIx-Class mailing list