Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

moo::role5.18(3) [mojave man page]

Moo::Role(3)						User Contributed Perl Documentation					      Moo::Role(3)

NAME
Moo::Role - Minimal Object Orientation support for Roles SYNOPSIS
package My::Role; use Moo::Role; sub foo { ... } sub bar { ... } has baz => ( is => 'ro', ); 1; And elsewhere: package Some::Class; use Moo; # bar gets imported, but not foo with('My::Role'); sub foo { ... } 1; DESCRIPTION
"Moo::Role" builds upon Role::Tiny, so look there for most of the documentation on how this works. The main addition here is extra bits to make the roles more "Moosey;" which is to say, it adds "has". IMPORTED SUBROUTINES
See "IMPORTED SUBROUTINES" in Role::Tiny for all the other subroutines that are imported by this module. has has attr => ( is => 'ro', ); Declares an attribute for the class to be composed into. See "has" in Moo for all options. CLEANING UP IMPORTS
Moo::Role cleans up its own imported methods and any imports declared before the "use Moo::Role" statement automatically. Anything imported after "use Moo::Role" will be composed into consuming packages. A package that consumes this role: package My::Role::ID; use Digest::MD5 qw(md5_hex); use Moo::Role; use Digest::SHA qw(sha1_hex); requires 'name'; sub as_md5 { my ($self) = @_; return md5_hex($self->name); } sub as_sha1 { my ($self) = @_; return sha1_hex($self->name); } 1; ..will now have a "$self->sha1_hex()" method available to it that probably does not do what you expect. On the other hand, a call to "$self->md5_hex()" will die with the helpful error message: "Can't locate object method "md5_hex"". See "CLEANING UP IMPORTS" in Moo for more details. SUPPORT
See Moo for support and contact information. AUTHORS
See Moo for authors. COPYRIGHT AND LICENSE
See Moo for the copyright and license. perl v5.18.2 2013-12-31 Moo::Role(3)

Check Out this Related Man Page

Mouse::Role(3pm)					User Contributed Perl Documentation					  Mouse::Role(3pm)

NAME
Mouse::Role - The Mouse Role VERSION
This document describes Mouse version 0.99 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 DESCRIPTION
This module declares the caller class to be a Mouse role. The concept of roles is documented in Moose::Manual::Roles. This document serves as API documentation. EXPORTED FUNCTIONS
Mouse::Role supports all of the functions that Mouse exports, but differs slightly in how some items are handled (see "CAVEATS" below for details). Mouse::Role also offers two role-specific keywords: "requires(@method_names)" Roles can require that certain methods are implemented by any class which "does" the role. Note that attribute accessors also count as methods for the purposes of satisfying the requirements of a role. "excludes(@role_names)" This is exported but not implemented in Mouse. IMPORT AND UNIMPORT
import Importing Mouse::Role will give you sugar. "-traits" are also supported. 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. CAVEATS
Role support has only a few caveats: o Roles cannot use the "extends" keyword; it will throw an exception for now. The same is true of the "augment" and "inner" keywords (not sure those really make sense for roles). All other Mouse keywords will be deferred so that they can be applied to the consuming class. o Role composition does its best to not be order-sensitive when it comes to conflict resolution and requirements detection. However, it is order-sensitive when it comes to method modifiers. All before/around/after modifiers are included whenever a role is composed into a class, and then applied in the order in which the roles are used. This also means that there is no conflict for before/around/after modifiers. In most cases, this will be a non-issue; however, it is something to keep in mind when using method modifiers in a role. You should never assume any ordering. SEE ALSO
Mouse Moose::Role Moose::Manual::Roles Moose::Spec::Role perl v5.14.2 2012-06-30 Mouse::Role(3pm)
Man Page