| 1 |
#!./perl -w |
| 2 |
|
| 3 |
use strict ; |
| 4 |
|
| 5 |
use lib 't' ; |
| 6 |
use BerkeleyDB; |
| 7 |
use util ; |
| 8 |
use Test::More ; |
| 9 |
|
| 10 |
BEGIN |
| 11 |
{ |
| 12 |
eval { require Encode; }; |
| 13 |
|
| 14 |
plan skip_all => "Encode is not available" |
| 15 |
if $@; |
| 16 |
|
| 17 |
plan tests => 8; |
| 18 |
|
| 19 |
use_ok('charnames', qw{greek}); |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
use charnames qw{greek}; |
| 24 |
|
| 25 |
|
| 26 |
my $Dfile = "dbhash.tmp"; |
| 27 |
unlink $Dfile; |
| 28 |
|
| 29 |
umask(0) ; |
| 30 |
|
| 31 |
{ |
| 32 |
# UTF8 |
| 33 |
# |
| 34 |
|
| 35 |
#use warnings ; |
| 36 |
use strict ; |
| 37 |
my (%h, $db) ; |
| 38 |
unlink $Dfile; |
| 39 |
|
| 40 |
ok $db = tie %h, 'BerkeleyDB::Hash', |
| 41 |
-Filename => $Dfile, |
| 42 |
-Flags => DB_CREATE; |
| 43 |
|
| 44 |
$db->filter_fetch_key (sub { $_ = Encode::decode_utf8($_) if defined $_ }); |
| 45 |
$db->filter_store_key (sub { $_ = Encode::encode_utf8($_) if defined $_ }); |
| 46 |
$db->filter_fetch_value (sub { $_ = Encode::decode_utf8($_) if defined $_ }); |
| 47 |
$db->filter_store_value (sub { $_ = Encode::encode_utf8($_) if defined $_ }); |
| 48 |
|
| 49 |
$h{"\N{alpha}"} = "alpha"; |
| 50 |
$h{"gamma"} = "\N{gamma}"; |
| 51 |
|
| 52 |
is $h{"\N{alpha}"}, "alpha"; |
| 53 |
is $h{"gamma"}, "\N{gamma}"; |
| 54 |
|
| 55 |
undef $db ; |
| 56 |
untie %h; |
| 57 |
|
| 58 |
my %newH; |
| 59 |
ok $db = tie %newH, 'BerkeleyDB::Hash', |
| 60 |
-Filename => $Dfile, |
| 61 |
-Flags => DB_CREATE; |
| 62 |
|
| 63 |
$newH{"fred"} = "joe" ; |
| 64 |
is $newH{"fred"}, "joe"; |
| 65 |
|
| 66 |
is $newH{"gamma"}, "\xCE\xB3"; |
| 67 |
is $newH{"\xCE\xB1"}, "alpha"; |
| 68 |
|
| 69 |
undef $db ; |
| 70 |
untie %newH; |
| 71 |
unlink $Dfile; |
| 72 |
} |