declare
"SmallInteger"
,
as
"Integer"
,
where {
no
warnings;
$_
< 10 }
message {
no
warnings;
"$_ is too big"
};
declare
"BigInteger"
,
as
"Integer"
,
where {
no
warnings;
$_
>= 10 };
{
our
$VERSION
= 1;
}
role_type
"DoesQuux"
, {
role
=>
"Quux"
};
{
sub
new {
my
$c
=
shift
;
bless
{
@_
},
$c
}
sub
foo { 1 }
sub
bar { 2 }
}
class_type
"FooBar"
, {
class
=>
"Foo::Bar"
};
{
our
@ISA
=
"Foo::Bar"
;
sub
DOES {
return
1
if
$_
[1] eq
'Quux'
;
$_
[0]->isa(
$_
[0]);
}
sub
foo { 3 }
sub
baz { 4 }
}
class_type
"Foo::Baz"
;
duck_type
"CanFooBar"
, [
qw/ foo bar /
];
duck_type
"CanFooBaz"
, [
qw/ foo baz /
];
coerce
"SmallInteger"
,
from
BigInteger
=> via {
abs
(
$_
) % 10 },
from
ArrayRef
=> via { 1 };
coerce
"BigInteger"
,
from
SmallInteger
=> via {
abs
(
$_
) + 10 },
from
ArrayRef
=> via { 100 };
declare_coercion
"ArrayRefFromAny"
, to_type
"ArrayRef"
, from
"Any"
,
q {
[
$_
] };
declare_coercion
"ArrayRefFromPiped"
, to_type
"ArrayRef"
, from
"Str"
,
q {
[
split
/\\|/] };
1;