+package Moose::Cookbook::Roles::Recipe2;
-=pod
+# ABSTRACT: Advanced Role Composition - method exclusion and aliasing
+
+__END__
-=head1 NAME
-Moose::Cookbook::Roles::Recipe2 - Advanced Role Composition - method exclusion and aliasing
+=pod
=head1 SYNOPSIS
use Moose::Role;
with 'Restartable' => {
- alias => {
+ -alias => {
stop => '_stop',
start => '_start'
- }
+ },
+ -excludes => [ 'stop', 'start' ],
};
sub stop {
package Restartable::ButBroken;
use Moose::Role;
- with 'Restartable' => { excludes => [ 'stop', 'start' ] };
+ with 'Restartable' => { -excludes => [ 'stop', 'start' ] };
sub stop {
my $self = shift;
C<Restartable> to private methods, and provide wrappers around the
originals (1).
+Note that aliasing simply I<adds> a name, so we also need to exclude the
+methods with their original names.
+
with 'Restartable' => {
- alias => {
+ -alias => {
stop => '_stop',
start => '_start'
- }
+ },
+ -excludes => [ 'stop', 'start' ],
};
In the C<Restartable::ButBroken> role, we want to provide an entirely
new behavior for C<stop> and C<start>. We exclude them entirely when
composing the C<Restartable> role into C<Restartable::ButBroken>.
-It's worth noting that the C<excludes> parameter also accepts a single
+It's worth noting that the C<-excludes> parameter also accepts a single
string as an argument if you just want to exclude one method.
- with 'Restartable' => { excludes => [ 'stop', 'start' ] };
+ with 'Restartable' => { -excludes => [ 'stop', 'start' ] };
=head1 CONCLUSION
=back
-=head1 AUTHOR
-
-Dave Rolsky E<lt>autarch@urth.orgE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2006-2009 by Infinity Interactive, Inc.
-
-L<http://www.iinteractive.com>
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
=begin testing
{