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: new 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 new method constructs an instance of the package.
new(any @args) (Venus::Assert)
{ since => '4.15', }
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 => '4.15', }
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
109 POD Errors
The following errors were encountered while parsing the POD:
- Around line 16:
Unknown directive: =name
- Around line 24:
Unknown directive: =tagline
- Around line 32:
Unknown directive: =abstract
- Around line 40:
Unknown directive: =includes
- Around line 64:
Unknown directive: =synopsis
- Around line 90:
Unknown directive: =description
- Around line 101:
Unknown directive: =inherits
- Around line 109:
Unknown directive: =integrates
- Around line 117:
Unknown directive: =attribute
- Around line 122:
Unknown directive: =signature
- Around line 126:
Unknown directive: =metadata
- Around line 144:
=cut found outside a pod block. Skipping to next block.
- Around line 166:
=cut found outside a pod block. Skipping to next block.
- Around line 176:
Unknown directive: =method
- Around line 181:
Unknown directive: =signature
- Around line 185:
Unknown directive: =metadata
- Around line 239:
=cut found outside a pod block. Skipping to next block.
- Around line 289:
=cut found outside a pod block. Skipping to next block.
- Around line 343:
=cut found outside a pod block. Skipping to next block.
- Around line 360:
Unknown directive: =method
- Around line 365:
Unknown directive: =signature
- Around line 369:
Unknown directive: =metadata
- Around line 387:
=cut found outside a pod block. Skipping to next block.
- Around line 409:
=cut found outside a pod block. Skipping to next block.
- Around line 419:
Unknown directive: =method
- Around line 424:
Unknown directive: =signature
- Around line 428:
Unknown directive: =metadata
- Around line 448:
=cut found outside a pod block. Skipping to next block.
- Around line 461:
Unknown directive: =method
- Around line 466:
Unknown directive: =signature
- Around line 470:
Unknown directive: =metadata
- Around line 492:
=cut found outside a pod block. Skipping to next block.
- Around line 517:
=cut found outside a pod block. Skipping to next block.
- Around line 528:
Unknown directive: =method
- Around line 533:
Unknown directive: =signature
- Around line 537:
Unknown directive: =metadata
- Around line 555:
=cut found outside a pod block. Skipping to next block.
- Around line 577:
=cut found outside a pod block. Skipping to next block.
- Around line 587:
Unknown directive: =method
- Around line 593:
Unknown directive: =signature
- Around line 597:
Unknown directive: =metadata
- Around line 655:
=cut found outside a pod block. Skipping to next block.
- Around line 671:
Unknown directive: =method
- Around line 676:
Unknown directive: =signature
- Around line 680:
Unknown directive: =metadata
- Around line 698:
=cut found outside a pod block. Skipping to next block.
- Around line 720:
=cut found outside a pod block. Skipping to next block.
- Around line 730:
Unknown directive: =method
- Around line 735:
Unknown directive: =signature
- Around line 739:
Unknown directive: =metadata
- Around line 761:
=cut found outside a pod block. Skipping to next block.
- Around line 775:
Unknown directive: =method
- Around line 781:
Unknown directive: =signature
- Around line 785:
Unknown directive: =metadata
- Around line 843:
=cut found outside a pod block. Skipping to next block.
- Around line 882:
=cut found outside a pod block. Skipping to next block.
- Around line 926:
=cut found outside a pod block. Skipping to next block.
- Around line 982:
=cut found outside a pod block. Skipping to next block.
- Around line 999:
Unknown directive: =method
- Around line 1004:
Unknown directive: =signature
- Around line 1008:
Unknown directive: =metadata
- Around line 1030:
=cut found outside a pod block. Skipping to next block.
- Around line 1044:
Unknown directive: =method
- Around line 1048:
Unknown directive: =signature
- Around line 1052:
Unknown directive: =metadata
- Around line 1070:
=cut found outside a pod block. Skipping to next block.
- Around line 1091:
=cut found outside a pod block. Skipping to next block.
- Around line 1112:
=cut found outside a pod block. Skipping to next block.
- Around line 1123:
Unknown directive: =method
- Around line 1129:
Unknown directive: =signature
- Around line 1133:
Unknown directive: =metadata
- Around line 1169:
=cut found outside a pod block. Skipping to next block.
- Around line 1189:
=cut found outside a pod block. Skipping to next block.
- Around line 1209:
=cut found outside a pod block. Skipping to next block.
- Around line 1229:
=cut found outside a pod block. Skipping to next block.
- Around line 1249:
=cut found outside a pod block. Skipping to next block.
- Around line 1269:
=cut found outside a pod block. Skipping to next block.
- Around line 1289:
=cut found outside a pod block. Skipping to next block.
- Around line 1309:
=cut found outside a pod block. Skipping to next block.
- Around line 1332:
=cut found outside a pod block. Skipping to next block.
- Around line 1364:
=cut found outside a pod block. Skipping to next block.
- Around line 1379:
Unknown directive: =method
- Around line 1384:
Unknown directive: =signature
- Around line 1388:
Unknown directive: =metadata
- Around line 1406:
=cut found outside a pod block. Skipping to next block.
- Around line 1427:
=cut found outside a pod block. Skipping to next block.
- Around line 1447:
=cut found outside a pod block. Skipping to next block.
- Around line 1467:
=cut found outside a pod block. Skipping to next block.
- Around line 1494:
=cut found outside a pod block. Skipping to next block.
- Around line 1504:
Unknown directive: =method
- Around line 1511:
Unknown directive: =signature
- Around line 1515:
Unknown directive: =metadata
- Around line 1535:
=cut found outside a pod block. Skipping to next block.
- Around line 1558:
=cut found outside a pod block. Skipping to next block.
- Around line 1570:
Unknown directive: =method
- Around line 1575:
Unknown directive: =signature
- Around line 1579:
Unknown directive: =metadata
- Around line 1601:
=cut found outside a pod block. Skipping to next block.
- Around line 1626:
=cut found outside a pod block. Skipping to next block.
- Around line 1637:
Unknown directive: =method
- Around line 1643:
Unknown directive: =signature
- Around line 1647:
Unknown directive: =metadata
- Around line 1667:
=cut found outside a pod block. Skipping to next block.
- Around line 1690:
=cut found outside a pod block. Skipping to next block.
- Around line 1702:
Unknown directive: =method
- Around line 1707:
Unknown directive: =signature
- Around line 1711:
Unknown directive: =metadata
- Around line 1762:
=cut found outside a pod block. Skipping to next block.
- Around line 1774:
Unknown directive: =partials