From: Dave Rolsky Date: Fri, 8 May 2009 02:42:39 +0000 (-0500) Subject: when checking @ISA to see if a class is loaded, make sure it actually has values... X-Git-Tag: 0.84~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d9d8a21bcb3f199ef18e4e46e4438189cc0574f7;p=gitmo%2FClass-MOP.git when checking @ISA to see if a class is loaded, make sure it actually has values in it --- diff --git a/Changes b/Changes index 73828c5..74b5362 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,10 @@ Revision history for Perl extension Class-MOP. * Class::MOP + - Made is_class_loaded a little stricter. It was reporting that + a class was loaded if it merely had an @ISA variable in its + stash. Now it checks that the @ISA var has elements in it. + * Class::MOP - Deprecate in_global_destruction and subname re-exporting (perigrin & Sartak) * Class::MOP::Class diff --git a/t/083_load_class.t b/t/083_load_class.t index 22a10af..0b5a0e3 100644 --- a/t/083_load_class.t +++ b/t/083_load_class.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 34; +use Test::More tests => 36; use Test::Exception; require Class::MOP; @@ -123,3 +123,24 @@ throws_ok { ok( Class::MOP::is_class_loaded('TestClassLoaded3'), 'We see that TestClassLoaded3 is loaded after requiring it (it has an @ISA but no methods or $VERSION)' ); } + +{ + { + package Not::Loaded; + our @ISA; + } + + ok( ! Class::MOP::is_class_loaded('Not::Loaded'), + 'the mere existence of an @ISA for a package does not mean a class is loaded' ); +} + +{ + { + package Loaded::Ish; + our @ISA = 'Foo'; + } + + ok( Class::MOP::is_class_loaded('Loaded::Ish'), + 'an @ISA with members does mean a class is loaded' ); +} + diff --git a/xs/MOP.xs b/xs/MOP.xs index 378f874..cf07b55 100644 --- a/xs/MOP.xs +++ b/xs/MOP.xs @@ -89,7 +89,7 @@ is_class_loaded(klass=&PL_sv_undef) if (hv_exists_ent (stash, KEY_FOR(ISA), HASH_FOR(ISA))) { HE *isa = hv_fetch_ent(stash, KEY_FOR(ISA), 0, HASH_FOR(ISA)); - if (isa && HeVAL(isa) && GvAV(HeVAL(isa))) { + if (isa && HeVAL(isa) && GvAV(HeVAL(isa)) && av_len(GvAV(HeVAL(isa))) != -1) { XSRETURN_YES; } }