Venus::Schema - Schema Class
Schema Class for Perl 5
package main; use Venus::Schema; my $schema = Venus::Schema->new; # bless({...}, 'Venus::Schema')
This package provides methods for validating whether objects and complex data structures conform to a schema.
This package has the following attributes:
definition(hashref $data) (hashref)
The definition attribute is read-write, accepts (HashRef) values, and is optional.
(HashRef)
Since 2.55
2.55
# given: synopsis package main; my $definition = $schema->definition({}); # {}
# given: synopsis # given: example-1 definition package main; $definition = $schema->definition; # {}
This package inherits behaviors from:
Venus::Kind::Utility
This package provides the following methods:
assert() (Venus::Assert)
The assert method builds and returns a Venus::Assert object based on the "definition".
# given: synopsis package main; my $assert = $schema->assert; # bless({...}, 'Venus::Assert')
# given: synopsis package main; $schema->definition({ name => 'string', }); my $assert = $schema->assert; # bless({...}, 'Venus::Assert')
check(hashref $data) (boolean)
The check method builds an assert object using "assert" and returns the result of the "check" in Venus::Assert method.
# given: synopsis package main; my $check = $schema->check; # false
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $check = $schema->check({}); # false
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $check = $schema->check({ name => 'someone', role => {}, }); # false
# 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(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.
# given: synopsis package main; my $deduce = $schema->deduce; # Exception! (isa Venus::Check::Error)
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $deduce = $schema->deduce({}); # Exception! (isa Venus::Check::Error)
# 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)
# 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(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.
# given: synopsis package main; my $error = $schema->error; # Exception! (isa Venus::Check::Error)
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $error = $schema->error({}); # Exception! (isa Venus::Check::Error)
# 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)
# 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(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.
# given: synopsis package main; my $validate = $schema->validate; # Exception! (isa Venus::Check::Error)
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $validate = $schema->validate({}); # Exception! (isa Venus::Check::Error)
# 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)
# 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,},}
Awncorp, awncorp@cpan.org
awncorp@cpan.org
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.
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.