Venus::Role::Optional

Optional Role

Optional Role for Perl 5

method: clear method: has method: reset

package Person;

use Venus::Class;

with 'Venus::Role::Optional';

attr 'fname';
attr 'lname';
attr 'email';

package main;

my $person = Person->new(
  fname => 'Elliot',
  lname => 'Alderson',
);

# bless({fname => 'Elliot', lname => 'Alderson'}, 'Person')

This package modifies the consuming package and provides methods for automating object construction and attribute accessors.

The clear method deletes an attribute and returns the removed value.

clear(string $name) (any)

{ since => '1.55', }

=example-1 clear

# given: synopsis

package main;

my $fname = $person->clear('fname');

# "Elliot"

The has method returns truthy if the attribute specified exists, otherwise returns falsy.

has(string $name) (boolean)

{ since => '1.55', }

=example-1 has

# given: synopsis

package main;

my $has_fname = $person->has('fname');

# true

The reset method rebuilds an attribute and returns the deleted value.

reset(string $name) (any)

{ since => '1.55', }

=example-1 reset

# given: synopsis

package main;

my $fname = $person->reset('fname');

# "Elliot"

This library provides a mechanism for automatically validating class attributes using Venus::Assert based on the return value of the attribute callback. The callback should be in the form of assert_${name}, and should return a Venus::Assert object or a "validation expression" (string) to be passed to the "expression" in Venus::Assert method.

This library provides a mechanism for automatically building class attributes on construction, and during getting and setting its value, after any default values are processed, based on the return value of the attribute callback. The callback should be in the form of build_${name}, and is passed any arguments provided.

This library provides a mechanism for automatically checking class attributes after getting or setting its value. The callback should be in the form of check_${name}, and is passed any arguments provided.

This library provides a mechanism for automatically coercing class attributes into class instances using Venus::Space based on the return value of the attribute callback. The callback should be in the form of coerce_${name}, and should return the name of the package to be constructed. That package will be instantiated via the customary new method, passing the data recevied as its arguments.

This library provides a mechanism for automatically defaulting class attributes to predefined values, statically or dynamically based on the return value of the attribute callback. The callback should be in the form of default_${name}, and should return the value to be used if no value exists or has been provided to the constructor.

This library provides a mechanism for automatically setting class attributes to predefined values, statically or dynamically based on the return value of the attribute callback. The callback should be in the form of initial_${name}, and should return the value to be used if no value has been provided to the constructor. This behavior is similar to the "defaulting" mechanism but is only executed during object construction.

This library provides a mechanism for automatically building class attributes during getting and setting its value, after any default values are processed, based on the return value of the attribute callback. The callback should be in the form of lazy_build_${name}, and is passed any arguments provided.

This library provides a mechanism for hooking into the class attribute reader (accessor) for reading values via the the attribute reader callback. The callback should be in the form of read_${name}, and should read and return the value for the attribute specified.

This library provides a mechanism for hooking into the class attribute writer (accessor) for writing values via the the attribute writer callback. The callback should be in the form of write_${name}, and should set and return the value for the attribute specified.

This library provides a mechanism for automatically validating class attributes using the attribute callback provided. The author is resposible for validating the state of the attribute and raising an exception when an attribute fails validation. The callback should be in the form of self_assert_${name}.

This library provides a mechanism for automatically coercing class attributes using the attribute callback provided. The author is resposible for any transformations to the attribute and value. The callback should be in the form of self_coerce_${name}.

This library provides a mechanism for automatically triggering routines after reading or writing class attributes via an attribute callback. The callback should be in the form of trigger_${name}, and will be invoked after the related attribute is read or written.

This library provides a mechanism for marking class attributes as "readonly" (or not) based on the return value of the attribute callback. The callback should be in the form of readonly_${name}, and should return truthy to automatically throw an exception if a change is attempted.

This library provides a mechanism for marking class attributes as "readwrite" (or not) based on the return value of the attribute callback. The callback should be in the form of readwrite_${name}, and should return falsy to automatically throw an exception if a change is attempted.

This library provides a mechanism for marking class attributes as "required" (i.e. to be provided to the constructor) based on the return value of the attribute callback. The callback should be in the form of require_${name}, and should return truthy to automatically throw an exception if the related attribute is missing.

