BEGIN {
use_ok(
'Tie::Hash::KeysMask'
);
};
sub
expecty
{
my
(
$x
,
$y
,
$h
,
$message
)=
@_
;
is (
$h
->{
$x
},
$y
,
"$message [$x=>$y] Y"
);
}
sub
expectn
{
my
(
$x
,
$y
,
$h
,
$message
)=
@_
;
isnt (
$h
->{
$x
},
$y
,
"$message [$x=>$y] N"
);
}
sub
isdef
{
my
(
$x
,
$h
,
$message
)=
@_
;
ok(
exists
$h
->{
$x
},
"$message [$x] Y"
);
}
sub
notdef
{
my
(
$x
,
$h
,
$message
)=
@_
;
ok(!(
exists
$h
->{
$x
}),
"$message [$x] N"
);
}
my
@compass
=
qw(north east south west)
;
my
@direction
=
qw(up right down left)
;
my
@D
=
qw(north up east right south down west left)
;
{
my
$myh
= Tie::Hash::KeysMask->newHASH(
sub
{
substr
(
$_
[0],0,1);});
%$myh
=
@D
;
my
$msg
=
'1st char significant'
;
notdef
'N'
,
$myh
,
$msg
;
isdef
'n'
,
$myh
,
$msg
;
expecty
qw(we left)
,
$myh
,
$msg
;
expecty
qw(sw down)
,
$myh
,
$msg
;
}
{
my
$myh
= Tie::Hash::KeysMask->newHASH(
'uc'
);
%$myh
=
@D
;
my
$msg
=
'ignore case'
;
isdef
'North'
,
$myh
,
$msg
;
isdef
'EAST'
,
$myh
,
$msg
;
expecty
qw(West left)
,
$myh
,
$msg
;
expecty
qw(WEST left)
,
$myh
,
$msg
;
expecty
qw(south down)
,
$myh
,
$msg
;
}
{
my
$myh
= Tie::Hash::KeysMask->newHASH
({
qw(North N north N south S SOUTH S Greenland N w west west W e east east E)
});
%$myh
=
@D
;
my
$msg
=
'alias by hash-mapping'
;
notdef
'NORTH'
,
$myh
,
$msg
;
isdef
'SOUTH'
,
$myh
,
$msg
;
expecty
qw(N up)
,
$myh
,
$msg
;;
expecty
qw(Greenland up)
,
$myh
,
$msg
;;
}