NAME
    Mo::utils::Number - Mo number utilities.

SYNOPSIS
     use Mo::utils::Number qw(check_int check_natural check_number check_percent check_positive_decimal check_positive_natural);

     check_int($self, $key);
     check_natural($self, $key);
     check_number($self, $key);
     check_percent($self, $key);
     check_positive_decimal($self, $key)
     check_positive_natural($self, $key);

DESCRIPTION
    Mo number utilities for checking of data objects.

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

    Check if the parameter defined by $key is an integer (... -2, -1, 0, 1,
    2, ...). Value could be undefined or doesn't exist.

    Put error if check isn't ok.

    Returns undef.

  "check_natural"
     check_natural($self, $key);

    Check if the parameter defined by $key is a natural number (0, 1, 2,
    ...). Value could be undefined or doesn't exist.

    Put error if check isn't ok.

    Returns undef.

  "check_number"
     check_number($self, $key);

    *Since version 0.02.*

    Check if the parameter defined by $key is a number. Number could be
    integer, float, exponencial and negative. Implementation is via
    "looks_like_number" in Scalar::Util.

    Put error if check isn't ok.

    Returns undef.

  "check_percent"
     check_percent($self, $key);

    Check if the parameter defined by $key is a percent. Value could be
    undefined or doesn't exist.

    Put error if check isn't ok.

    Returns undef.

  "check_positive_decimal"
     check_positive_decimal($self, $key)

    *Since version 0.05. Described functionality since version 0.08.*

    Check if the parameter defined by $key is a positive decimal number.
    Value could be undefined or doesn't exist. Check accepts numbers in
    scientific notation.

    Put error if check isn't ok.

    Returns undef.

  "check_positive_natural"
     check_positive_natural($self, $key);

    Check if the parameter defined by $key is a positive natural number (1,
    2, ...). Value could be undefined or doesn't exist.

    Put error if check isn't ok.

    Returns undef.

ERRORS
     check_int():
             Parameter '%s' must be a integer.
                     Value: %s
     check_natural():
             Parameter '%s' must be a natural number.
                     Value: %s
     check_number():
             Parameter '%s' must be a number.
                     Value: %s
     check_percent():
             Parameter '%s' has bad percent value.
                     Value: %s
             Parameter '%s' has bad percent value (missing %).
                     Value: %s
     check_positive_decimal():
             Parameter '%s' must be a positive decimal number.
                     Value: %s
     check_positive_natural():
             Parameter '%s' must be a positive natural number.
                     Value: %s

EXAMPLE1
     use strict;
     use warnings;

     use Mo::utils::Number qw(check_int);

     my $self = {
             'key' => -2,
     };
     check_int($self, 'key');

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE2
     use strict;
     use warnings;

     use Error::Pure;
     use Mo::utils::Number qw(check_int);

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

     my $self = {
             'key' => 1.2,
     };
     check_int($self, 'key');

     # Print out.
     print "ok\n";

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

EXAMPLE3
     use strict;
     use warnings;

     use Mo::utils::Number qw(check_natural);

     my $self = {
             'key' => 0,
     };
     check_natural($self, 'key');

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE4
     use strict;
     use warnings;

     use Error::Pure;
     use Mo::utils::Number qw(check_natural);

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

     my $self = {
             'key' => -2,
     };
     check_natural($self, 'key');

     # Print out.
     print "ok\n";

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

EXAMPLE5
     use strict;
     use warnings;

     use Mo::utils::Number qw(check_number);

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

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE6
     use strict;
     use warnings;

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

     use Mo::utils::Number qw(check_number);

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

     # Print out.
     print "ok\n";

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

EXAMPLE7
     use strict;
     use warnings;

     use Mo::utils::Number qw(check_percent);

     my $self = {
             'key' => '10%',
     };
     check_percent($self, 'key');

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE8
     use strict;
     use warnings;

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

     use Mo::utils::Number qw(check_percent);

     my $self = {
             'key' => 'foo',
     };
     check_percent($self, 'key');

     # Print out.
     print "ok\n";

     # Output like:
     # #Error [...Number.pm:?] Parameter 'key' has bad percent value.

EXAMPLE9
     use strict;
     use warnings;

     use Mo::utils::Number qw(check_positive_decimal);

     my $self = {
             'key' => 3.2,
     };
     check_positive_decimal($self, 'key');

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE10
     use strict;
     use warnings;

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

     use Mo::utils::Number qw(check_positive_decimal);

     my $self = {
             'key' => -1.2,
     };
     check_positive_decimal($self, 'key');

     # Print out.
     print "ok\n";

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

EXAMPLE11
     use strict;
     use warnings;

     use Mo::utils::Number qw(check_positive_natural);

     my $self = {
             'key' => '3',
     };
     check_positive_natural($self, 'key');

     # Print out.
     print "ok\n";

     # Output:
     # ok

EXAMPLE12
     use strict;
     use warnings;

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

     use Mo::utils::Number qw(check_positive_natural);

     my $self = {
             'key' => -1,
     };
     check_positive_natural($self, 'key');

     # Print out.
     print "ok\n";

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

DEPENDENCIES
    Error::Pure, Exporter, Readonly, Scalar::Util.

SEE ALSO
    Mo::utils::Number::Range
        Mo number utilities for ranges.

    Mo  Micro Objects. Mo is less.

    Mo::utils
        Mo utilities.

    Wikibase::Datatype::Utils
        Wikibase datatype utilities.

REPOSITORY
    <https://github.com/michal-josef-spacek/Mo-utils-Number>

AUTHOR
    Michal Josef Špaček <mailto:skim@cpan.org>

    <http://skim.cz>

LICENSE AND COPYRIGHT
    © 2024-2025 Michal Josef Špaček

    BSD 2-Clause License

VERSION
    0.08

