Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Sub-Exporter-Lexical CPAN distribution.

Report information
The Basics
Id: 79219
Status: resolved
Priority: 0/
Queue: Sub-Exporter-Lexical

People
Owner: Nobody in particular
Requestors: MAUKE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.092291
Fixed in: (no value)



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
Yeah, frankly I don't know what I was thinking when I wrote this module. On the other hand, hopefully I can make it *really* work soon, now that 5.17.x has real lexical subs. -- rjbs
On Tue Oct 09 22:15:47 2012, RJBS wrote: Show quoted text
> Yeah, frankly I don't know what I was thinking when I wrote this > module. > > On the other hand, hopefully I can make it *really* work soon, now > that 5.17.x has real lexical > subs.
And in 5.12.0+ you can use Lexical::Sub, which lexically hooks the bareword lookup mechanism.
I am shipping a new version with (a) a statement of the fact that I don't know why I wrote this to begin and (b) a conversion to Lexical::Sub and (c) no more tests and (d) no existing tests failing. This should be substantially less ridiculously wrong, although I'm sure it's still not great. Since I don't use it, I'm going to leave it be for now. Thanks for reminding me of this blunder. :-/ -- rjbs