NAME

mixin::with - declaring a mix-in class

SYNOPSIS

package Dog::Retriever;
use mixin::with 'Dog';

DESCRIPTION

mixin::with is used to declare mix-in classes.

Creating a mixin class.

There's one critical difference between a normal subclass and one intended to be mixin.

1. It can have no private methods. Instead, use lexical methods.
my $private = sub { ... };
$self->$private(@args);

instead of

sub _private { ... }
$self->_private(@args);

Don't worry, it's the same thing.

Mixin classes useful for those that add new functionality to an existing class. If you find yourself doing:

package Foo::ExtraStuff;
use base 'Foo';

package Bar;
use base qw(Foo Foo::ExtraStuff);

it's a good indication that Foo::ExtraStuff might do better as a mixin.

How?

Basic usage is simple:

package Foo::Extra;
use mixin::with 'Foo';

sub new_thing {
    my($self) = shift;
    ...normal method...
}

use mixin::with 'Foo' is similar to subclassing from 'Foo'.

All public methods of Foo::Extra will be mixed in. mixin::with considers all methods that don't start with an '_' as public.

FAQ

What if I want to mixin with anything?

Sometimes a mixin does not care what it mixes in with. Consider a logging or error handling mixin. For these, simply mixin with UNIVERSAL.

package My::Errors;
use mixin::with qw(UNIVERSAL);

AUTHOR

Michael G Schwern <schwern@pobox.com>

SEE ALSO

mixin, ruby from which I stole this idea.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 122:

You forgot a '=back' before '=head1'