use
lib
qw( ./lib ./t/lib ../inc ./inc )
;
use
lib
qw( ./lib ./t/lib ../inc ./inc )
;
my
$type
= Int->plus_coercions(
Num,
q[ int($_) ]
,
ArrayRef,
q[ scalar(@$_) ]
,
);
my
$coercion
=
$type
->coercion;
my
(
$name
,
$code
,
$captures
,
$compiled_sub
) = @{
Sub::Quote::quoted_from_sub( \
&$coercion
);
};
ok(
defined
(
$code
),
'Got back code from Sub::Quote'
);
my
$coderef
=
eval
"sub { $code }"
;
is(
ref
(
$coderef
),
'CODE'
,
'... which compiles OK'
);
is(
$coderef
->(42),
42,
"... which passes through values that don't need to be coerced"
,
);
ok(
$coderef
->(3.1)==3 &&
$coderef
->([
qw/foo bar/
])==2,
"... coerces values that can be coerced"
,
);
is_deeply(
$coderef
->({
foo
=> 666}),
{
foo
=> 666},
"... and passes through any values it can't handle"
,
);
done_testing;