BEGIN
{
if ($^O eq 'darwin'
- && (split(/\./, $Config{osvers}))[0] < 7 # Mac OS X 10.3 == Darwin 7
- && $Config{db_version_major} == 1
- && $Config{db_version_minor} == 0
- && $Config{db_version_patch} == 0) {
- warn <<EOM;
+ && (split(/\./, $Config{osvers}))[0] < 7 # Mac OS X 10.3 == Darwin 7
+ && $Config{db_version_major} == 1
+ && $Config{db_version_minor} == 0
+ && $Config{db_version_patch} == 0) {
+ warn <<EOM;
#
# This test is known to crash in Mac OS X versions 10.2 (or earlier)
# because of the buggy Berkeley DB version included with the OS.
{
my $class = shift ;
my $filename = shift ;
- my $fh = gensym ;
- open ($fh, ">$filename") || die "Cannot open $filename: $!" ;
- my $real_stdout = select($fh) ;
- return bless [$fh, $real_stdout ] ;
+ my $fh = gensym ;
+ open ($fh, ">$filename") || die "Cannot open $filename: $!" ;
+ my $real_stdout = select($fh) ;
+ return bless [$fh, $real_stdout ] ;
}
sub DESTROY
{
my $self = shift ;
- close $self->[0] ;
- select($self->[1]) ;
+ close $self->[0] ;
+ select($self->[1]) ;
}
}
my $db185mode = ($DB_File::db_version == 1 && ! $DB_File::db_185_compat) ;
my $null_keys_allowed = ($DB_File::db_ver < 2.004010
- || $DB_File::db_ver >= 3.1 );
+ || $DB_File::db_ver >= 3.1 );
my $TEMPDIR = tempdir( CLEANUP => 1 );
chdir $TEMPDIR;
$i = 0 ;
while (($key,$value) = each(%h)) {
if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
- $key =~ y/a-z/A-Z/;
- $i++ if $key eq $value;
+ $key =~ y/a-z/A-Z/;
+ $i++ if $key eq $value;
}
}
ok(62, $value eq 'replace value' );
$status = $X->get('y', $value) ;
ok(63, 1) ; # hard-wire to always pass. the previous test ($status == 1)
- # only worked because of a bug in 1.85/6
+ # only worked because of a bug in 1.85/6
# use seq to walk forwards through a file
my %wall = $YY->get_dup('Wall', 1) ;
ok(83, keys %wall == 3 && $wall{'Larry'} == 1 && $wall{'Stone'} == 1
- && $wall{'Brick'} == 2);
+ && $wall{'Brick'} == 2);
undef $YY ;
untie %hh ;
my $dbh1 = new DB_File::BTREEINFO ;
$dbh1->{compare} = sub {
- no warnings 'numeric' ;
- $_[0] <=> $_[1] } ;
+ no warnings 'numeric' ;
+ $_[0] <=> $_[1] } ;
my $dbh2 = new DB_File::BTREEINFO ;
$dbh2->{compare} = sub { $_[0] cmp $_[1] } ;
@EXPORT = @DB_File::EXPORT ;
sub STORE {
- my $self = shift ;
+ my $self = shift ;
my $key = shift ;
my $value = shift ;
$self->SUPER::STORE($key, $value * 2) ;
}
sub FETCH {
- my $self = shift ;
+ my $self = shift ;
my $key = shift ;
$self->SUPER::FETCH($key) - 1 ;
}
sub put {
- my $self = shift ;
+ my $self = shift ;
my $key = shift ;
my $value = shift ;
$self->SUPER::put($key, $value * 3) ;
}
sub get {
- my $self = shift ;
+ my $self = shift ;
$self->SUPER::get($_[0], $_[1]) ;
- $_[1] -= 2 ;
+ $_[1] -= 2 ;
}
sub A_new_method
{
- my $self = shift ;
+ my $self = shift ;
my $key = shift ;
my $value = $self->FETCH($key) ;
- return "[[$value]]" ;
+ return "[[$value]]" ;
}
1 ;
my %h ;
my $X ;
eval '
- $X = tie(%h, "SubDB","dbbtree.tmp", O_RDWR|O_CREAT, 0640, $DB_BTREE );
- ' ;
+ $X = tie(%h, "SubDB","dbbtree.tmp", O_RDWR|O_CREAT, 0640, $DB_BTREE );
+ ' ;
main::ok(92, $@ eq "") ;
my($fk, $sk, $fv, $sv) = @_ ;
return
$fetch_key eq $fk && $store_key eq $sk &&
- $fetch_value eq $fv && $store_value eq $sv &&
- $_ eq 'original' ;
+ $fetch_value eq $fv && $store_value eq $sv &&
+ $_ eq 'original' ;
}
ok(101, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
# replace the filters, but remember the previous set
my ($old_fk) = $db->filter_fetch_key
- (sub { $_ = uc $_ ; $fetch_key = $_ }) ;
+ (sub { $_ = uc $_ ; $fetch_key = $_ }) ;
my ($old_sk) = $db->filter_store_key
- (sub { $_ = lc $_ ; $store_key = $_ }) ;
+ (sub { $_ = lc $_ ; $store_key = $_ }) ;
my ($old_fv) = $db->filter_fetch_value
- (sub { $_ = "[$_]"; $fetch_value = $_ }) ;
+ (sub { $_ = "[$_]"; $fetch_value = $_ }) ;
my ($old_sv) = $db->filter_store_value
- (sub { s/o/x/g; $store_value = $_ }) ;
+ (sub { s/o/x/g; $store_value = $_ }) ;
($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
$h{"Fred"} = "Joe" ;
sub Closure
{
my ($name) = @_ ;
- my $count = 0 ;
- my @kept = () ;
+ my $count = 0 ;
+ my @kept = () ;
- return sub { ++$count ;
- push @kept, $_ ;
- $result{$name} = "$name - $count: [@kept]" ;
- }
+ return sub { ++$count ;
+ push @kept, $_ ;
+ $result{$name} = "$name - $count: [@kept]" ;
+ }
}
$db->filter_store_key(Closure("store key")) ;
undef $db ;
untie %h;
unlink $Dfile;
-}
+}
{
# DBM Filter recursion detection
$DB_BTREE->{'flags'} = R_DUP ;
tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
- or die "Cannot open $filename: $!\n";
+ or die "Cannot open $filename: $!\n";
# Add some key/value pairs to the file
$h{'Wall'} = 'Larry' ;
# iterate through the associative array
# and print each key/value pair.
foreach (keys %h)
- { print "$_ -> $h{$_}\n" }
+ { print "$_ -> $h{$_}\n" }
untie %h ;
}
ok(148, docat_del($file) eq ($db185mode ? <<'EOM' : <<'EOM') ) ;
-Smith -> John
-Wall -> Brick
-Wall -> Brick
-Wall -> Brick
-mouse -> mickey
+Smith -> John
+Wall -> Brick
+Wall -> Brick
+Wall -> Brick
+mouse -> mickey
EOM
-Smith -> John
-Wall -> Larry
-Wall -> Larry
-Wall -> Larry
-mouse -> mickey
+Smith -> John
+Wall -> Larry
+Wall -> Larry
+Wall -> Larry
+mouse -> mickey
EOM
{
$DB_BTREE->{'flags'} = R_DUP ;
$x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
- or die "Cannot open $filename: $!\n";
+ or die "Cannot open $filename: $!\n";
# Add some key/value pairs to the file
$h{'Wall'} = 'Larry' ;
for ($status = $x->seq($key, $value, R_FIRST) ;
$status == 0 ;
$status = $x->seq($key, $value, R_NEXT) )
- { print "$key -> $value\n" }
+ { print "$key -> $value\n" }
undef $x ;
}
ok(149, docat_del($file) eq ($db185mode == 1 ? <<'EOM' : <<'EOM') ) ;
-Smith -> John
-Wall -> Brick
-Wall -> Brick
-Wall -> Larry
-mouse -> mickey
+Smith -> John
+Wall -> Brick
+Wall -> Brick
+Wall -> Larry
+mouse -> mickey
EOM
-Smith -> John
-Wall -> Larry
-Wall -> Brick
-Wall -> Brick
-mouse -> mickey
+Smith -> John
+Wall -> Larry
+Wall -> Brick
+Wall -> Brick
+mouse -> mickey
EOM
$DB_BTREE->{'flags'} = R_DUP ;
$x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
- or die "Cannot open $filename: $!\n";
+ or die "Cannot open $filename: $!\n";
my $cnt = $x->get_dup("Wall") ;
print "Wall occurred $cnt times\n" ;
print "There are $hash{'Brick'} Brick Walls\n" ;
my @list = sort $x->get_dup("Wall") ;
- print "Wall => [@list]\n" ;
+ print "Wall => [@list]\n" ;
@list = $x->get_dup("Smith") ;
- print "Smith => [@list]\n" ;
+ print "Smith => [@list]\n" ;
@list = $x->get_dup("Dog") ;
- print "Dog => [@list]\n" ;
+ print "Dog => [@list]\n" ;
undef $x ;
untie %h ;
Wall occurred 3 times
Larry is there
There are 2 Brick Walls
-Wall => [Brick Brick Larry]
-Smith => [John]
-Dog => []
+Wall => [Brick Brick Larry]
+Smith => [John]
+Dog => []
EOM
{
$DB_BTREE->{'flags'} = R_DUP ;
$x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
- or die "Cannot open $filename: $!\n";
+ or die "Cannot open $filename: $!\n";
$found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
print "Larry Wall is $found there\n" ;
$DB_BTREE->{'flags'} = R_DUP ;
$x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
- or die "Cannot open $filename: $!\n";
+ or die "Cannot open $filename: $!\n";
$x->del_dup("Wall", "Larry") ;
my $value = 0;
my $orig_key = $key ;
$x->seq($key, $value, R_CURSOR) ;
- print "$orig_key\t-> $key\t-> $value\n" ;
+ print "$orig_key -> $key -> $value\n" ;
}
$filename = "tree" ;
$key = $value = 0 ;
print "IN ORDER\n" ;
for ($st = $x->seq($key, $value, R_FIRST) ;
- $st == 0 ;
+ $st == 0 ;
$st = $x->seq($key, $value, R_NEXT) )
-
- { print "$key -> $value\n" }
+
+ { print "$key -> $value\n" }
print "\nPARTIAL MATCH\n" ;
ok(153, docat_del($file) eq <<'EOM') ;
IN ORDER
-Smith -> John
-Wall -> Larry
-Walls -> Brick
-mouse -> mickey
+Smith -> John
+Wall -> Larry
+Walls -> Brick
+mouse -> mickey
PARTIAL MATCH
-Wa -> Wall -> Larry
-A -> Smith -> John
-a -> mouse -> mickey
+Wa -> Wall -> Larry
+A -> Smith -> John
+a -> mouse -> mickey
EOM
}
local $SIG{__WARN__} = sub {$a = $_[0]} ;
tie %h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_BTREE
- or die "Can't open file: $!\n" ;
+ or die "Can't open file: $!\n" ;
$h{ABC} = undef;
ok(154, $a eq "") ;
untie %h ;
local $SIG{__WARN__} = sub {$a = $_[0]} ;
tie %h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_BTREE
- or die "Can't open file: $!\n" ;
+ or die "Can't open file: $!\n" ;
%h = (); ;
ok(155, $a eq "") ;
untie %h ;
# my (%h);
# ok(164, tie(%hash, 'DB_File',$Dfile, O_RDWR|O_CREAT, 0640, $dbh ) );
#
-# eval { $hash{1} = 2;
-# $hash{4} = 5;
-# };
+# eval { $hash{1} = 2;
+# $hash{4} = 5;
+# };
#
# ok(165, $@ =~ /^DB_File btree_compare: recursion detected/);
# {