NAME

Getopt::Pad::Type::Number - Base class of the numeric option types

SYNOPSIS

use Object::Pad;
use Getopt::Pad::Type;
use Getopt::Pad::Type::Number;

# A numeric type that accepts only multiples of 5, with min and max.
class My::Type::Five :isa(Getopt::Pad::Type::Number) {
    use constant NAMES => ['five'];

    method checkFormat($value) {
        return undef if $value =~ /\A-?[0-9]+\z/ && $value % 5 == 0;
        return sprintf("'%s' is not a multiple of 5", $value);
    }
}

Getopt::Pad::Type::registerType('My::Type::Five');

DESCRIPTION

The common base class of Getopt::Pad::Type::Int and Getopt::Pad::Type::Float. It is abstract: specs cannot use it directly, but you can subclass it for numeric types of your own.

It provides:

  • the spec keys min and max (inclusive bounds). When the spec is built, both must be numbers and min must not be larger than max; otherwise the spec is invalid (min must be a number, not 'VALUE', min MIN is larger than max MAX);

  • the value check: first the subclass's checkFormat, then the bounds (VALUE is smaller than the minimum of MIN, VALUE is larger than the maximum of MAX), compared after the value and the bound went through coerce;

  • the conversion of the value to a number;

  • glSuffix '=s': every numeric type takes a value.

A subclass provides NAMES and one method:

checkFormat($value)

Returns undef when $value has the right format, otherwise a short description of the problem without the option name. It runs before the bounds are checked, so the bounds only ever see numbers.

See Getopt::Pad::Type for the rest of the type contract.

SEE ALSO

Getopt::Pad::Type, Getopt::Pad::Type::Int, Getopt::Pad::Type::Float

AUTHOR

davenonymous <perl@davenonymous.com>

COPYRIGHT AND LICENSE

Copyright 2026 davenonymous

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.