<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    Mo::utils - Mo utilities.

SYNOPSIS
     use Mo::utils qw(check_array check_array_object check_bool check_isa check_length check_number check_number_of_items check_required);

     check_array($self, $key);
     check_array_object($self, $key, $class, $class_name);
     check_bool($self, $key);
     check_isa($self, $key, $class);
     check_length($self, $key, $max_length);
     check_number($self, $key);
     check_number_of_items($self, $list_method, $item_method, $object_name, $item_name);
     check_required($self, $key);

DESCRIPTION
    Mo utilities for checking of data objects.

SUBROUTINES
  "check_array"
     check_array($self, $key);

    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);

    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_bool"
     check_bool($self, $key);

    Check parameter defined by $key if value is bool or not.

    Put error if check isn't ok.

    Returns undef.

  "check_isa"
     check_isa($self, $key, $class);

    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);

    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_number"
     check_number($self, $key);

    Check parameter defined by $key which is number (positive or negative)
    or no.

    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);

    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_required"
     check_required($self, $key);

    Check required parameter defined by $key.

    Put error if check isn't ok.

    Returns undef.

ERRORS
     check_array():
             Parameter '%s' must be a array.
                     Value: %s
                     Reference: %s

     check_array_object():
             Parameter '%s' must be a array.
             %s isn't '%s' object.

     check_bool():
             Parameter '%s' must be a bool (0/1).
                     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_number():
             Parameter '%s' must a number.
                     Value: %s

     check_number_of_items():
             %s for %s '%s' has multiple values.

     check_required():
             Parameter '%s' is required.

EXAMPLE1
     use strict;
     use warnings;

     use Mo::utils qw(check_array);

     my $self = {
             'key' =&gt; ['foo'],
     };
     check_array($self, 'key');

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE2
     use strict;
     use warnings;

     use Error::Pure;
     use Mo::utils qw(check_array);

     $Error::Pure::TYPE = 'Error';

     my $self = {
             'key' =&gt; 'foo',
     };
     check_array($self, 'key');

     # Print out.
     print "ok\n";

     # Output like:
     # #Error [..utils.pm:?] Parameter 'key' must be a array.

EXAMPLE3
     use strict;
     use warnings;

     use Mo::utils qw(check_array_object);
     use Test::MockObject;

     my $self = {
             'key' =&gt; [
                     Test::MockObject-&gt;new,
             ],
     };
     check_array_object($self, 'key', 'Test::MockObject', 'Value');

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE4
     use strict;
     use warnings;

     use Error::Pure;
     use Mo::utils qw(check_array_object);

     $Error::Pure::TYPE = 'Error';

     my $self = {
             'key' =&gt; [
                     'foo',
             ],
     };
     check_array_object($self, 'key', 'Test::MockObject', 'Value');

     # Print out.
     print "ok\n";

     # Output like:
     # #Error [..utils.pm:?] Value isn't 'Test::MockObject' object.

EXAMPLE5
     use strict;
     use warnings;

     use Mo::utils qw(check_isa);
     use Test::MockObject;

     my $self = {
             'key' =&gt; Test::MockObject-&gt;new,
     };
     check_isa($self, 'key', 'Test::MockObject');

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE6
     use strict;
     use warnings;

     $Error::Pure::TYPE = 'Error';

     use Mo::utils qw(check_isa);

     my $self = {
             'key' =&gt; 'foo',
     };
     check_isa($self, 'key', 'Test::MockObject');

     # Print out.
     print "ok\n";

     # Output like:
     # #Error [...utils.pm:?] Parameter 'key' must be a 'Test::MockObject' object.

EXAMPLE7
     use strict;
     use warnings;

     $Error::Pure::TYPE = 'Error';

     use Mo::utils qw(check_length);

     my $self = {
             'key' =&gt; 'foo',
     };
     check_length($self, 'key', 3);

     # Print out.
     print "ok\n";

     # Output like:
     # ok

