#!perl
sub
new {
my
$class
=
shift
;
bless
{
x
=>
shift
,
y
=>
shift
,
z
=>
shift
},
$class
;
}
for
my
$meth
(
qw/x y/
) {
no
strict
'refs'
;
*$meth
=
sub
{
my
$self
=
shift
;
$self
->{
$meth
} =
shift
if
@_
;
return
$self
->{
$meth
}; };
}
sub
z {
my
$self
=
shift
;
$self
->{z} =
shift
if
@_
;
return
wantarray
? (
qw(hello list context)
)
:
$self
->{z};
}
plan
tests
=> 9;
my
$point
= Point->new(5, 7, 1_000);
is(
$point
->x, 5);
is(
$point
->y, 7);
is(
$point
->z, 1_000);
(mslice(
$point
,
qw/x y/
)) = mslice(
$point
,
qw/y x/
);
is(
$point
->x, 7);
is(
$point
->y, 5);
(mslice(
$point
,
qw/x y z/
)) =
map
{
$_
+ 10} @{[mslice(
$point
,
qw/x y z/
)]};
is(
$point
->x, 17);
is(
$point
->y, 15);
is(
$point
->z, 1_010);
my
(
$x
,
$y
,
$z
) = mslice(
$point
,
qw/x y z/
);
is_deeply( {
x
=>
$x
,
y
=>
$y
,
z
=>
$z
},
{
x
=>
$point
->x,
y
=>
$point
->y,
z
=> 1_010} );