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::Role::Assertable(3) User Contributed Perl Documentation Venus::Role::Assertable(3)

Venus::Role::Assertable - Assertable Role

Assertable Role for Perl 5

  package Example;
  use Venus::Class;
  use Venus::Assert;
  with 'Venus::Role::Assertable';
  sub assertion {
    Venus::Assert->new('Example')->accept('Example')
  }
  package main;
  my $example = Example->new;
  # $example->check;

This package modifies the consuming package and requires methods for making the object assertable.

This package provides the following methods:

  assert(any $data) (any)

The assert method returns the data provided if it passes the registered type constraints, or throws an exception.

Since 1.23

assert example 1
  # given: synopsis
  package main;
  my $assert = $example->assert;
  # Exception! (isa Venus::Check::Error)
    
assert example 2
  # given: synopsis
  package main;
  my $assert = $example->assert({});
  # Exception! (isa Venus::Check::Error)
    
assert example 3
  # given: synopsis
  package main;
  my $assert = $example->assert($example);
  # bless({}, "Example")
    

  assertion() (Venus::Assert)

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

Since 1.23

assertion example 1
  package main;
  my $example = Example->new;
  my $assertion = $example->assertion;
  # bless({name => "Example"}, "Venus::Assert")
    

  check(any $data) (boolean)

The check method returns true if the data provided passes the registered type constraints, or returns false.

Since 1.23

check example 1
  # given: synopsis
  package main;
  my $check = $example->check;
  # 0
    
check example 2
  # given: synopsis
  package main;
  my $check = $example->check({});
  # 0
    
check example 3
  # given: synopsis
  package main;
  my $check = $example->check($example);
  # 1
    

  coerce(any $data) (any)

The coerce method returns a coerced value if the data provided matches any of the registered type coercions, or returns the data provided.

Since 1.23

coerce example 1
  # given: synopsis
  package main;
  my $assertion = $example->assertion;
  $assertion->match('string')->format(sub{ucfirst(lc($_))});
  my $coerce = $assertion->coerce;
  # undef
    
coerce example 2
  # given: synopsis
  package main;
  my $assertion = $example->assertion;
  $assertion->match('string')->format(sub{ucfirst(lc($_))});
  my $coerce = $assertion->coerce({});
  # {}
    
coerce example 3
  # given: synopsis
  package main;
  my $assertion = $example->assertion;
  $assertion->match('string')->format(sub{ucfirst(lc($_))});
  my $coerce = $assertion->coerce('hello');
  # "Hello"
    

  make(any $data) (object)

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.

Since 1.23

make example 1
  # given: synopsis
  package main;
  my $make = $example->make;
  # Exception! (isa Venus::Check::Error)
    
make example 2
  # given: synopsis
  package main;
  my $make = $example->make($example);
  # bless({}, "Example")
    
make example 3
  # given: synopsis
  package main;
  my $make = $example->make({});
  # Exception! (isa Venus::Check::Error)
    

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.