From: Peter Rabbitson Date: Tue, 8 Mar 2011 12:58:38 +0000 (+0100) Subject: Make sure the component_class autoloader works across module reloads X-Git-Tag: v0.08191~68 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0d37421493c1fa1b599e0a1c6d71dd9478d839f6;p=dbsrgits%2FDBIx-Class.git Make sure the component_class autoloader works across module reloads (works around corner cases from db29433c) --- diff --git a/lib/DBIx/Class/AccessorGroup.pm b/lib/DBIx/Class/AccessorGroup.pm index bd245e3..2b0462b 100644 --- a/lib/DBIx/Class/AccessorGroup.pm +++ b/lib/DBIx/Class/AccessorGroup.pm @@ -4,15 +4,24 @@ use strict; use warnings; use base qw/Class::Accessor::Grouped/; +use Scalar::Util qw/weaken/; +use namespace::clean; -our %successfully_loaded_components; +my $successfully_loaded_components; sub get_component_class { my $class = $_[0]->get_inherited($_[1]); - if (defined $class and ! $successfully_loaded_components{$class}) { + + if (defined $class and ! $successfully_loaded_components->{$class} ) { $_[0]->ensure_class_loaded($class); - $successfully_loaded_components{$class}++; # only increment if the load succeeded + + no strict 'refs'; + $successfully_loaded_components->{$class} + = ${"${class}::__LOADED__BY__DBIC__CAG__COMPONENT_CLASS__"} + = do { \(my $anon = 'loaded') }; + weaken($successfully_loaded_components->{$class}); } + $class; }; diff --git a/lib/DBIx/Class/Optional/Dependencies.pm b/lib/DBIx/Class/Optional/Dependencies.pm index d946fc1..6f7c10d 100644 --- a/lib/DBIx/Class/Optional/Dependencies.pm +++ b/lib/DBIx/Class/Optional/Dependencies.pm @@ -132,6 +132,12 @@ my $reqs = { req => $id_shortener, }, + test_component_accessor => { + req => { + 'Class::Unload' => '0.07', + }, + }, + test_pod => { req => { 'Test::Pod' => '1.41', diff --git a/t/storage/cursor.t b/t/storage/cursor.t index fb5f0cc..e6c0ba7 100644 --- a/t/storage/cursor.t +++ b/t/storage/cursor.t @@ -13,4 +13,15 @@ lives_ok { is($schema->resultset("Artist")->search(), 3, "Three artists returned"); } 'Custom cursor autoloaded'; +SKIP: { + eval { require Class::Unload } + or skip 'component_class reentrancy test requires Class::Unload', 1; + + Class::Unload->unload('DBICTest::Cursor'); + + lives_ok { + is($schema->resultset("Artist")->search(), 3, "Three artists still returned"); + } 'Custom cursor auto re-loaded'; +} + done_testing;