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

MooseX::Role::Parameterized::Extending(3)		User Contributed Perl Documentation		 MooseX::Role::Parameterized::Extending(3)

NAME
MooseX::Role::Parameterized::Extending - extending MooseX::Role::Parameterized roles DESCRIPTION
There are heaps of useful modules in the "MooseX" namespace that you can use to make your roles more powerful. However, they do not always work out of the box with MooseX::Role::Parameterized, but it's fairly straight-forward to achieve the functionality you desire. MooseX::Role::Parameterized was designed to be as extensible as the rest of Moose, and as such it is possible to apply custom traits to both the parameterizable role or the ordinary roles they generate. In this example, we will look at applying the fake trait "MooseX::MagicRole" to a parameterizable role. First we need to define a new metaclass for our parameterizable role. package MyApp::Meta::Role::Parameterizable; use Moose; extends 'MooseX::Role::Parameterized::Meta::Role::Parameterizable'; with 'MooseX::MagicRole'; This is a class (observe that it uses Moose, not Moose::Role) which extends the class which governs parameterizable roles. MooseX::Role::Parameterized::Meta::Role::Parameterizable is the metaclass that packages using MooseX::Role::Parameterized receive by default. Note that the class we are extending, MooseX::Role::Parameterized::Meta::Role::Parameterizable, is entirely distinct from the similarly- named class which governs the ordinary roles that parameterized roles generate. An instance of MooseX::Role::Parameterized::Meta::Role::Parameterized represents a role with its parameters already bound. Now we can take advantage of our new subclass by specifying that we want to use "MyApp::Meta::Role::Parameterizable" as our metaclass when importing MooseX::Role::Parameterized: package MyApp::Role; use MooseX::Role::Parameterized -metaclass => 'MyApp::Meta::Role::Parameterizable'; role { ... } And there you go! "MyApp::Role" now has the "MooseX::MagicRole" trait applied. perl v5.18.2 2012-08-14 MooseX::Role::Parameterized::Extending(3)
Man Page