GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Venus::Schema(3) User Contributed Perl Documentation Venus::Schema(3)

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.

Since 2.55

definition example 1
  # given: synopsis
  package main;
  my $definition = $schema->definition({});
  # {}
    
definition example 2
  # 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".

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(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 1
  # given: synopsis
  package main;
  my $check = $schema->check;
  # false
    
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(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(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(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,},}
    

Awncorp, "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.

2023-11-27 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.