Skip to content
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

Anonymous functions which are a key in a hash will get the line number of the hash declaration. #112

Open
schwern opened this issue Oct 22, 2014 · 2 comments
Labels

Comments

@schwern
Copy link
Contributor

schwern commented Oct 22, 2014

Here's an example.

#line 15
my $hash = {
    over    => 'under',
    left    => 'right',
    key     => func() {
        return __LINE__;
    },
    foo     => "bar",
    up      => "down",
};

is $hash->{key}->(), 19;
is __LINE__, 26;

It doesn't matter how many hash pairs come before the function, it will always return 16. The function thinks it starts on the same line as the hash.

This has been a problem since at least v20090424. This does not appear to be a mistake on our part, but something wrong with the compiler / Devel::Declare.

This a particular problem in classes which use Moose.

has foo =>
    is => 'rw',
    default => method() {
        return $self->bar + 23;
    };
@schwern schwern added the Bug label Oct 22, 2014
@schwern
Copy link
Contributor Author

schwern commented Oct 22, 2014

Wrapping the function in a do block fixes the problem. Unfortunately we have no way of doing that.

@schwern
Copy link
Contributor Author

schwern commented Feb 20, 2015

Function::Parameters doesn't have this problem. It uses the keyword plugin API instead of Devel::Declare. It might be more prudent to adapt it to Method::Signatures. That would mean raising the minimum requirement to 5.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant