Skip Menu |

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 130050
Status: resolved
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: jlmartinez [...] capside.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2.003004
Fixed in: (no value)



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.
Here is a stack trace of the failure case. : [ether@aquavit moo-test/moo-role-error-demo]$; perl -d:Confess -Ifail -MClass1 -E "say 'success'" Can't use string ("-1") as a symbol ref while "strict refs" in use at /Users/ether/.perlbrew/libs/26.3@std/lib/perl5/Role/Tiny.pm line 382. Role::Tiny::_install_methods("Moo::Role", "Class1", "Role") called at /Users/ether/.perlbrew/libs/26.3@std/lib/perl5/Role/Tiny.pm line 113 Role::Tiny::apply_single_role_to_package("Moo::Role", "Class1", "Role") called at /Users/ether/.perlbrew/libs/26.3@std/lib/perl5/Moo/Role.pm line 288 Moo::Role::apply_single_role_to_package("Moo::Role", "Class1", "Role") called at /Users/ether/.perlbrew/libs/26.3@std/lib/perl5/Role/Tiny.pm line 216 Role::Tiny::apply_role_to_package("Moo::Role", "Class1", "Role") called at /Users/ether/.perlbrew/libs/26.3@std/lib/perl5/Role/Tiny.pm line 221 Role::Tiny::apply_roles_to_package("Moo::Role", "Class1", "Role") called at /Users/ether/.perlbrew/libs/26.3@std/lib/perl5/Moo/Role.pm line 280 Moo::Role::apply_roles_to_package("Moo::Role", "Class1", "Role") called at /Users/ether/.perlbrew/libs/26.3@std/lib/perl5/Moo.pm line 59 Moo::with("Role") called at fail/Class1.pm line 6 require Class1.pm called at -e line 0 main::BEGIN() called at fail/Class1.pm line 0 eval {...} called at fail/Class1.pm line 0 Compilation failed in require. at -e line 0. main::BEGIN() called at -e line 0 eval {...} called at -e line 0 BEGIN failed--compilation aborted. at -e line 0.
Fixed in Role::Tiny commit d698a6437e4f23a281ec3f871631663f7a5669bf.
Fixed in 2.003_005.