BEGIN {
-base,
-declare
=>
qw[ StrList ]
;
declare StrList, as ArrayRef [Str];
coerce StrList, from Str,
q {
[
$_
] };
};
sub
a {
validate(
\
@_
,
slurpy Dict [
connect
=> Optional [Bool],
encoding
=> Optional [Str],
hg
=> Optional [Types::StrList],
]
);
}
sub
b {
validate(
\
@_
,
slurpy Dict [
connect
=> Optional [Bool],
hg
=> Optional [Types::StrList],
]
);
}
sub
c {
validate(
\
@_
,
slurpy Dict [
connect
=> Optional [Bool],
encoding
=> Optional [Str],
hg2
=> Optional [Types::StrList->no_coercions->plus_coercions(Types::Standard::Str,
sub
{[
$_
]})],
]
);
}
my
$expect
= {
connect
=> 1,
hg
=> [
'a'
],
};
my
$expect2
= {
connect
=> 1,
hg2
=> [
'a'
],
};
{
my
(
$opts
,
$e
);
$e
= exception { (
$opts
) = a(
connect
=> 1,
hg
=> [
'a'
] ) }
and diag
$e
;
is_deeply(
$opts
,
$expect
,
"StrList ArrayRef"
);
}
{
my
(
$opts
,
$e
);
$e
= exception { (
$opts
) = a(
connect
=> 1,
hg
=>
'a'
) }
and diag
$e
;
is_deeply(
$opts
,
$expect
,
"StrList scalar"
);
}
{
my
(
$opts
,
$e
);
$e
= exception { (
$opts
) = b(
connect
=> 1,
hg
=> [
'a'
] ) }
and diag
$e
;
is_deeply(
$opts
,
$expect
,
"StrList ArrayRef"
);
}
{
my
(
$opts
,
$e
);
$e
= exception { (
$opts
) = b(
connect
=> 1,
hg
=>
'a'
) }
and diag
$e
;
is_deeply(
$opts
,
$expect
,
"StrList scalar"
);
}
{
my
(
$opts
,
$e
);
$e
= exception { (
$opts
) = c(
connect
=> 1,
hg2
=> [
'a'
] ) }
and diag
$e
;
is_deeply(
$opts
,
$expect2
,
"StrList ArrayRef - noninline"
);
}
{
my
(
$opts
,
$e
);
$e
= exception { (
$opts
) = c(
connect
=> 1,
hg2
=>
'a'
) }
and diag
$e
;
is_deeply(
$opts
,
$expect2
,
"StrList scalar - noninline"
);
}
done_testing;