Created
February 1, 2016 23:23
-
-
Save 2shortplanks/f2760d1d8b2d8a8d27a6 to your computer and use it in GitHub Desktop.
The perils of use constant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mark@travis:~/tmp/nac$ ls | |
MyClass.pm MyConstants.pm RoleA.pm RoleB.pm | |
Mark@travis:~/tmp/nac$ cat MyConstants.pm | |
package MyConstants; | |
use base qw(Exporter); | |
# this is fine | |
sub my_good_constant { 1 }; | |
push @EXPORT_OK, qw(my_good_constant); | |
# this ain't | |
use constant my_bad_constant => 1; | |
push @EXPORT_OK, qw(my_bad_constant); | |
1; | |
Mark@travis:~/tmp/nac$ cat RoleA.pm | |
package RoleA; | |
use Moose::Role; | |
use MyConstants qw( my_good_constant my_bad_constant ); | |
sub from_role_a { return 1 }; | |
1; | |
Mark@travis:~/tmp/nac$ cat RoleB.pm | |
package RoleB; | |
use Moose::Role; | |
use MyConstants qw( my_good_constant my_bad_constant ); | |
sub from_role_b { return 1 }; | |
1; | |
Mark@travis:~/tmp/nac$ cat MyClass.pm | |
package MyClass; | |
use Moose; | |
with 'RoleA', 'RoleB'; | |
__PACKAGE__->meta->make_immutable; | |
1; | |
Mark@travis:~/tmp/nac$ perl MyClass.pm | |
Due to a method name conflict in roles 'RoleA' and 'RoleB', the method 'my_bad_constant' must be implemented or excluded by 'MyClass' at /opt/markperl/lib/site_perl/5.22.0/darwin-2level/Moose/Exporter.pm line 419 | |
Moose::with('RoleA', 'RoleB') called at MyClass.pm line 4 | |
Mark@travis:~/tmp/nac$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment