X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fnamespace%2Fclean.pm;h=9aaa51ae26ec1bfe026e19e9c27bcf9379e39c6c;hb=1a1be5dc205173c95164e59932ef58652a223975;hp=d7c9a1076c55714e7ccbba4e9801316fcfcf19b4;hpb=472d4b1e844e78b06c74e5792999e388a886c5fe;p=p5sagit%2Fnamespace-clean.git diff --git a/lib/namespace/clean.pm b/lib/namespace/clean.pm index d7c9a10..9aaa51a 100644 --- a/lib/namespace/clean.pm +++ b/lib/namespace/clean.pm @@ -9,18 +9,19 @@ namespace::clean - Keep imports and functions out of your namespace use warnings; use strict; -use vars qw( $VERSION $STORAGE_VAR ); -use Symbol qw( qualify_to_ref ); -use Filter::EOF; +use vars qw( $VERSION $STORAGE_VAR $SCOPE_HOOK_KEY ); +use Symbol qw( qualify_to_ref ); +use Scope::Guard; =head1 VERSION -0.05 +0.07 =cut -$VERSION = 0.05; -$STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE'; +$VERSION = 0.07; +$STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE'; +$SCOPE_HOOK_KEY = 'namespace_clean_SCOPING'; =head1 SYNOPSIS @@ -79,6 +80,18 @@ be a module exporting an C method along with some functions: If you just want to C<-except> a single sub, you can pass it directly. For more than one value you have to use an array reference. +=head2 Moose + +When using C together with L you want to keep +the installed C method. So your classes should look like: + + package Foo; + use Moose; + use namespace::clean -except => 'meta'; + ... + +Same goes for L. + =head1 METHODS You shouldn't need to call any of these. Just C the package at the @@ -88,9 +101,8 @@ appropriate place. =head2 import -Makes a snapshot of the current defined functions and registers a -L cleanup routine to remove those symbols at the end -of the compile-time. +Makes a snapshot of the current defined functions and installs a +L in the current scope to invoke the cleanups. =cut @@ -119,7 +131,8 @@ sub import { # register EOF handler on first call to import unless ($store->{handler_is_installed}) { - Filter::EOF->on_eof_call(sub { + $^H |= 0x120000; + $^H{ $SCOPE_HOOK_KEY } = Scope::Guard->new(sub { SYMBOL: for my $f (keys %{ $store->{remove} }) { @@ -128,8 +141,10 @@ sub import { no strict 'refs'; # keep original value to restore non-code slots - local *__tmp = *{ ${ "${cleanee}::" }{ $f } }; - delete ${ "${cleanee}::" }{ $f }; + { no warnings 'uninitialized'; # fix possible unimports + local *__tmp = *{ ${ "${cleanee}::" }{ $f } }; + delete ${ "${cleanee}::" }{ $f }; + } SLOT: # restore non-code slots to symbol @@ -225,7 +240,7 @@ use C instead. =head1 SEE ALSO -L +L =head1 AUTHOR AND COPYRIGHT