If you are familiar with the concept of abstract base classes in other
languages, you may be tempted to use roles in the same way.
-You I<can> define a "interface-only" role, one that contains I<just> a
-list of required methods.
+You I<can> define an "interface-only" role, one that contains I<just>
+a list of required methods.
However, any class which consumes this role must implement all of the
required methods, either directly or through inheritance from a
the same name, we will have a conflict. In that case, the composing
class is required to provide its I<own> method of the same name.
- package Breakdances;
+ package Breakdancer;
use Moose::Role
the new name. We also need to exclude the original name:
with 'Breakable' => {
- alias => { break => 'break_bone' },
- exclude => 'break',
+ alias => { break => 'break_bone' },
+ excludes => 'break',
},
'Breakdancer' => {
- alias => { break => 'break_dance' },
- exclude => 'break',
+ alias => { break => 'break_dance' },
+ excludes => 'break',
};
-The exclude parameter prevents the C<break> method from being composed
+The excludes parameter prevents the C<break> method from being composed
into the C<FragileDancer> class, so we don't have a conflict. This
means that C<FragileDancer> does not need to implement its own
C<break> method.