What I would like to achieve is to create a Moose class that imports several roles. This is what I have been doing for many years without any problems, although I am currently insisting on why the simple example below will generate method name conflicts.
package logrole; use Moose::Role; use POSIX; use namespace::autoclean; package otherrole; use Moose::Role; use File::Temp; use namespace::autoclean; package myclass; use Moose; use namespace::autoclean; with 'logrole', 'otherrole'; package main; use strict; use warnings; use myclass;
Running this gives:
Due to method name conflicts in roles 'logrole' and 'otherrole', the methods 'SEEK_CUR', 'SEEK_END', and 'SEEK_SET' must be implemented or excluded by 'myclass' at /home/user/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/x86_64-linux/Moose/Exporter.pm line 419 Moose::with('logrole', 'otherrole') called at roles.pl line 29
According to docs, you can exclude method names when using this role:
package logrole; use Moose::Role; use POSIX; use namespace::autoclean; package otherrole; use Moose::Role; use File::Temp; use namespace::autoclean; package myclass; use Moose; use namespace::autoclean; with 'logrole', 'otherrole' => { -excludes => ["SEEK_CUR", "SEEK_END", "SEEK_SET" ] }; package main; use strict; use warnings; use myclass;
This resolves name conflicts, but the problem with this solution is that trying to import POSIX into otherrole creates hundreds of name conflicts, so fixing the exception to them in the myclass module seems very confusing.
How to import (or write) these roles to avoid method name conflicts?
source share