X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema.pm;h=3c992ab33e89b1522ce355360600661b2240bad3;hb=a8c2c746a5bb98671cbe3a58f26cd115b7770cf9;hp=77a7fe7e511d1eba2d9e71b20309f1949c7879b1;hpb=c3e9f7189094e94137356251c4f0b1f1cbfeb04a;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 77a7fe7..3c992ab 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -898,6 +898,7 @@ sub compose_namespace { my $schema = $self->clone; { no warnings qw/redefine/; + no strict qw/refs/; # local *Class::C3::reinitialize = sub { }; foreach my $moniker ($schema->sources) { my $source = $schema->source($moniker); @@ -906,8 +907,14 @@ sub compose_namespace { $target_class => $source->result_class, ($base ? $base : ()) ); $source->result_class($target_class); - $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"}; + } $schema->register_source($moniker, $source); } }