#!perl
{
method add(
$this
= 23,
$that
= 42) {
return
$this
+
$that
;
}
method minus(
$this
= 23,
$that
= 42) {
return
$this
-
$that
;
}
is( Stuff->add(), 23 + 42 );
is( Stuff->add(99), 99 + 42 );
is( Stuff->add(2,3), 5 );
is( Stuff->minus(), 23 - 42 );
is( Stuff->minus(99), 99 - 42 );
is( Stuff->minus(2, 3), 2 - 3 );
method echo(
$message
=
"what?"
) {
return
$message
}
is( Stuff->echo(),
"what?"
);
is( Stuff->echo(
undef
),
undef
);
is( Stuff->echo(
"who?"
),
'who?'
);
method copy_cat(
$this
,
$that
=
$this
) {
return
$that
;
}
is( Stuff->copy_cat(
"wibble"
),
"wibble"
);
is( Stuff->copy_cat(23, 42), 42 );
}
{
method hello(
$msg
=
"Hello, world!"
) {
return
$msg
;
}
is( Bar->hello,
"Hello, world!"
);
is( Bar->hello(
"Greetings!"
),
"Greetings!"
);
method hi(
$msg
=
q,Hi,
) {
return
$msg
;
}
is( Bar->hi,
"Hi"
);
is( Bar->hi(
"Yo"
),
"Yo"
);
method code(
$num
,
$code
=
sub
{
$num
+ 2 }) {
return
$code
->();
}
is( Bar->code(42), 44 );
}