-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use Devel::LexAlias #3
Conversation
I still don't like the global variable idea. For instance: #!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Eval::Closure;
my $destroyed = 0;
package Foo {
sub DESTROY { $destroyed++ }
}
{
my $number = bless \(my $foo), "Foo";
$$number = 40;
my $closure = eval_closure(
source => 'sub { $$xxx += 2 }',
environment => { '$xxx' => \$number },
);
$closure->();
is($$number, 42);
is($destroyed, 0);
}
is($destroyed, 1);
done_testing; There are a lot of ways that global variables don't behave the same way as lexical variables do, and I don't want to have to deal with all of that and end up breaking in a bunch of different edge cases. |
Hmmm... good point. |
I do actually have another a pure Perl fallback solution (using tied lexicals) if you're interested. |
Not particularly, that would be even more broken (you wouldn't be able to close over existing tied variables anymore, for instance). Maybe aliasing should just be an option, that dies if Devel::LexAlias isn't installed? |
I have a test case with a tied scalar that works. I'm not doing anything especially interesting in the tied object; just:
|
The only place it fails is if you call |
On Thu, Jul 25, 2013 at 12:20:47PM -0700, Toby Inkster wrote:
I imagine it'll also fail if you untie the original variable outside of Basically, if this is going to be an implicit decision based only on |
No, that all works fine. |
My second point still stands. |
This is all quite academic anyway - the pull request as it stands doesn't include the fallback to tie. |
Thinking about this some more, I think this should probably be an |
OK; I'll sort that out tomorrow. |
Done. |
Thanks, that looks good. |
This is a second attempt at a fix for #2 using Devel::LexAlias.
It has a fallback to using package variables when Devel::LexAlias is not available, because I think it's nice to have a pure Perl implementation. The two code paths only diverge in a couple of very small places, so I don't think it should have much impact on Eval::Closure's maintainability.