EXAMPLE8
     use strict;
     use warnings;

     $Error::Pure::TYPE = 'Error';

     use Mo::utils qw(check_length);

     my $self = {
             'key' =&gt; 'foo',
     };
     check_length($self, 'key', 2);

     # Print out.
     print "ok\n";

     # Output like:
     # #Error [...utils.pm:?] Parameter 'key' has length greater than '2'.

EXAMPLE9
     use strict;
     use warnings;

     use Mo::utils qw(check_number);

     my $self = {
             'key' =&gt; '10',
     };
     check_number($self, 'key');

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE10
     use strict;
     use warnings;

     $Error::Pure::TYPE = 'Error';

     use Mo::utils qw(check_number);

     my $self = {
             'key' =&gt; 'foo',
     };
     check_number($self, 'key');

     # Print out.
     print "ok\n";

     # Output like:
     # #Error [...utils.pm:?] Parameter 'key' must be a number.

EXAMPLE11
     use strict;
     use warnings;

     use Test::MockObject;

     $Error::Pure::TYPE = 'Error';

     use Mo::utils qw(check_number_of_items);

     # Item object #1.
     my $item1 = Test::MockObject-&gt;new;
     $item1-&gt;mock('value', sub {
            return 'value1',
     });

     # Item object #1.
     my $item2 = Test::MockObject-&gt;new;
     $item2-&gt;mock('value', sub {
            return 'value2',
     });

     # Tested object.
     my $self = Test::MockObject-&gt;new({
            'key' =&gt; [],
     });
     $self-&gt;mock('list', sub {
            return [
                    $item1,
                    $item2,
            ];
     });

     # Check number of items.
     check_number_of_items($self, 'list', 'value', 'Test', 'Item');

     # Print out.
     print "ok\n";

     # Output like:
     # ok

EXAMPLE12
     use strict;
     use warnings;

     use Test::MockObject;

     $Error::Pure::TYPE = 'Error';

     use Mo::utils qw(check_number_of_items);

     # Item object #1.
     my $item1 = Test::MockObject-&gt;new;
     $item1-&gt;mock('value', sub {
            return 'value1',
     });

     # Item object #2.
     my $item2 = Test::MockObject-&gt;new;
     $item2-&gt;mock('value', sub {
            return 'value1',
     });

     # Tested object.
     my $self = Test::MockObject-&gt;new({
            'key' =&gt; [],
     });
     $self-&gt;mock('list', sub {
            return [
                    $item1,
                    $item2,
            ];
     });

     # Check number of items.
     check_number_of_items($self, 'list', 'value', 'Test', 'Item');

     # Print out.
     print "ok\n";

     # Output like:
     # #Error [...utils.pm:?] Test for Item 'value1' has multiple values.

EXAMPLE13
     use strict;
     use warnings;

     use Mo::utils qw(check_required);

     my $self = {
             'key' =&gt; 'value',
     };
     check_required($self, 'key');

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE14
     use strict;
     use warnings;

     use Error::Pure;
     use Mo::utils qw(check_required);

     $Error::Pure::TYPE = 'Error';

     my $self = {
             'key' =&gt; undef,
     };
     check_required($self, 'key');

     # Print out.
     print "ok\n";

     # Output like:
     # #Error [...utils.pm:?] Parameter 'key' is required.

DEPENDENCIES
    Exporter, Error::Pure, Readonly.

SEE ALSO
    Mo  Micro Objects. Mo is less.

REPOSITORY
    &lt;https://github.com/michal-josef-spacek/Mo-utils&gt;

AUTHOR
    Michal Josef Ĺ&nbsp;paÄŤek &lt;mailto:skim@cpan.org&gt;

    &lt;http://skim.cz&gt;

LICENSE AND COPYRIGHT
    Â© Michal Josef Ĺ&nbsp;paÄŤek 2020-2022

    BSD 2-Clause License

VERSION
    0.10

</pre></body></html>