Created
May 9, 2012 15:19
-
-
Save rightgo09/2645412 to your computer and use it in GitHub Desktop.
To unload all used module
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
package Class::Unload::All; | |
use strict; | |
use warnings; | |
use B::Hooks::EndOfScope qw/ on_scope_end /; | |
use Class::Unload; | |
use Module::Used qw/ modules_used_in_files /; | |
sub import { | |
my $class = caller; | |
my $path = _path($class); | |
my @modules = modules_used_in_files($path); | |
on_scope_end { | |
for my $module (@modules) { | |
Class::Unload->unload($module); | |
} | |
}; | |
} | |
sub _path { | |
my $class = shift; | |
$class =~ s!::!/!g; | |
$class .= '.pm'; | |
return $INC{$class}; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment