NAME
Venus::Schema - Schema Class
ABSTRACT
Schema Class for Perl 5
SYNOPSIS
package main;
use Venus::Schema;
my $schema = Venus::Schema->new;
# bless({...}, 'Venus::Schema')
DESCRIPTION
This package provides methods for validating whether objects and complex data structures conform to a schema.
ATTRIBUTES
This package has the following attributes:
definition
definition(hashref $data) (hashref)
The definition attribute is read-write, accepts (HashRef)
values, and is optional.
Since 2.55
- definition example 2
-
# given: synopsis # given: example-1 definition package main; $definition = $schema->definition; # {}
INHERITS
This package inherits behaviors from:
METHODS
This package provides the following methods:
assert
assert() (Venus::Assert)
The assert method builds and returns a Venus::Assert object based on the "definition".
Since 2.55
- assert example 1
-
# given: synopsis package main; my $assert = $schema->assert; # bless({...}, 'Venus::Assert')
- assert example 2
-
# given: synopsis package main; $schema->definition({ name => 'string', }); my $assert = $schema->assert; # bless({...}, 'Venus::Assert')
check
check(hashref $data) (boolean)
The check method builds an assert object using "assert" and returns the result of the "check" in Venus::Assert method.
Since 2.55
- check example 2
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $check = $schema->check({}); # false
- check example 3
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $check = $schema->check({ name => 'someone', role => {}, }); # false
- check example 4
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $check = $schema->check({ name => 'someone', role => { title => 'engineer', level => 1, }, }); # true
deduce
deduce(hashref $data) (Venus::Hash)
The deduce method builds an assert object using "assert" and validates the value provided using "validate" in Venus::Assert, passing the result to "deduce_deep" in Venus::Type unless the validation throws an exception.
Since 2.55
- deduce example 1
-
# given: synopsis package main; my $deduce = $schema->deduce; # Exception! (isa Venus::Check::Error)
- deduce example 2
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $deduce = $schema->deduce({}); # Exception! (isa Venus::Check::Error)
- deduce example 3
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $deduce = $schema->deduce({ name => 'someone', role => {}, }); # Exception! (isa Venus::Check::Error)
- deduce example 4
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $deduce = $schema->deduce({ name => 'someone', role => { title => 'engineer', level => 1, }, }); # bless({...}, 'Venus::Hash')
error
error(hashref $data) (Venus::Error)
The error method builds an assert object using "assert" and validates the value provided using "validate" in Venus::Assert, catching any error thrown and returning it, otherwise returning undefined.
Since 2.55
- error example 1
-
# given: synopsis package main; my $error = $schema->error; # Exception! (isa Venus::Check::Error)
- error example 2
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $error = $schema->error({}); # Exception! (isa Venus::Check::Error)
- error example 3
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $error = $schema->error({ name => 'someone', role => {}, }); # Exception! (isa Venus::Check::Error)
- error example 4
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $error = $schema->error({ name => 'someone', role => { title => 'engineer', level => 1, }, }); # undef
validate
validate(hashref $data) (hashref)
The validate method builds an assert object using "assert" and validates the value provided using "validate" in Venus::Assert, returning the result unless the validation throws an exception.
Since 2.55
- validate example 1
-
# given: synopsis package main; my $validate = $schema->validate; # Exception! (isa Venus::Check::Error)
- validate example 2
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $validate = $schema->validate({}); # Exception! (isa Venus::Check::Error)
- validate example 3
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $validate = $schema->validate({ name => 'someone', role => {}, }); # Exception! (isa Venus::Check::Error)
- validate example 4
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $validate = $schema->validate({ name => 'someone', role => { title => 'engineer', level => 1, }, }); # {name => 'someone', role => {title => 'engineer', level => 1,},}
AUTHORS
Awncorp, awncorp@cpan.org
LICENSE
Copyright (C) 2022, Awncorp, awncorp@cpan.org
.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.