Data::Object::ClassHas
Data-Object Class Attribute Builder
package Point; use Data::Object::Class; use Data::Object::ClassHas; has 'x'; has 'y'; 1;
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.
has
This package uses type constraints defined by:
Data::Object::Library
This package automatically exports the following keywords.
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.
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.
is
# 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.
isa
# 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.
required
# 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.
optional
# 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.
builder
# 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.
clearer
# 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.
coerce
# 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.
default
# 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.
handles
# 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.
lazy
# 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.
predicate
# 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.
reader
# 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.
trigger
# 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.
weak_ref
# 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.
writer
Al Newkirk, +296
+296
Anthony Brummett, +10
+10
José Joaquín Atria, +1
+1
Al Newkirk, awncorp@cpan.org
awncorp@cpan.org
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.
GitHub
Projects
Milestones
Contributing
Issues
To get the most out of this distribution, consider reading the following:
Do
Data::Object
Data::Object::Class
Data::Object::Role
Data::Object::RoleHas
To install Do, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Do
CPAN shell
perl -MCPAN -e shell install Do
For more information on module installation, please visit the detailed CPAN module installation guide.