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')->constraint('object', sub{
    $_->value->isa('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::Assert::Error)

The assertion method receives no arguments and should returns a Venus::Assert object.

assertion() (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) (Bool)

{ 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->coercion('string', sub{ucfirst(lc($_->value))});

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::Assert::Error)

t/Venus.t: pdml: authors t/Venus.t: pdml: 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 81:

Unknown directive: =description

Around line 90:

Unknown directive: =method

Around line 95:

Unknown directive: =signature

Around line 99:

Unknown directive: =metadata

Around line 135:

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

Around line 155:

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

Around line 165:

Unknown directive: =method

Around line 170:

Unknown directive: =signature

Around line 174:

Unknown directive: =metadata

Around line 200:

Unknown directive: =method

Around line 205:

Unknown directive: =signature

Around line 209:

Unknown directive: =metadata

Around line 245:

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

Around line 265:

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

Around line 275:

Unknown directive: =method

Around line 280:

Unknown directive: =signature

Around line 284:

Unknown directive: =metadata

Around line 327:

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

Around line 351:

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

Around line 361:

Unknown directive: =method

Around line 368:

Unknown directive: =signature

Around line 372:

Unknown directive: =metadata

Around line 408:

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

Around line 428:

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

Around line 438:

Unknown directive: =partials