NAME
Data::Object::RoleHas
ABSTRACT
Data-Object Role Attribute Builder
SYNOPSIS
package Pointable;
use Data::Object::Role;
use Data::Object::RoleHas;
has 'x';
has 'y';
1;
DESCRIPTION
This package modifies the consuming package with behaviors useful in defining classes. Specifically, this package wraps the has attribute keyword functions and adds shortcuts and enhancements.
LIBRARIES
This package uses type constraints defined by:
EXPORTS
This package automatically exports the following keywords.
has
package Person;
use Data::Object::Class;
use Data::Object::ClassHas;
has 'id';
has fname => (
is => 'ro',
isa => 'StrObj',
crc => 1,
req => 1
);
has lname => (
is => 'ro',
isa => 'StrObj',
crc => 1,
req => 1
);
1;
The has keyword is used to declare role attributes, which can be accessed and assigned to using the built-in getter/setter or by the object constructor. See Moo for more information.
- is
-
is => 'ro' # read-only is => 'rw' # read-writeThe
isdirective is used to denote whether the attribute is read-only or read-write. See the Moo documentation for more details. - isa
-
# declare type constraint isa => 'StrObject' isa => 'ArrayObject' isa => 'CodeObject'The
isadirective is used to define the type constraint to validate the attribute against. See the Moo documentation for more details. - req|required
-
# required attribute req => 1 required => 1The
requireddirective is used to denote if an attribute is required or optional. See the Moo documentation for more details. - opt|optional
-
# optional attribute opt => 1 optional => 1The
optionaldirective is used to denote if an attribute is optional or required. See the Moo documentation for more details. - bld|builder
-
# build value bld => $builder builder => $builderThe
builderdirective expects a coderef and builds the attribute value if it wasn't provided to the constructor. See the Moo documentation for more details. - clr|clearer
-
# create clear_${attribute} clr => $clearer clearer => $clearerThe
clearerdirective expects a coderef and generates a clearer method. See the Moo documentation for more details. - crc|coerce
-
# coerce value crc => 1 coerce => 1The
coercedirective denotes whether an attribute's value should be automatically coerced. See the Moo documentation for more details. - def|default
-
# default value def => $default default => $defaultThe
defaultdirective expects a coderef and is used to build a default value if one is not provided to the constructor. See the Moo documentation for more details. - hnd|handles
-
# dispatch to value hnd => $handles handles => $handlesThe
handlesdirective denotes the methods created on the object which dispatch to methods available on the attribute's object. See the Moo documentation for more details. - lzy|lazy
-
# lazy attribute lzy => 1 lazy => 1The
lazydirective denotes whether the attribute will be constructed on-demand, or on-construction. See the Moo documentation for more details. - pre|predicate
-
# create has_${attribute} pre => 1 predicate => 1The
predicatedirective expects a coderef and generates a method for checking the existance of the attribute. See the Moo documentation for more details. - rdr|reader
-
# attribute reader rdr => $reader reader => $readerThe
readerdirective denotes the name of the method to be used to "read" and return the attribute's value. See the Moo documentation for more details. - tgr|trigger
-
# attribute trigger tgr => $trigger trigger => $triggerThe
triggerdirective expects a coderef and is executed whenever the attribute's value is changed. See the Moo documentation for more details. - wkr|weak_ref
-
# weaken ref wkr => 1 weak_ref => 1The
weak_refdirective is used to denote if the attribute's value should be weakened. See the Moo documentation for more details. - wrt|writer
-
# attribute writer wrt => $writer writer => $writerThe
writerdirective denotes the name of the method to be used to "write" and return the attribute's value. See the Moo documentation for more details.
CREDITS
Al Newkirk, +296
Anthony Brummett, +10
José Joaquín Atria, +1
AUTHOR
Al Newkirk, awncorp@cpan.org
LICENSE
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
PROJECT
SEE ALSO
To get the most out of this distribution, consider reading the following: