Venus::Assert

Assert Class

Assert Class for Perl 5

method: accept method: check method: clear method: coerce method: coercion method: conditions method: constraint method: ensure method: expression method: format method: parse method: render method: result method: valid method: validate method: validator

package main;

use Venus::Assert;

my $assert = Venus::Assert->new('Float');

# $assert->accept('float');

# $assert->format(sub{sprintf('%.2f', $_)});

# $assert->result(123.456);

# 123.46

This package provides a mechanism for asserting type constraints and coercions on data. Type constraints are handled via Venus::Constraint, and coercions are handled via Venus::Coercion, using Venus::Check to perform data type validations.

Venus::Kind::Utility

Venus::Role::Buildable

The name attribute is read-write, accepts (string) values, and is optional.

name(string $data) (string)

{ since => '1.40', }

The accept method registers a condition via "check" based on the arguments provided. The built-in types are defined as methods in Venus::Check.

accept(string $name, any @args) (Venus::Assert)

{ since => '1.40', }

=example-1 accept

# given: synopsis

package main;

$assert = $assert->accept('float');

# bless(..., "Venus::Assert")

# $assert->valid;

# false

# $assert->valid(1.01);

# true

The check method gets or sets the Venus::Check object used for performing runtime data type validation.

check(Venus::Check $data) (Venus::Check)

{ since => '3.55', }

The clear method resets the "check", "constraint", and "coercion" attributes and returns the invocant.

clear() (Venus::Assert)

{ since => '1.40', }

The coerce method dispatches to the "coercion" object and returns the result of the "result" in Venus::Coercion operation.

coerce(any $data) (any)

{ since => '3.55', }

The coercion method gets or sets the Venus::Coercion object used for performing runtime data type coercions.

coercion(Venus::Coercion $data) (Venus::Coercion)

{ since => '3.55', }

The conditions method is an object construction hook that allows subclasses to configure the object on construction setting up constraints and coercions and returning the invocant.

conditions() (Venus::Assert)

{ since => '1.40', }

=example-1 conditions

# given: synopsis

package main;

$assert = $assert->conditions;

# bless(..., 'Venus::Assert')

The constraint method gets or sets the Venus::Constraint object used for performing runtime data type constraints.

constraint(Venus::Constraint $data) (Venus::Constraint)

{ since => '3.55', }

The ensure method registers a custom (not built-in) constraint condition and returns the invocant.

ensure(coderef $code) (Venus::Assert)

{ since => '3.55', }

The expression method parses a string representation of an type assertion, registers the subexpressions using the "accept" method, and returns the invocant.

expression(string $expr) (Venus::Assert)

{ since => '1.71', }

=example-1 expression

# given: synopsis

package main;

$assert = $assert->expression('string');

# bless(..., 'Venus::Assert')

# $assert->valid('hello');

# true

# $assert->valid(['goodbye']);

# false

The format method registers a custom (not built-in) coercion condition and returns the invocant.

format(coderef $code) (Venus::Assert)

{ since => '3.55', }

The parse method accepts a string representation of a type assertion and returns a data structure representing one or more method calls to be used for validating the assertion signature.

parse(string $expr) (any)

{ since => '2.01', }

=example-1 parse

# given: synopsis

package main;

my $parsed = $assert->parse('');

# ['']

The render method builds and returns a type expressions suitable for providing to "expression" based on the data provided.

render(string $into, string $expression) (string)

{ since => '2.55', }

The result method validates the value provided against the registered constraints and if valid returns the result of the value having any registered coercions applied. If the value is invalid an exception from Venus::Check will be thrown.

result(any $data) (any)

{ since => '3.55', }

The valid method dispatches to the "constraint" object and returns the result of the "result" in Venus::Constraint operation.

valid(any $data) (any)

{ since => '3.55', }

The validate method validates the value provided against the registered constraints and if valid returns the value. If the value is invalid an exception from Venus::Check will be thrown.

validate(any $data) (any)

{ since => '3.55', }

The validator method returns a coderef which calls the "validate" method with the invocant when called.

validator(any @args) (coderef)

{ since => '3.55', }

=example-1 validator

# given: synopsis

package main;

$assert->accept('string');

my $validator = $assert->validator;

# sub{...}

# my $result = $validator->();

# Exception! (isa Venus::Check::Error) (see error_on_coded)

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

103 POD Errors

The following errors were encountered while parsing the POD:

Around line 15:

Unknown directive: =name

Around line 23:

Unknown directive: =tagline

Around line 31:

Unknown directive: =abstract

Around line 39:

Unknown directive: =includes

Around line 62:

Unknown directive: =synopsis

Around line 88:

Unknown directive: =description

Around line 99:

Unknown directive: =inherits

Around line 107:

Unknown directive: =integrates

Around line 115:

Unknown directive: =attribute

Around line 120:

Unknown directive: =signature

Around line 124:

Unknown directive: =metadata

Around line 142:

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

Around line 164:

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

Around line 174:

Unknown directive: =method

Around line 179:

Unknown directive: =signature

Around line 183:

Unknown directive: =metadata

Around line 237:

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

Around line 287:

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

Around line 341:

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

Around line 358:

Unknown directive: =method

Around line 363:

Unknown directive: =signature

Around line 367:

Unknown directive: =metadata

Around line 385:

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

Around line 407:

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

Around line 417:

Unknown directive: =method

Around line 422:

Unknown directive: =signature

Around line 426:

Unknown directive: =metadata

Around line 446:

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

Around line 459:

Unknown directive: =method

Around line 464:

Unknown directive: =signature

Around line 468:

Unknown directive: =metadata

Around line 490:

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

Around line 515:

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

Around line 526:

Unknown directive: =method

Around line 531:

Unknown directive: =signature

Around line 535:

Unknown directive: =metadata

Around line 553:

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

Around line 575:

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

Around line 585:

Unknown directive: =method

Around line 591:

Unknown directive: =signature

Around line 595:

Unknown directive: =metadata

Around line 653:

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

Around line 669:

Unknown directive: =method

Around line 674:

Unknown directive: =signature

Around line 678:

Unknown directive: =metadata

Around line 696:

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

Around line 718:

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

Around line 728:

Unknown directive: =method

Around line 733:

Unknown directive: =signature

Around line 737:

Unknown directive: =metadata

Around line 759:

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

Around line 773:

Unknown directive: =method

Around line 779:

Unknown directive: =signature

Around line 783:

Unknown directive: =metadata

Around line 841:

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

Around line 880:

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

Around line 924:

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

Around line 980:

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

Around line 997:

Unknown directive: =method

Around line 1002:

Unknown directive: =signature

Around line 1006:

Unknown directive: =metadata

Around line 1028:

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

Around line 1042:

Unknown directive: =method

Around line 1048:

Unknown directive: =signature

Around line 1052:

Unknown directive: =metadata

Around line 1088:

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

Around line 1108:

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

Around line 1128:

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

Around line 1148:

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

Around line 1168:

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

Around line 1188:

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

Around line 1208:

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

Around line 1228:

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

Around line 1256:

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

Around line 1287:

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

Around line 1301:

Unknown directive: =method

Around line 1306:

Unknown directive: =signature

Around line 1310:

Unknown directive: =metadata

Around line 1328:

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

Around line 1348:

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

Around line 1368:

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

Around line 1388:

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

Around line 1413:

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

Around line 1423:

Unknown directive: =method

Around line 1430:

Unknown directive: =signature

Around line 1434:

Unknown directive: =metadata

Around line 1454:

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

Around line 1477:

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

Around line 1489:

Unknown directive: =method

Around line 1494:

Unknown directive: =signature

Around line 1498:

Unknown directive: =metadata

Around line 1520:

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

Around line 1545:

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

Around line 1556:

Unknown directive: =method

Around line 1562:

Unknown directive: =signature

Around line 1566:

Unknown directive: =metadata

Around line 1586:

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

Around line 1609:

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

Around line 1621:

Unknown directive: =method

Around line 1626:

Unknown directive: =signature

Around line 1630:

Unknown directive: =metadata

Around line 1681:

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

Around line 1693:

Unknown directive: =partials