This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add copyright and license. POD cleanup. Mention Moose::Role.
- Loading branch information
Showing
2 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,9 @@ The idea is to solve the same sets of problems which MI solves without | |
the problems of MI. For all practical purposes you can think of a | ||
mixin as multiple inheritance without the actual inheritance. | ||
Mixins are a band-aid for the problems of MI. A better solution is to use traits (called "Roles" in Perl 6), which are like mixins on steroids. Class::Trait implements this. | ||
Mixins are a band-aid for the problems of MI. A better solution is to | ||
use traits (called "Roles" in Perl 6), which are like mixins on | ||
steroids. Class::Trait implements this. | ||
=head2 Using a mixin class | ||
|
@@ -70,7 +72,9 @@ See L<mixin::with>. | |
=head2 Mixins, Inheritance and SUPER | ||
A class which uses a mixin I<does not> inherit from it. However, through some clever trickery, C<SUPER> continues to work. Here's an example. | ||
A class which uses a mixin I<does not> inherit from it. However, | ||
through some clever trickery, C<SUPER> continues to work. Here's an | ||
example. | ||
{ | ||
package Parent; | ||
|
@@ -100,9 +104,17 @@ A class which uses a mixin I<does not> inherit from it. However, through some c | |
print join " ", Child->foo; # Parent Middle Child | ||
This will print C<Parent Middle Child>. You'll note that this is the same result if Child inherited from Middle and Middle from Parent. Its also the same result if Child multiply inherited from Middle and Parent but I<NOT> if it inherited from Parent then Middle. The advantage of mixins vs multiple inheritance is such ambiguities do not exist. | ||
This will print C<Parent Middle Child>. You'll note that this is the | ||
same result if Child inherited from Middle and Middle from Parent. | ||
Its also the same result if Child multiply inherited from Middle and | ||
Parent but I<NOT> if it inherited from Parent then Middle. The | ||
advantage of mixins vs multiple inheritance is such ambiguities do not | ||
exist. | ||
Note that even though both the Child and Middle define foo() the Middle mixin does not overwrite Child's foo(). A mixin does not simply export its methods into the mixer and thus does not blow over existing methods. | ||
Note that even though both the Child and Middle define foo() the | ||
Middle mixin does not overwrite Child's foo(). A mixin does not | ||
simply export its methods into the mixer and thus does not blow over | ||
existing methods. | ||
=cut | ||
|
||
|
@@ -182,15 +194,30 @@ sub _croak { | |
A mixin will not warn if the mixin and the user define the same method. | ||
=head1 AUTHOR | ||
Michael G Schwern E<lt>[email protected]E<gt> | ||
=head1 LICENSE | ||
Copyright 2002-2010 by Michael G Schwern | ||
This library is free software; you can redistribute it and/or modify it | ||
under the same terms as Perl itself. | ||
L<http://dev.perl.org/licenses/> | ||
=head1 SEE ALSO | ||
L<Class::Trait> - mixin.pm is a gateway drug to traits | ||
L<Class::C3> - another band-aid on multiple inheritance | ||
L<Moose::Role> - Moose's implementation of traits/roles. | ||
=cut | ||
|
||
1; |