Subject: | Declaring a sub before a role application and later declaring a has results in error |
Hi,
I've encountered a strange error, which only happens to me in only some setups (I haven't been able to fully determine the conditions yet, since this has started happening to us when we set up a CI environment). Nonetheless I've found a minimal test case to demonstrate the error.
I was intially writing a role that requires some methods to be implemented. As I wanted those methods to be implemented with an attribute, I did it in a typical Moose style of first declaring the sub "sub attribute;", applying the role, and later declaring "has attribute".
I get this error: "Can't use string ("-1") as a symbol ref while "strict refs" in use at local/lib/perl5/Role/Tiny.pm line 382.".
I've set up a repo with the code to test it: https://github.com/pplu/moo-role-error-demo (run carton, and then make fail).
What I've found out:
- The role can be empty to trigger the error, but has to be applied (if no role is applied: no error).
- Changing the role to be after the has, and deleting the sub declaration: it works.
- I have a project where the fail case is working without problems, but I really don't know why (maybe because some extra dependency makes Moo behave in a different way?).
- It can consistently be reproduced in different perls (I've tried docker perl:5.2X-slim images).
I hope this helps solve the issue. If you need more info, please shout out.