NAME
Mo::utils - Mo utilities.
SYNOPSIS
check_bool check_code check_isa check_length check_length_fix check_number
check_number_id check_number_min check_number_of_items check_number_range
check_regexp check_required check_string check_string_begin check_strings)
;
check_angle(
$self
,
$key
);
check_array(
$self
,
$key
);
check_array_object(
$self
,
$key
,
$class
,
$class_name
);
check_array_required(
$self
,
$key
);
check_bool(
$self
,
$key
);
check_code(
$self
,
$key
);
check_isa(
$self
,
$key
,
$class
);
check_length(
$self
,
$key
,
$max_length
);
check_length_fix(
$self
,
$key
,
$length
);
check_number(
$self
,
$key
);
check_number_id(
$self
,
$key
);
check_number_min(
$self
,
$key
,
$min
);
check_number_of_items(
$self
,
$list_method
,
$item_method
,
$object_name
,
$item_name
);
check_number_range(
$self
,
$key
,
$min
,
$max
);
check_regexp(
$self
,
$key
,
$regexp
);
check_required(
$self
,
$key
);
check_string(
$self
,
$key
,
$string
);
check_string_begin(
$self
,
$key
,
$string_base
);
check_strings(
$self
,
$key
,
$strings_ar
);
DESCRIPTION
Mo utilities for checking of data objects.
SUBROUTINES
check_angle
check_angle(
$self
,
$key
);
Since version 0.20.
Check parameter defined by $key
which is number between 0 and 360.
Put error if check isn't ok.
Returns undef.
check_array
check_array(
$self
,
$key
);
Since version 0.06.
Check parameter defined by $key
which is reference to array.
Put error if check isn't ok.
Returns undef.
check_array_object
check_array_object(
$self
,
$key
,
$class
,
$class_name
);
Since version 0.02. Described functionality since version 0.21.
Check parameter defined by $key
which is reference to array with instances of some object type ($class
). $class_name
is used to error message.
Put error if check isn't ok.
Returns undef.
check_array_required
check_array_required(
$self
,
$key
);
Since version 0.18. Described functionality since version 0.19.
Check parameter defined by $key
which is reference to array for at least one value inside.
Put error if check isn't ok.
Returns undef.
check_bool
check_bool(
$self
,
$key
);
Since version 0.06.
Check parameter defined by $key
if value is bool or not.
Put error if check isn't ok.
Returns undef.
check_code
check_code(
$self
,
$key
);
Since version 0.12.
Check parameter defined by $key
which is code reference or no.
Put error if check isn't ok.
Returns undef.
check_isa
check_isa(
$self
,
$key
,
$class
);
Since version 0.01. Described functionality since version 0.08.
Check parameter defined by $key
which is instance of $class
or no.
Put error if check isn't ok.
Returns undef.
check_length
check_length(
$self
,
$key
,
$max_length
);
Since version 0.04. Described functionality since version 0.05.
Check length of value for parameter defined by $key
. Maximum length is defined by $max_length
.
Put error if check isn't ok.
Returns undef.
check_length_fix
check_length_fix(
$self
,
$key
,
$length
);
Since version 0.22.
Check fixed length of value for parameter defined by $key
. Length is defined by $length
variable.
Put error if check isn't ok.
Returns undef.
check_number
check_number(
$self
,
$key
);
Since version 0.01. Described functionality since version 0.26.
Check parameter defined by $key
which is number (positive or negative) or no. Number could be integer, float, exponencial and negative.
Put error if check isn't ok.
Returns undef.
check_number_id
check_number_id(
$self
,
$key
);
Since version 0.28.
Check parameter defined by $key
which is number which could be used as id in computer systems. This number is a natural number beginning from 1 (1, 2, 3, …).
Put error if check isn't ok.
Returns undef.
check_number_min
check_number_min(
$self
,
$key
,
$min
);
Since version 0.25. Described functionality since version 0.26.
Check parameter defined by $key
which is number greater than $min
value. Number could be integer, float, exponencial and negative.
Put error if check isn't ok.
Returns undef.
check_number_of_items
check_number_of_items(
$self
,
$list_method
,
$item_method
,
$object_name
,
$item_name
);
Since version 0.01.
Check amount of unique items defined by $item_method
method value. List items via $list_method
and get value via $item_method
method. $object_name
and $item_name
are variables for error output.
Put error if check isn't ok.
Returns undef.
check_number_range
check_number_range(
$self
,
$key
,
$min
,
$max
);
Since version 0.23. Described functionality since version 0.26.
Check if number defined by $key
is in range between $min
and $max
. Number could be integer, float, exponencial and negative.
Put error if check isn't ok.
Returns undef.
check_regexp
check_regexp(
$self
,
$key
,
$regexp
);
Since version 0.17.
Check parameter defined by $key
via regular expression defined by $regexp
.
Put error if check isn't ok.
Returns undef.
check_required
check_required(
$self
,
$key
);
Since version 0.01.
Check required parameter defined by $key
.
Put error if check isn't ok.
Returns undef.
check_string
check_string(
$self
,
$key
,
$string
);
Since version 0.24.
Check string defined by $key
to expected value.
Put error if check isn't ok.
Returns undef.
check_string_begin
check_string_begin(
$self
,
$key
,
$string_base
);
Since version 0.16.
Check parameter if it is correct string which begins with base.
Put error if string base doesn't exist. Put error string base isn't present in string on begin.
Returns undef.
check_strings
check_strings(
$self
,
$key
,
$strings_ar
);
Since version 0.15.
Check parameter if it is correct string from strings list.
Put error if strings definition is undef or not list of strings. Put error if check isn't ok.
Returns undef.
ERRORS
check_angle():
From check_number():
Parameter
'%s'
must be a number.
Value:
%s
Parameter
'%s'
must be a number between 0 and 360.
Value:
%s
check_array():
Parameter
'%s'
must be a array.
Value:
%s
Reference:
%s
check_array_object():
Parameter
'%s'
must be a array.
Value:
%s
Reference:
%s
%s
isn
't '
%s
' object.
Value:
%s
Reference:
%s
check_array_required():
Parameter
'%s'
is required.
Parameter
'%s'
must be a array.
Value:
%s
Reference:
%s
Parameter
'%s'
with
array must have at least one item.
check_bool():
Parameter
'%s'
must be a bool (0/1).
Value:
%s
check_code():
Parameter
'%s'
must be a code.
Value:
%s
check_isa():
Parameter
'%s'
must be a
'%s'
object.
Value:
%s
Reference:
%s
check_length():
Parameter
'%s'
has
length
greater than
'%s'
.
Value:
%s
check_length_fix():
Parameter
'%s'
has
length
different than
'%s'
.
Value:
%s
check_number():
Parameter
'%s'
must be a number.
Value:
%s
check_number_id():
Parameter
'%s'
must be a natural number.
Value:
%s
check_number_min():
Parameter
'%s'
must be a number.
Value:
%s
Parameter
'%s'
must be greater than
%s
.
Value:
%s
check_number_of_items():
%s
for
%s
'%s'
has
multiple
values
.
check_number_range():
Parameter
'%s'
must be a number.
Value:
%s
Parameter
'%s'
must be a number between
%s
and
%s
.",
Value:
%s
check_regexp():
Parameter
'%s'
must have
defined
regexp.
Parameter
'%s'
does not match the specified regular expression.
String:
%s
Regexp:
%s
check_required():
Parameter
'%s'
is required.
check_string():
Parameter
'%s'
must have expected value.
Value:
%s
Expected value:
%s
check_string_begin():
Parameter
'%s'
must have
defined
string base.
Parameter
'%s'
must begin
with
defined
string base.
String:
%s
String base:
%s
check_strings():
Parameter
'%s'
must have strings definition.
Parameter
'%s'
must have right string definition.
Parameter
'%s'
must be one of
defined
strings.
String:
%s
Possible strings:
%s
EXAMPLE1
EXAMPLE2
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
'key'
=> 400,
};
check_angle(
$self
,
'key'
);
# Print out.
"ok\n"
;
# Output like:
# #Error [..utils.pm:?] Parameter 'key' must be a number between 0 and 360.
EXAMPLE3
EXAMPLE4
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
'key'
=>
'foo'
,
};
check_array(
$self
,
'key'
);
# Print out.
"ok\n"
;
# Output like:
# #Error [..utils.pm:?] Parameter 'key' must be a array.
EXAMPLE5
use
strict;
use
warnings;
use
Test::MockObject;
my
$self
= {
'key'
=> [
Test::MockObject->new,
],
};
check_array_object(
$self
,
'key'
,
'Test::MockObject'
,
'Value'
);
# Print out.
"ok\n"
;
# Output:
# ok
EXAMPLE6
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
'key'
=> [
'foo'
,
],
};
check_array_object(
$self
,
'key'
,
'Test::MockObject'
,
'Value'
);
# Print out.
"ok\n"
;
# Output like:
# #Error [..utils.pm:?] Value isn't 'Test::MockObject' object.
EXAMPLE7
EXAMPLE8
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
'key'
=> [],
};
check_array_required(
$self
,
'key'
);
# Print out.
"ok\n"
;
# Output like:
# #Error [..utils.pm:?] Parameter 'key' with array must have at least one item.
EXAMPLE9
use
strict;
use
warnings;
use
Test::MockObject;
my
$self
= {
'key'
=> 1,
};
check_bool(
$self
,
'key'
);
# Print out.
"ok\n"
;
# Output:
# ok
EXAMPLE10
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
'key'
=>
'bad'
,
};
check_bool(
$self
,
'key'
);
# Print out.
"ok\n"
;
# Output like:
# #Error [..utils.pm:?] Parameter 'key' must be a bool (0/1).
EXAMPLE11
use
strict;
use
warnings;
use
Test::MockObject;
my
$self
= {
'key'
=>
sub
{},
};
check_code(
$self
,
'key'
);
# Print out.
"ok\n"
;
# Output:
# ok
EXAMPLE12
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
'key'
=>
'bad'
,
};
check_code(
$self
,
'key'
);
# Print out.
"ok\n"
;
# Output like:
# #Error [..utils.pm:?] Parameter 'key' must be a code.
EXAMPLE13
use
strict;
use
warnings;
use
Test::MockObject;
my
$self
= {
'key'
=> Test::MockObject->new,
};
check_isa(
$self
,
'key'
,
'Test::MockObject'
);
# Print out.
"ok\n"
;
# Output:
# ok
EXAMPLE14
EXAMPLE15
EXAMPLE16
EXAMPLE17
EXAMPLE18
EXAMPLE19
EXAMPLE20
EXAMPLE21
EXAMPLE22
EXAMPLE23
EXAMPLE24
EXAMPLE25
use
strict;
use
warnings;
use
Test::MockObject;
$Error::Pure::TYPE
=
'Error'
;
# Item object #1.
my
$item1
= Test::MockObject->new;
$item1
->mock(
'value'
,
sub
{
return
'value1'
,
});
# Item object #1.
my
$item2
= Test::MockObject->new;
$item2
->mock(
'value'
,
sub
{
return
'value2'
,
});
# Tested object.
my
$self
= Test::MockObject->new({
'key'
=> [],
});
$self
->mock(
'list'
,
sub
{
return
[
$item1
,
$item2
,
];
});
# Check number of items.
check_number_of_items(
$self
,
'list'
,
'value'
,
'Test'
,
'Item'
);
# Print out.
"ok\n"
;
# Output like:
# ok
EXAMPLE26
use
strict;
use
warnings;
use
Test::MockObject;
$Error::Pure::TYPE
=
'Error'
;
# Item object #1.
my
$item1
= Test::MockObject->new;
$item1
->mock(
'value'
,
sub
{
return
'value1'
,
});
# Item object #2.
my
$item2
= Test::MockObject->new;
$item2
->mock(
'value'
,
sub
{
return
'value1'
,
});
# Tested object.
my
$self
= Test::MockObject->new({
'key'
=> [],
});
$self
->mock(
'list'
,
sub
{
return
[
$item1
,
$item2
,
];
});
# Check number of items.
check_number_of_items(
$self
,
'list'
,
'value'
,
'Test'
,
'Item'
);
# Print out.
"ok\n"
;
# Output like:
# #Error [...utils.pm:?] Test for Item 'value1' has multiple values.
EXAMPLE27
EXAMPLE28
EXAMPLE29
EXAMPLE30
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
};
# Print out.
"ok\n"
;
# Output like:
# #Error [...utils.pm:?] Parameter 'key' does not match the specified regular expression.
EXAMPLE31
EXAMPLE32
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
'key'
=>
undef
,
};
check_required(
$self
,
'key'
);
# Print out.
"ok\n"
;
# Output like:
# #Error [...utils.pm:?] Parameter 'key' is required.
EXAMPLE33
EXAMPLE34
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
'key'
=>
'bad'
,
};
check_string(
$self
,
'key'
,
'foo'
);
# Print out.
"ok\n"
;
# Output like:
# #Error [...utils.pm:?] Parameter 'key' have expected value.
EXAMPLE35
EXAMPLE36
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
};
# Print out.
"ok\n"
;
# Output like:
# #Error [...utils.pm:?] Parameter 'key' must begin with defined string base.
EXAMPLE37
EXAMPLE38
use
strict;
use
warnings;
use
Error::Pure;
$Error::Pure::TYPE
=
'Error'
;
my
$self
= {
'key'
=>
'bar'
,
};
check_strings(
$self
,
'key'
, [
'foo'
,
'value'
]);
# Print out.
"ok\n"
;
# Output like:
# #Error [...utils.pm:?] Parameter 'key' must be one of defined strings.
DEPENDENCIES
Exporter, Error::Pure, List::Utils, Readonly, Scalar::Util.
SEE ALSO
- Mo
-
Micro Objects. Mo is less.
- Mo::utils::Language
-
Mo language utilities.
- Mo::utils::CSS
-
Mo CSS utilities.
- Wikibase::Datatype::Utils
-
Wikibase datatype utilities.
REPOSITORY
https://github.com/michal-josef-spacek/Mo-utils
AUTHOR
Michal Josef Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2020-2024 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.29