The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mouse::Role - The Mouse Role

VERSION

This document describes Mouse version 0.83

SYNOPSIS

    package Comparable;
    use Mouse::Role; # the package is now a Mouse role

    # Declare methods that are required by this role
    requires qw(compare);

    # Define methods this role provides
    sub equals {
        my($self, $other) = @_;
        return $self->compare($other) == 0;
    }

    # and later
    package MyObject;
    use Mouse;
    with qw(Comparable); # Now MyObject can equals()

    sub compare {
        # ...
    }

    my $foo = MyObject->new();
    my $bar = MyObject->new();
    $obj->equals($bar); # yes, it is comparable

KEYWORDS

meta -> Mouse::Meta::Role

Returns this role's metaclass instance.

before (method|methods|regexp) -> CodeRef

Sets up a before method modifier. See "before" in Moose.

after (method|methods|regexp) => CodeRef

Sets up an after method modifier. See "after" in Moose.

around (method|methods|regexp) => CodeRef

Sets up an around method modifier. See "around" in Moose.

super

Sets up the super keyword. See "super" in Moose.

override method => CodeRef

Sets up an override method modifier. See "Role/override" in Moose.

inner

This is not supported in roles and emits an error. See "Role" in Moose.

augment method => CodeRef

This is not supported in roles and emits an error. See "Role" in Moose.

has (name|names) => parameters

Sets up an attribute (or if passed an arrayref of names, multiple attributes) to this role. See "has" in Mouse.

confess(error) -> BOOM

"confess" in Carp for your convenience.

blessed(value) -> ClassName | undef

"blessed" in Scalar::Util for your convenience.

MISC

import

Importing Mouse::Role will give you sugar.

unimport

Please unimport (no Mouse::Role) so that if someone calls one of the keywords (such as "has") it will break loudly instead breaking subtly.

SEE ALSO

Moose::Role