Skip to content

Instantly share code, notes, and snippets.

@rightgo09
Created May 9, 2012 15:19
Show Gist options
  • Save rightgo09/2645412 to your computer and use it in GitHub Desktop.
Save rightgo09/2645412 to your computer and use it in GitHub Desktop.
To unload all used module
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