MooseX::Role::WarnOnConflict - Warn if classes override role methods without excluding them
version 0.01
This code will warn at composition time:
{ package My::Role; use MooseX::Role::WarnOnConflict; sub conflict {} } { package My::Class; use Moose; with 'My::Role'; sub conflict {} }
With an error message similar to the following:
The class My::Class has implicitly overridden the method (conflict) from role My::Role ...
To resolve this, explicitly exclude the 'conflict' method:
{ package My::Class; use Moose; with 'My::Role' => { -excludes => [ 'conflict' ] }; sub conflict {} }
Aliasing a role method to an existing method will also warn:
{ package My::Class; use Moose; with 'My::Role' => { -excludes => ['conflict'], -alias => { conflict => 'another_method' }, }; sub conflict { } sub another_method { } }
When using Moose::Role, a class which provides a method a role provides will silently override that method. This can cause strange, hard-to-debug errors when the role's methods are not called. Simply use MooseX::Role::WarnOnConflict instead of Moose::Role and overriding a role's method becomes a composition-time warning. See the synopsis for a resolution.
MooseX::Role::WarnOnConflict
Moose::Role
Curtis "Ovid" Poe <curtis.poe@gmail.com>
This software is Copyright (c) 2022 by Curtis "Ovid" Poe.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install MooseX::Role::WarnOnConflict, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Role::WarnOnConflict
CPAN shell
perl -MCPAN -e shell install MooseX::Role::WarnOnConflict
For more information on module installation, please visit the detailed CPAN module installation guide.