Data::Object::ClassHas

Data-Object Class Attribute Builder

package Point;

use Data::Object::Class;
use Data::Object::ClassHas;

has 'x';
has 'y';

1;

Data::Object::Library

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.

+=head1 EXPORTS

This package automatically exports the following keywords.

+=head2 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 class attributes, which can be accessed and assigned to using the built-in getter/setter or by the object constructor. See Moo for more information.

+=over 4

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=item 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 named new_{attribute}. This ability is not supported by the Moo object superclass.

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=item 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.

+=back

6 POD Errors

The following errors were encountered while parsing the POD:

Around line 8:

Unknown directive: =name

Around line 12:

Unknown directive: =abstract

Around line 16:

Unknown directive: =synopsis

Around line 28:

Unknown directive: =libraries

Around line 32:

Unknown directive: =description

Around line 38:

Unknown directive: =headers