Skip Menu |

This queue is for tickets about the Method-Signatures CPAN distribution.

Report information
The Basics
Id: 83961
Status: resolved
Priority: 0/
Queue: Method-Signatures

People
Owner: Nobody in particular
Requestors: stephen.thirlwall [...] strategicdata.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 20130222
Fixed in: 20131010



Subject: Named parameters cause lexical scoping problems with Try::Tiny
I don't know if this is a Try::Tiny issue, but the following code fails. func named_params(:$a) { my $b; try { die $a } catch { $b = $_ }; return $b; #<---- $b is undef here } Also, this warning is issued: Aliasing of outer lexical variable has limited scope The bug only happens with named parameters & try/catch. The same code works with positional parameters are used, or dropping try/catch for plain eval. Attached is a small test case. git bisecting with this test points to this commit: https://github.com/schwern/method-signatures/commit/6f353069833dd6febab6c11cc9613f3204d63d32
Subject: aliasing-outer-lexical.t
use strict; use warnings; use Test::More; use Method::Signatures; use Try::Tiny; func positional_params($a) { my $b; try { die $a } catch { $b = $_ }; return $b; } func named_params(:$a) { my $b; try { die $a } catch { $b = $_ }; return $b; } func named_params_eval(:$a) { my $b; eval { die $a }; if ($@) { $b = $@ } return $b; } my $arg = {}; is( positional_params($arg), $arg, 'try/catch with positional params'); is( named_params(a => $arg), $arg, 'try/catch with named params'); is( named_params_eval(a => $arg), $arg , 'eval with named params'); done_testing();
This appears to be a known Data::Alias issue. https://metacpan.org/module/Data::Alias#KNOWN-ISSUES Reverting this line fixes my issue, but breaks t/named_alias.t https://github.com/schwern/method-signatures/commit/6f353069833dd6febab6c11cc9613f3204d63d32#L0L991 - push @code, "my \%args = \@_[$first_named_idx..\$#_];"; + push @code, "Data::Alias::alias( my (\%args) = \@_[$first_named_idx..\$#_] );"; Attached is a refined test case which indicates the bug is not related to the parameters themselves. The value thrown is now a global, the parameters are completely ignored.
Subject: aliasing-outer-lexical-2.t
use strict; use warnings; use Test::More; use Method::Signatures; use Try::Tiny; my $arg = {}; func positional_params($a) { my $b; try { die $arg } catch { $b = $_ }; return $b; } func named_params(:$a) { my $b; try { die $arg } catch { $b = $_ }; return $b; } func aliased_params(:$a) { my $b; try { die $arg } catch { $b = $_ }; return $b; } func named_params_eval(:$a) { my $b; eval { die $arg }; if ($@) { $b = $@ } return $b; } is( positional_params($arg), $arg, 'try/catch with positional params'); is( named_params(a => $arg), $arg, 'try/catch with named params'); is( aliased_params(a => $arg), $arg , 'try/catch with aliased params'); is( named_params_eval(a => $arg), $arg , 'eval with named params'); done_testing();
Stephen, Show quoted text
> Reverting this line fixes my issue, but breaks t/named_alias.t > > > https://github.com/schwern/method- > signatures/commit/6f353069833dd6febab6c11cc9613f3204d63d32#L0L991 > > - push @code, "my \%args = \@_[$first_named_idx..\$#_];"; > + push @code, "Data::Alias::alias( my (\%args) = > \@_[$first_named_idx..\$#_] );";
Okay, it looks like the change that Damian made was too aggressive; I'll need to conditionalize it, I suppose. Thanks for the test case! I'll try to get this done this weekend.
This is now also being tracked as GitHub issue #71. I will close both simultaneously once I get a chance to implement the solution suggested by Damian.
This should be fixed on master. Once I can get this released to CPAN, I'll close this ticket. In the meantime, if you want to test the solution with the latest [GitHub code](https://github.com/schwern/method-signatures), you can let me know if that doesn't actually solve your problem. Along with this release, I'll be making Data::Alias optional (i.e. recommended instead of required), so you shouldn't require Data::Alias at all (as long as you don't try to use any aliasing features).
Confirmed - that fix works for me. Thanks Buddy!
Show quoted text
> Confirmed - that fix works for me.
Excellent. Release is official now; closing ticket.