PrePAN

Sign in to PrePAN

namespace::local Forget imports at end of scope, think namespace::clean inside-out

Good

Synopsis

package My::Module;

sub uses_imports {
     use namespace::local;
     use Foo::Bar qw(quux);

     # quux available
};

sub no_imports {
     # quux is not defined here
};

# quux is not defined here as well
1;

Description

Say we need some utility functions inside a subroutine or scope, but we'd like to (a) keep them private and (b) keep them unavailable for the rest of the package.

This module would make imports (in fast, any symbol table changes) only available until end of scope.

namespace::clean does similar thing (and is cool!), but one must be careful to avoid erasing needed functions.

Comments

anonymouse
Anonymous
Very cool! Would use it in lots of places!
Will Foo::Bar be loaded in BEGIN {} or only when uses_imports() called?

Please sign up to post a review.