The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Term::CLI::Argument::TypeTiny - class for Type::Tiny validated arguments in Term::CLI

VERSION

version 0.059000

SYNOPSIS

 use Term::CLI::Argument::TypeTiny;
 use Types::Standard qw( ArrayRef Split );
 use Types::Common::String qw( NonEmptyStr );

 # accept a comma separated list of strings, split them and return an array
 my $arg = Term::CLI::Argument::TypeTiny->new(
     name => 'arg1',
     typetiny => ArrayRef->of(NonEmptyStr)->plus_coercions(Split[qr/,/]),
     coerce => 1,
 );

DESCRIPTION

Class for Type::Tiny validated arguments in Term::CLI(3p).

This class inherits from the Term::CLI::Argument(3p) class.

CLASS STRUCTURE

Inherits from:

Term::CLI::Argument(3p).

Consumes:

None.

CONSTRUCTORS

new
    OBJ = Term::CLI::Argument::TypeTiny(
        name         => STRING,
        typetiny     => InstanceOf['Type::Tiny'],
        coerce       => Bool,
    );

See also Term::CLI::Argument(3p). The typetiny argument is mandatory and must be a Type::Tiny(3p) object. It will be used to validate values.

If coerce is true, validate will call the Type::Tiny object's coercion method to coerce the input value.

ACCESSORS

See also Term::CLI::Argument(3p).

typetiny

The Type::Tiny object which will validate values.

coerce

Boolean that indicates whether validate will call the Type::Tiny object's coercion method to coerce the input value.

METHODS

See also Term::CLI::Argument(3p).

The following methods are added or overloaded:

validate

Overloaded from Term::CLI::Argument(3p).

EXAMPLES

  • Only allow positive or zero numbers for # of zombies seen. Allow non integers, in case they've lost bits and pieces:

        use Types::Common::Numeric qw( PositiveOrZeroNum);
        my $arg = Term::CLI::Argument::TypeTiny(
            name => 'zombies',
            typetiny => PositiveOrZeroNum
        );
  • Accept a URI, convert to a URI object:

        use Types::URI 'URI';
        my $arg = Term::CLI::Argument::TypeTiny(
            name => 'uri',
            typetiny => URI,
            coerce => 1
        );
  • Accept a file which must exist, convert to a Path::Tiny object:

        use Types::Path::Tiny 'File';
        my $arg = Term::CLI::Argument::TypeTiny(
            name => 'file',
            typetiny => File,
            coerce => 1
        );

SEE ALSO

Term::CLI::Argument(3p), Term::CLI(3p), Type::Tiny(3p).

AUTHOR

Diab Jerius <djerius@cpan.org>, 2022.

COPYRIGHT AND LICENSE

Copyright (c) 2022 Diab Jerius, Smithsonian Astrophysical Observatory

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See "perldoc perlartistic."

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.