Subject: | Sub::Exporter::Lexical not actually lexical |
Short version:
foo(); { use Some::Module { installer => lex }, qw(foo); foo(); } foo();
^ the first two 'foo()'s call Some::Module::foo, the last 'foo()' dies
with Undefined subroutine &main::foo called
Long version:
The documentation claims "all you need to know is that by using
Sub::Exporter::Lexical's installer, you can import routines into a
lexical scope that will be cleaned up when that scope ends". This is not
the case. It looks like what's happening is that by using lex, the sub
is imported into the package (not lexical scope) as normal, but
clobbered when the scope ends.
The two main problems with this approach:
- It works retroactively, i.e. it affects calls that appear lexically
before the import.
- It doesn't nest. Once the scope ends, the sub is deleted. Any previous
sub is not restored.
Funny consequences:
foo;
{ use Some::Module { installer => lex }, qw(foo); }
# ^ dies with: Bareword "foo" not allowed while "strict subs" in use
sub foo {}
foo;
{ use Some::Module { installer => lex }, qw(foo); }
# ^ silently calls Some::Module::foo
sub foo {}
foo;
{ use Some::Module { installer => lex }, qw(foo); }
foo;
# ^ dies with: Bareword "foo" not allowed while "strict subs" in use
# at the second "foo;" line