NAME
Venus::Validate - Validate Class
ABSTRACT
Validate Class for Perl 5
SYNOPSIS
package main;
use Venus::Validate;
my $validate = Venus::Validate->new('hello');
# $validate->string->trim->strip;
# bless(..., "Venus::Validate")
# $validate->is_valid;
# true
DESCRIPTION
This package provides a mechanism for performing data validation of simple and hierarchal data at runtime.
ATTRIBUTES
This package has the following attributes:
issue
issue(arrayref $issue) (arrayref)
The issue attribute is read/write, accepts (arrayref) values, and is optional.
Since 4.15
path
path(string $path) (string)
The path attribute is read/write, accepts (string) values, is optional, and defaults to ".".
Since 4.15
input
input(arrayref $input) (arrayref)
The input attribute is read/write, accepts (arrayref) values, and is optional.
Since 4.15
INHERITS
This package inherits behaviors from:
INTEGRATES
This package integrates behaviors from:
METHODS
This package provides the following methods:
arrayref
arrayref() (Venus::Validate)
The arrayref method is shorthand for calling "type" with "arrayref". This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- arrayref example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new([1,2]); my $arrayref = $validate->arrayref; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- arrayref example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({1..4}); my $arrayref = $validate->arrayref; # bless(..., "Venus::Validate") # $validate->is_valid; # false
- arrayref example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new([1..4]); my $arrayref = $validate->arrayref; # bless(..., "Venus::Validate") # $validate->is_valid; # true
boolean
boolean() (Venus::Validate)
The boolean method is shorthand for calling "type" with "boolean". This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- boolean example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(true); my $boolean = $validate->boolean; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- boolean example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(false); my $boolean = $validate->boolean; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- boolean example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(1); my $boolean = $validate->boolean; # bless(..., "Venus::Validate") # $validate->is_valid; # false
- boolean example 4
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(0); my $boolean = $validate->boolean; # bless(..., "Venus::Validate") # $validate->is_valid; # false
check
check(string $type, string $name, string | coderef $callback, any @args) (Venus::Validate)
The check method provides a mechanism for performing a custom data validation check. The first argument enables a data type check via "type" based on the type expression provided. The second argument is the name of the check being performed, which will be used by "issue_info" if the validation fails. The remaining arguments are used in the callback provided which performs the custom data validation.
Since 4.15
- check example 1
-
# given: synopsis package main; my $check = $validate->check; # bless(..., "Venus::Validate") # $check->is_valid; # true
- check example 2
-
# given: synopsis package main; my $check = $validate->check('string'); # bless(..., "Venus::Validate") # $check->is_valid; # true
- check example 3
-
# given: synopsis package main; my $check = $validate->check('string', 'is_email', sub{ /\w\@\w/ }); # bless(..., "Venus::Validate") # $check->is_valid; # false # $check->issue; # ['is_email', []]
- check example 4
-
# given: synopsis package main; $validate->value('hello@example.com'); my $check = $validate->check('string', 'is_email', sub{ /\w\@\w/ }); # bless(..., "Venus::Validate") # $check->is_valid; # true # $check->issue; # undef
defined
defined() (Venus::Validate)
The defined method is shorthand for calling "type" with "defined". This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- defined example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(''); my $defined = $validate->defined; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- defined example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(undef); my $defined = $validate->defined; # bless(..., "Venus::Validate") # $validate->is_valid; # false
- defined example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new; my $defined = $validate->defined; # bless(..., "Venus::Validate") # $validate->is_valid; # false
each
each(string $type, string $path) (within[arrayref, Venus::Validate])
The each method uses "select" to retrieve data and for each item, builds a Venus::Validate object for the value, settings the object to "present", "required" or "optional" based on the argument provided, executing the callback provided for each object, and returns list of objects created. Defaults to "optional" if no argument is provided. Returns a list in list context.
Since 4.15
- each example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(['hello', 'bonjour']); my $each = $validate->each; # [bless(..., "Venus::Validate"), ...]
- each example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(['hello', 'bonjour']); my @each = $validate->each; # (bless(..., "Venus::Validate"), ...)
- each example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(['hello', 'bonjour']); my $each = $validate->each('required'); # [bless(..., "Venus::Validate"), ...]
- each example 4
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({ greetings => ['hello', 'bonjour'], }); my $each = $validate->each('optional', 'greetings'); # [bless(..., "Venus::Validate"), ...]
errors
errors(arrayref $data) (arrayref)
The errors method gets and sets the arrayref used by the current object and all subsequent nodes to capture errors/issues encountered. Each element of the arrayref will be an arrayref consisting of the node's "path" and the "issue". This method returns a list in list context.
Since 4.15
- errors example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new([ { name => 'john', }, { name => 'jane', }, ]); $validate->errors([]); # [] my $required = $validate->required('2.name'); # bless(..., "Venus::Validate") my $errors = $validate->errors; # [['2.name', ['required', []]]]
- errors example 4
-
package main; use Venus::Validate; my $validate = Venus::Validate->new([ { name => 'john', }, { name => 'jane', }, ]); $validate->errors([]); # [] my $required = $validate->required('1.name'); # bless(..., "Venus::Validate") $required->min_length(10); # bless(..., "Venus::Validate") my $errors = $validate->errors; # [['1.name', ['min_length', [10]]]]
- errors example 5
-
package main; use Venus::Validate; my $validate = Venus::Validate->new([ { name => 'john', }, { name => 'jane', }, ]); $validate->errors([]); # [] my $name_0 = $validate->required('0.name'); # bless(..., "Venus::Validate") $name_0->min_length(10); # bless(..., "Venus::Validate") my $name_1 = $validate->required('1.name'); # bless(..., "Venus::Validate") $name_1->min_length(10); # bless(..., "Venus::Validate") my $errors = $validate->errors; # [['0.name', ['min_length', [10]]], ['1.name', ['min_length', [10]]]]
exists
exists() (boolean)
The exists method returns true if a value exists for the current object, and otherwise returns false.
Since 4.15
- exists example 2
-
# given: synopsis package main; $validate->value(undef); my $exists = $validate->exists; # true
- exists example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new; my $exists = $validate->exists; # false
float
float() (Venus::Validate)
The float method is shorthand for calling "type" with "float". This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- float example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(1.23); my $float = $validate->float; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- float example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(1_23); my $float = $validate->float; # bless(..., "Venus::Validate") # $validate->is_valid; # false
- float example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new("1.23"); my $float = $validate->float; # bless(..., "Venus::Validate") # $validate->is_valid; # true
hashref
hashref() (Venus::Validate)
The hashref method is shorthand for calling "type" with "hashref". This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- hashref example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({1,2}); my $hashref = $validate->hashref; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- hashref example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new([1..4]); my $hashref = $validate->hashref; # bless(..., "Venus::Validate") # $validate->is_valid; # false
- hashref example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({1..4}); my $hashref = $validate->hashref; # bless(..., "Venus::Validate") # $validate->is_valid; # true
is_invalid
is_invalid() (boolean)
The is_invalid method returns true if an issue exists, and false otherwise.
Since 4.15
- is_invalid example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello')->string; my $is_invalid = $validate->is_invalid; # false
- is_invalid example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello')->number; my $is_invalid = $validate->is_invalid; # true
is_valid
is_valid() (boolean)
The is_valid method returns true if no issue exists, and false otherwise.
Since 4.15
- is_valid example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello')->string; my $is_valid = $validate->is_valid; # true
- is_valid example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello')->number; my $is_valid = $validate->is_valid; # false
issue_args
issue_args() (arrayref)
The issue_args method returns the arguments provided as part of the issue context. Returns a list in list context.
Since 4.15
- issue_args example 1
-
# given: synopsis; $validate->issue(['max_length', ['255']]); my $issue_args = $validate->issue_args; # ['255']
issue_info
issue_info(string $type, any @args) (tuple[string, arrayref])
The issue_info method gets or sets the issue context and returns the "issue_type" and "issue_args". Returns a list in list context.
Since 4.15
- issue_info example 2
-
# given: synopsis; my $issue_info = $validate->issue_info('max_length', '255'); # ['max_length', ['255']]
- issue_info example 3
-
# given: synopsis; # given: example-2 issue_info $issue_info = $validate->issue_info; # ['max_length', ['255']]
- issue_info example 4
-
# given: synopsis; # given: example-2 issue_info my ($type, @args) = $validate->issue_info; # ('max_length', '255')
issue_type
issue_type() (string)
The issue_type method returns the issue type (i.e. type of issue) provided as part of the issue context.
Since 4.15
- issue_type example 1
-
# given: synopsis; $validate->issue(['max_length', ['255']]); my $issue_type = $validate->issue_type; # 'max_length'
length
length(number $min, number $max) (Venus::Validate)
The length method accepts a minimum and maximum and validates that the length of the data meets the criteria and returns the invocant. This method is a proxy for the "min_length" and "max_length" methods and the errors/issues encountered will be specific to those operations.
Since 4.15
- length example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(''); my $length = $validate->length(1, 3); # bless(..., "Venus::Validate") # $length->issue; # ['min_length', [1]]
- length example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello'); my $length = $validate->length(1, 3); # bless(..., "Venus::Validate") # $length->issue; # ['max_length', [3]]
lowercase
lowercase() (Venus::Validate)
The lowercase method lowercases the value and returns the invocant.
Since 4.15
- lowercase example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('Hello world'); my $lowercase = $validate->lowercase; # bless(..., "Venus::Validate") # $lowercase->value; # "hello world"
max_length
max_length(number $max) (Venus::Validate)
The max_length method accepts a maximum and validates that the length of the data meets the criteria and returns the invocant. This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- max_length example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello'); my $max_length = $validate->max_length(5); # bless(..., "Venus::Validate") # $max_length->issue; # undef
- max_length example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello'); my $max_length = $validate->max_length(3); # bless(..., "Venus::Validate") # $max_length->issue; # ['max_length', [3]]
max_number
max_number(number $max) (Venus::Validate)
The max_number accepts a maximum and validates that the data is exactly the number provided or less, and returns the invocant. This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- max_number example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(1); my $max_number = $validate->max_number(1); # bless(..., "Venus::Validate") # $max_number->issue; # undef
- max_number example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(1); my $max_number = $validate->max_number(0); # bless(..., "Venus::Validate") # $max_number->issue; # ['max_number', [0]]
min_length
min_length(number $min) (Venus::Validate)
The min_length accepts a minimum and validates that the length of the data meets the criteria and returns the invocant. This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- min_length example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello'); my $min_length = $validate->min_length(1); # bless(..., "Venus::Validate") # $min_length->issue; # undef
- min_length example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(''); my $min_length = $validate->min_length(1); # bless(..., "Venus::Validate") # $min_length->issue; # ['min_length', [1]]
min_number
min_number(number $min) (Venus::Validate)
The min_number accepts a minimum and validates that the data is exactly the number provided or greater, and returns the invocant. This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- min_number example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(1); my $min_number = $validate->min_number(1); # bless(..., "Venus::Validate") # $min_number->issue; # undef
- min_number example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(1); my $min_number = $validate->min_number(2); # bless(..., "Venus::Validate") # $min_number->issue; # ['min_number', [2]]
new
new(hashref $data) (Venus::Validate)
The new method returns a Venus::Validate object.
Since 4.15
- new example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new; # bless(..., "Venus::Validate")
- new example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(input => 'hello'); # bless(..., "Venus::Validate")
- new example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({input => 'hello'}); # bless(..., "Venus::Validate")
- new example 4
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello'); # bless(..., "Venus::Validate")
number
number() (Venus::Validate)
The number method is shorthand for calling "type" with "number". This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- number example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(123); my $number = $validate->number; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- number example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(1.23); my $number = $validate->number; # bless(..., "Venus::Validate") # $validate->is_valid; # false
- number example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(1_23); my $number = $validate->number; # bless(..., "Venus::Validate") # $validate->is_valid; # true
on_invalid
on_invalid(coderef $callback, any @args) (Venus::Validate)
The on_invalid method chains an operations by passing the issue value of the object to the callback provided and returns a Venus::Validate object.
Since 4.15
- on_invalid example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello')->number; my $on_invalid = $validate->on_invalid; # bless(..., "Venus::Validate")
- on_invalid example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello')->number; my $on_invalid = $validate->on_invalid(sub{ $validate->{called} = time; return $validate; }); # bless(..., "Venus::Validate")
on_valid
on_valid(coderef $callback, any @args) (Venus::Validate)
The on_valid method chains an operations by passing the value of the object to the callback provided and returns a Venus::Validate object.
Since 4.15
- on_valid example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello')->string; my $on_valid = $validate->on_valid; # bless(..., "Venus::Validate")
- on_valid example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello')->string; my $on_valid = $validate->on_valid(sub{ $validate->{called} = time; return $validate; }); # bless(..., "Venus::Validate")
optional
optional(string $path) (Venus::Validate)
The optional method uses "select" to retrieve data and returns a Venus::Validate object with the selected data marked as optional.
Since 4.15
- optional example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({ fname => 'John', lname => 'Doe', }); my $optional = $validate->optional('email'); # bless(..., "Venus::Validate") # $optional->is_valid; # true
- optional example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({ fname => 'John', lname => 'Doe', email => 'johndoe@example.com', }); my $optional = $validate->optional('email'); # bless(..., "Venus::Validate") # $optional->is_valid; # true
present
present(string $path) (Venus::Validate)
The present method uses "select" to retrieve data and returns a Venus::Validate object with the selected data marked as needing to be present. This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- present example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({ fname => 'John', lname => 'Doe', }); my $present = $validate->present('email'); # bless(..., "Venus::Validate") # $present->is_valid; # false
- present example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({ fname => 'John', lname => 'Doe', email => 'johndoe@example.com', }); my $present = $validate->present('email'); # bless(..., "Venus::Validate") # $present->is_valid; # true
required
required(string $path) (Venus::Validate)
The required method uses "select" to retrieve data and returns a Venus::Validate object with the selected data marked as required. This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- required example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({ fname => 'John', lname => 'Doe', }); my $required = $validate->required('email'); # bless(..., "Venus::Validate") # $present->is_valid; # false
- required example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({ fname => 'John', lname => 'Doe', email => 'johndoe@example.com', }); my $required = $validate->required('email'); # bless(..., "Venus::Validate") # $present->is_valid; # true
select
select(string $path) (Venus::Validate)
The select method uses "path" in Venus::Hash to retrieve data and returns a Venus::Validate object with the selected data. Returns undef if the data can't be selected.
Since 4.15
- select example 2
-
# given: synopsis; my $select = $validate->select('ello'); # bless(..., "Venus::Validate")
- select example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new([ { name => 'john', }, { name => 'jane', }, ]); my $select = $validate->select('0.name'); # bless(..., "Venus::Validate") # $select->value; # "john"
- select example 4
-
package main; use Venus::Validate; my $validate = Venus::Validate->new([ { name => 'john', }, { name => 'jane', }, ]); my $select = $validate->select('1.name'); # bless(..., "Venus::Validate") # $select->value; # "jane"
- select example 5
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({ persons => [ { name => 'john', }, { name => 'jane', }, ] }); my $select = $validate->select('persons.0.name'); # bless(..., "Venus::Validate") # $select->value; # "john"
- select example 6
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({ persons => [ { name => 'john', }, { name => 'jane', }, ] }); my $select = $validate->select('persons.1.name'); # bless(..., "Venus::Validate") # $select->value; # "jane"
string
string() (Venus::Validate)
The string method is shorthand for calling "type" with "string". This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- string example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello'); my $string = $validate->string; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- string example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(''); my $string = $validate->string; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- string example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('1.23'); my $string = $validate->string; # bless(..., "Venus::Validate") # $validate->is_valid; # false
strip
strip() (Venus::Validate)
The strip method removes multiple consecutive whitespace characters from the value and returns the invocant.
Since 4.15
- strip example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello world'); my $strip = $validate->strip; # bless(..., "Venus::Validate") # $strip->value; # "hello world"
- strip example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({text => 'hello world'}); my $strip = $validate->strip; # bless(..., "Venus::Validate") # $strip->value; # {text => 'hello world'}
sync
sync(Venus::Validate $node) (Venus::Validate)
The sync method merges the Venus::Validate node provided with the current object.
Since 4.15
- sync example 2
-
package main; use Venus::Validate; my $root = Venus::Validate->new({ persons => [ { name => 'john', }, { name => 'jane', }, ] }); my $node = $root->select('persons.1.name'); # bless(..., "Venus::Validate") $node->value('jack'); # "jack" # $root->select('persons.1.name')->value; # "john" $root->sync($node); # bless(..., "Venus::Validate") # $root->select('persons.1.name')->value; # "jack"
- sync example 3
-
package main; use Venus::Validate; my $root = Venus::Validate->new(['john', 'jane']); my $node = $root->select(1); # bless(..., "Venus::Validate") $node->value('jill'); # "jill" # $root->select(1)->value; # "jane" $root->sync($node); # bless(..., "Venus::Validate") # $root->select(1)->value; # "jill"
titlecase
titlecase() (Venus::Validate)
The titlecase method titlecases the value and returns the invocant.
Since 4.15
- titlecase example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello world'); my $titlecase = $validate->titlecase; # bless(..., "Venus::Validate") # $titlecase->value; # "Hello World"
trim
trim() (Venus::Validate)
The trim method removes whitespace characters from both ends of the value and returns the invocant.
Since 4.15
- trim example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(' hello world '); my $trim = $validate->trim; # bless(..., "Venus::Validate") # $trim->value; # "hello world"
- trim example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new({text => ' hello world '}); my $trim = $validate->trim; # bless(..., "Venus::Validate") # $trim->value; # {text => ' hello world '}
type
type(string $type) (Venus::Validate)
The type method validates that the value conforms with the Venus::Type type expression provided, and returns the invocant. This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- type example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello'); my $type = $validate->type; # bless(..., "Venus::Validate") # $type->is_valid; # true
- type example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello'); my $type = $validate->type('string'); # bless(..., "Venus::Validate") # $type->is_valid; # true
- type example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello'); my $type = $validate->type('number'); # bless(..., "Venus::Validate") # $type->is_valid; # false
- type example 4
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('Y'); my $type = $validate->type('yesno'); # bless(..., "Venus::Validate") # $type->is_valid; # true
- type example 5
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('A'); my $type = $validate->type('enum[A, B]'); # bless(..., "Venus::Validate") # $type->is_valid; # true
- type example 6
-
package main; use Venus::Validate; my $validate = Venus::Validate->new([200, [], '']); my $type = $validate->type('tuple[number, arrayref, string]'); # bless(..., "Venus::Validate") # $type->is_valid; # true
- type example 7
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(undef); my $type = $validate->type('string'); # bless(..., "Venus::Validate") # $type->is_valid; # true
- type example 8
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(undef); my $type = $validate->optional->type('string'); # bless(..., "Venus::Validate") # $type->is_valid; # true
uppercase
uppercase() (Venus::Validate)
The uppercase method uppercases the value and returns the invocant.
Since 4.15
- uppercase example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello world'); my $uppercase = $validate->uppercase; # bless(..., "Venus::Validate") # $uppercase->value; # "HELLO WORLD"
value
value() (any)
The value method returns the value being validated.
Since 4.15
yesno
yesno() (Venus::Validate)
The yesno method is shorthand for calling "type" with "yesno". This method is a validator and uses "issue_info" to capture validation errors.
Since 4.15
- yesno example 1
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('Yes'); my $yesno = $validate->yesno; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- yesno example 2
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('No'); my $yesno = $validate->yesno; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- yesno example 3
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(1); my $yesno = $validate->yesno; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- yesno example 4
-
package main; use Venus::Validate; my $validate = Venus::Validate->new(0); my $yesno = $validate->yesno; # bless(..., "Venus::Validate") # $validate->is_valid; # true
- yesno example 5
-
package main; use Venus::Validate; my $validate = Venus::Validate->new('hello'); my $yesno = $validate->yesno; # bless(..., "Venus::Validate") # $validate->is_valid; # false
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.