-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.10: add support for restricted stashes and ISAs
classes can be locked and closed. handle all cases. protect internal core stashes from being deleted.
- Loading branch information
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!perl -T | ||
|
||
use Class::Inspector; | ||
use Class::Unload; | ||
use lib 't/lib'; | ||
BEGIN { eval "use Hash::Util"; } # since 5.8.0 | ||
|
||
use Test::More tests => 12; | ||
|
||
for my $class ( qw/ MyClass::Sub::Sub MyClass::Sub MyClass / ) { | ||
no strict 'refs'; | ||
eval "require $class" or diag $@; | ||
if (defined $Hash::Util::VERSION) { | ||
Hash::Util::lock_keys(%{$class."::"}); | ||
} else { | ||
Internals::SvREADONLY(%{$class."::"}, 1); | ||
} | ||
} | ||
|
||
ok( Class::Unload->unload( 'MyClass' ), 'Unloading MyClass' ); | ||
ok( ! Class::Inspector->loaded( 'MyClass' ), 'MyClass is not loaded' ); | ||
ok( ! exists(${'MyClass::'}{'::ISA::CACHE::'}), 'Stash cruft deleted' ); | ||
ok( Class::Inspector->loaded( 'MyClass::Sub' ), 'MyClass::Sub is still loaded' ); | ||
|
||
ok( Class::Unload->unload( 'MyClass::Sub' ), 'Unloading MyClass::Sub' ); | ||
ok( ! Class::Inspector->loaded( 'MyClass::Sub' ), 'MyClass::Sub is not loaded'); | ||
|
||
ok( Class::Unload->unload( 'MyClass::Sub::Sub' ), 'Unloading MyClass::Sub::Sub' ); | ||
ok( ! Class::Inspector->loaded( 'MyClass::Sub::Sub' ), 'MyClass::Sub::Sub is not loaded'); | ||
|
||
ok( ! Class::Unload->unload('MyClass'), 'Unloading not-loaded class'); | ||
|
||
ok( Class::Unload->unload( 'Class::Unload' ), 'Unloading Class::Unload' ); | ||
ok( ! Class::Inspector->loaded( 'Class::Unload' ), 'Class::Unload is not loaded' ); | ||
|
||
eval { Class::Unload->unload( 'dummy' ) }; | ||
like( $@, qr /Can't locate object method "unload" via package "Class::Unload"/, | ||
"Can't call method on unloaded class" ); |