#!./perl
BEGIN {
chdir
't'
if
-d
't'
;
require
'./test.pl'
;
set_up_inc(
'../lib'
);
}
no
warnings
qw( experimental::class experimental::builtin )
;
{
class Testcase1 {
field
$x
:param;
method x {
return
$x
; }
}
my
$obj
= Testcase1->new(
x
=> 123);
is(
$obj
->x, 123,
'Value of $x set by constructor'
);
is(
ref
$obj
,
"Testcase1"
,
'ref of $obj'
);
is(blessed
$obj
,
"Testcase1"
,
'blessed of $obj'
);
is(reftype
$obj
,
"OBJECT"
,
'reftype of $obj'
);
is(
$obj
+0, builtin::refaddr(
$obj
),
'numified object'
);
like(
"$obj"
,
qr/^Testcase1=OBJECT\(0x[[:xdigit:]]+\)$/
,
'stringified object'
);
ok(!
eval
{ Testcase1->new(
x
=> 123,
y
=> 456); 1 },
'Unrecognised parameter fails'
);
like($@,
qr/^Unrecognised parameters for "Testcase1" constructor: y at /
,
'Exception thrown by constructor for unrecogniser parameter'
);
}
{
class Testcase2 {
'0+'
=>
sub
{
return
12345 },
'""'
=>
sub
{
"<Testcase2 instance>"
},
fallback
=> 1;
}
my
$obj
= Testcase2->new;
is(
$obj
+0, 12345,
'numified object with overload'
);
is(
"$obj"
,
"<Testcase2 instance>"
,
'stringified object with overload'
);
}
done_testing;