t/Venus.t: present: authors t/Venus.t: present: license

68 POD Errors

The following errors were encountered while parsing the POD:

Around line 19:

Unknown directive: =name

Around line 27:

Unknown directive: =tagline

Around line 35:

Unknown directive: =abstract

Around line 43:

Unknown directive: =includes

Around line 53:

Unknown directive: =synopsis

Around line 88:

Unknown directive: =description

Around line 97:

Unknown directive: =method

Around line 101:

Unknown directive: =signature

Around line 105:

Unknown directive: =metadata

Around line 145:

=cut found outside a pod block. Skipping to next block.

Around line 168:

=cut found outside a pod block. Skipping to next block.

Around line 178:

Unknown directive: =method

Around line 183:

Unknown directive: =signature

Around line 187:

Unknown directive: =metadata

Around line 222:

=cut found outside a pod block. Skipping to next block.

Around line 231:

Unknown directive: =method

Around line 235:

Unknown directive: =signature

Around line 239:

Unknown directive: =metadata

Around line 279:

=cut found outside a pod block. Skipping to next block.

Around line 306:

=cut found outside a pod block. Skipping to next block.

Around line 319:

Unknown directive: =feature

Around line 360:

=cut found outside a pod block. Skipping to next block.

Around line 408:

=cut found outside a pod block. Skipping to next block.

Around line 451:

=cut found outside a pod block. Skipping to next block.

Around line 500:

=cut found outside a pod block. Skipping to next block.

Around line 527:

Unknown directive: =feature

Around line 588:

=cut found outside a pod block. Skipping to next block.

Around line 661:

=cut found outside a pod block. Skipping to next block.

Around line 721:

=cut found outside a pod block. Skipping to next block.

Around line 769:

=cut found outside a pod block. Skipping to next block.

Around line 810:

=cut found outside a pod block. Skipping to next block.

Around line 825:

Unknown directive: =feature

Around line 872:

=cut found outside a pod block. Skipping to next block.

Around line 935:

=cut found outside a pod block. Skipping to next block.

Around line 957:

Unknown directive: =feature

Around line 1012:

=cut found outside a pod block. Skipping to next block.

Around line 1074:

=cut found outside a pod block. Skipping to next block.

Around line 1124:

=cut found outside a pod block. Skipping to next block.

Around line 1141:

Unknown directive: =feature

Around line 1191:

=cut found outside a pod block. Skipping to next block.

Around line 1216:

Unknown directive: =feature

Around line 1267:

=cut found outside a pod block. Skipping to next block.

Around line 1293:

Unknown directive: =feature

Around line 1329:

=cut found outside a pod block. Skipping to next block.

Around line 1375:

=cut found outside a pod block. Skipping to next block.

Around line 1421:

=cut found outside a pod block. Skipping to next block.

Around line 1436:

Unknown directive: =feature

Around line 1488:

=cut found outside a pod block. Skipping to next block.

Around line 1508:

Unknown directive: =feature

Around line 1557:

=cut found outside a pod block. Skipping to next block.

Around line 1580:

Unknown directive: =feature

Around line 1625:

=cut found outside a pod block. Skipping to next block.

Around line 1682:

=cut found outside a pod block. Skipping to next block.

Around line 1740:

=cut found outside a pod block. Skipping to next block.

Around line 1763:

Unknown directive: =feature

Around line 1813:

=cut found outside a pod block. Skipping to next block.

Around line 1864:

=cut found outside a pod block. Skipping to next block.

Around line 1881:

Unknown directive: =feature

Around line 1940:

=cut found outside a pod block. Skipping to next block.

Around line 1969:

Unknown directive: =feature

Around line 2021:

=cut found outside a pod block. Skipping to next block.

Around line 2037:

Unknown directive: =feature

Around line 2089:

=cut found outside a pod block. Skipping to next block.

Around line 2105:

Unknown directive: =feature

Around line 2156:

=cut found outside a pod block. Skipping to next block.

Around line 2213:

=cut found outside a pod block. Skipping to next block.

Around line 2267:

=cut found outside a pod block. Skipping to next block.

Around line 2283:

Unknown directive: =partials