NAME

Smart::Options::Declare - DSL for Smart::Options

SYNOPSIS

use Smart::Options::Declare;

opts my $rif => 'Int', my $xup => 'Num';

if ($rif - 5 * $xup > 7.138) {
    say 'Buy more fiffiwobbles';
}
else {
   say 'Sell the xupptumblers';
}

# $ ./example.pl --rif=55 --xup=9.52
# Buy more fiffiwobbles
#
# $ ./example.pl --rif 12 --xup 8.1
# Sell the xupptumblers

DESCRIPTION

Smart::Options::Declare is a library which offers DSL for Smart::Options.

METHOD

opts $var => TYPE, $var2 => { isa => TYPE, RULE => ... }

set option value to variable.

use Smart::Options::Declare;

opts my $var => 'Str', my $value => { isa => 'Int', default => 4 };

opts_coerce ( NewType, Source, Generater )

define new type and convert logic.

opts_coerce Time => 'Str', sub { Time::Piece->strptime($_[0]) }

opts my $time => 'Time';

$time->hour;

RULE

isa define option value type. see "TYPES".

required define option value is required.

default define options default value. If passed a coderef, it will be executed if no value is provided on the command line.

alias define option param's alias.

comment this comment is used to generate help. help can show --help

TYPES

Str

Int

Num

Bool

ArrayRef

HashRef

Multiple

This subtype is based off of ArrayRef. It will attempt to split any values passed on the command line on a comma: that is,

opts my $foo => 'ArrayRef';
# script.pl --foo=one --foo=two,three
# => ['one', 'two,three']

will become

opts my $foo => 'Multiple';
# script.pl --foo=one --foo=two,three
# => ['one', 'two', 'three']

AUTHOR

Kan Fushihara <kan.fushihara@gmail.com>

SEE ALSO

opts

LICENSE

Copyright (C) Kan Fushihara

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