Venus::Role::Assertable
Assertable Role
Assertable Role for Perl 5
method: assert method: assertion method: check method: coerce method: make
package Example;
use Venus::Class;
use Venus::Assert;
with 'Venus::Role::Assertable';
sub assertion {
Venus::Assert->new('Example')->accept('Example')
}
package main;
my $example = Example->new;
# $example->check;
This package modifies the consuming package and requires methods for making the object assertable.
The assert method returns the data provided if it passes the registered type constraints, or throws an exception.
assert(any $data) (any)
{ since => '1.23', }
=example-1 assert
# given: synopsis
package main;
my $assert = $example->assert;
# Exception! (isa Venus::Check::Error)
The assertion method receives no arguments and should returns a Venus::Assert object.
assertion() (Venus::Assert)
{ since => '1.23', }
=example-1 assertion
package main;
my $example = Example->new;
my $assertion = $example->assertion;
# bless({name => "Example"}, "Venus::Assert")
The check method returns true if the data provided passes the registered type constraints, or returns false.
check(any $data) (boolean)
{ since => '1.23', }
=example-1 check
# given: synopsis
package main;
my $check = $example->check;
# 0
The coerce method returns a coerced value if the data provided matches any of the registered type coercions, or returns the data provided.
coerce(any $data) (any)
{ since => '1.23', }
=example-1 coerce
# given: synopsis
package main;
my $assertion = $example->assertion;
$assertion->match('string')->format(sub{ucfirst(lc($_))});
my $coerce = $assertion->coerce;
# undef
The make method returns an instance of the invocant, if the data provided passes the registered type constraints, allowing for any coercion, or throws an exception. If the data provided is itself an instance of the invocant it will be returned unaltered.
make(any $data) (object)
{ since => '1.23', }
=example-1 make
# given: synopsis
package main;
my $make = $example->make;
# Exception! (isa Venus::Check::Error)
t/Venus.t: present: authors t/Venus.t: present: license
30 POD Errors
The following errors were encountered while parsing the POD:
- Around line 13:
Unknown directive: =name
- Around line 21:
Unknown directive: =tagline
- Around line 29:
Unknown directive: =abstract
- Around line 37:
Unknown directive: =includes
- Around line 49:
Unknown directive: =synopsis
- Around line 79:
Unknown directive: =description
- Around line 88:
Unknown directive: =method
- Around line 93:
Unknown directive: =signature
- Around line 97:
Unknown directive: =metadata
- Around line 133:
=cut found outside a pod block. Skipping to next block.
- Around line 153:
=cut found outside a pod block. Skipping to next block.
- Around line 163:
Unknown directive: =method
- Around line 168:
Unknown directive: =signature
- Around line 172:
Unknown directive: =metadata
- Around line 198:
Unknown directive: =method
- Around line 203:
Unknown directive: =signature
- Around line 207:
Unknown directive: =metadata
- Around line 243:
=cut found outside a pod block. Skipping to next block.
- Around line 263:
=cut found outside a pod block. Skipping to next block.
- Around line 273:
Unknown directive: =method
- Around line 278:
Unknown directive: =signature
- Around line 282:
Unknown directive: =metadata
- Around line 325:
=cut found outside a pod block. Skipping to next block.
- Around line 349:
=cut found outside a pod block. Skipping to next block.
- Around line 359:
Unknown directive: =method
- Around line 366:
Unknown directive: =signature
- Around line 370:
Unknown directive: =metadata
- Around line 406:
=cut found outside a pod block. Skipping to next block.
- Around line 426:
=cut found outside a pod block. Skipping to next block.
- Around line 436:
Unknown directive: =partials