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-write
The
is
directive 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
isa
directive 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 => 1
The
required
directive 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 => 1
The
optional
directive 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 => $builder
The
builder
directive 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 => $clearer
The
clearer
directive expects a coderef and generates a clearer method. See the Moo documentation for more details. - crc|coerce
-
# coerce value crc => 1 coerce => 1
The
coerce
directive denotes whether an attribute's value should be automatically coerced. See the Moo documentation for more details. - def|default
-
# default value def => $default default => $default
The
default
directive 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. - mod|modify
-
# modify definition mod => 1 modify => 1
The
modify
directive denotes whether a pre-existing attribute's definition is being modified. This ability is not supported by the Moo object superclass. - hnd|handles
-
# dispatch to value hnd => $handles handles => $handles
The
handles
directive 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 => 1
The
lazy
directive denotes whether the attribute will be constructed on-demand, or on-construction. See the Moo documentation for more details. - new
-
# lazy attribute # create new_${attribute} new => 1
The
new
directive, if truthy, denotes that the attribute will be constructed on-demand, i.e. is lazy, with a builder namednew_{attribute}
. This ability is not supported by the Moo object superclass. - pre|predicate
-
# create has_${attribute} pre => 1 predicate => 1
The
predicate
directive 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 => $reader
The
reader
directive 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 => $trigger
The
trigger
directive expects a coderef and is executed whenever the attribute's value is changed. See the Moo documentation for more details. - use
-
# lazy dependency injection use => ['service', 'datetime']
The
use
directive denotes that the attribute will be constructed on-demand, i.e. is lazy, using a custom builder meant to perform service construction. This directive exists to provide a simple dependency injection mechanism for class attributes. This ability is not supported by the Moo object superclass. - wkr|weak_ref
-
# weaken ref wkr => 1 weak_ref => 1
The
weak_ref
directive 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 => $writer
The
writer
directive 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, +319
Anthony Brummett, +10
Adam Hopkins, +2
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 terms of the The Apache License, Version 2.0, as elucidated here, https://github.com/iamalnewkirk/do/blob/master/LICENSE.
PROJECT
SEE ALSO
To get the most out of this distribution, consider reading the following: