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() (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) (Bool)
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({}); # 0
- check example 3
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $check = $schema->check({ name => 'someone', role => {}, }); # 0
- 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, }, }); # 1
deduce
deduce(HashRef $data) (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::Assert::Error)
- deduce example 2
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $deduce = $schema->deduce({}); # Exception! (isa Venus::Assert::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::Assert::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) (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::Assert::Error)
- error example 2
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $error = $schema->error({}); # Exception! (isa Venus::Assert::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::Assert::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::Assert::Error)
- validate example 2
-
# given: synopsis package main; $schema->definition({ name => 'string', role => { title => 'string', level => 'number', }, }); my $validate = $schema->validate({}); # Exception! (isa Venus::Assert::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::Assert::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) 2000, Al Newkirk.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.