summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/DB_File/DB_File.pm
diff options
context:
space:
mode:
authorafresh1 <afresh1@openbsd.org>2021-03-01 23:19:42 +0000
committerafresh1 <afresh1@openbsd.org>2021-03-01 23:19:42 +0000
commit56d68f1e19ff848c889ecfa71d3a06340ff64892 (patch)
tree272372e9e82dd675d06054187c7f04b32fe71acc /gnu/usr.bin/perl/cpan/DB_File/DB_File.pm
parentImport perl-5.32.1 (diff)
downloadwireguard-openbsd-56d68f1e19ff848c889ecfa71d3a06340ff64892.tar.xz
wireguard-openbsd-56d68f1e19ff848c889ecfa71d3a06340ff64892.zip
Fix merge issues, remove excess files - match perl-5.32.1 dist
OK sthen@
Diffstat (limited to 'gnu/usr.bin/perl/cpan/DB_File/DB_File.pm')
-rw-r--r--gnu/usr.bin/perl/cpan/DB_File/DB_File.pm396
1 files changed, 201 insertions, 195 deletions
diff --git a/gnu/usr.bin/perl/cpan/DB_File/DB_File.pm b/gnu/usr.bin/perl/cpan/DB_File/DB_File.pm
index 6ca1592aadc..a732ff41e09 100644
--- a/gnu/usr.bin/perl/cpan/DB_File/DB_File.pm
+++ b/gnu/usr.bin/perl/cpan/DB_File/DB_File.pm
@@ -2,7 +2,7 @@
#
# Written by Paul Marquess (pmqs@cpan.org)
#
-# Copyright (c) 1995-2018 Paul Marquess. All rights reserved.
+# Copyright (c) 1995-2020 Paul Marquess. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
@@ -31,14 +31,14 @@ sub TIEHASH
my $pkg = shift ;
bless { VALID => {
- bsize => 1,
- ffactor => 1,
- nelem => 1,
- cachesize => 1,
- hash => 2,
- lorder => 1,
- },
- GOT => {}
+ bsize => 1,
+ ffactor => 1,
+ nelem => 1,
+ cachesize => 1,
+ hash => 2,
+ lorder => 1,
+ },
+ GOT => {}
}, $pkg ;
}
@@ -65,8 +65,8 @@ sub STORE
if ( $type )
{
- croak "Key '$key' not associated with a code reference"
- if $type == 2 && !ref $value && ref $value ne 'CODE';
+ croak "Key '$key' not associated with a code reference"
+ if $type == 2 && !ref $value && ref $value ne 'CODE';
$self->{GOT}{$key} = $value ;
return ;
}
@@ -122,9 +122,9 @@ sub TIEHASH
my $pkg = shift ;
bless { VALID => { map {$_, 1}
- qw( bval cachesize psize flags lorder reclen bfname )
- },
- GOT => {},
+ qw( bval cachesize psize flags lorder reclen bfname )
+ },
+ GOT => {},
}, $pkg ;
}
@@ -140,16 +140,16 @@ sub TIEHASH
my $pkg = shift ;
bless { VALID => {
- flags => 1,
- cachesize => 1,
- maxkeypage => 1,
- minkeypage => 1,
- psize => 1,
- compare => 2,
- prefix => 2,
- lorder => 1,
- },
- GOT => {},
+ flags => 1,
+ cachesize => 1,
+ maxkeypage => 1,
+ minkeypage => 1,
+ psize => 1,
+ compare => 2,
+ prefix => 2,
+ lorder => 1,
+ },
+ GOT => {},
}, $pkg ;
}
@@ -165,7 +165,7 @@ use Carp;
# Module not thread safe, so don't clone
sub CLONE_SKIP { 1 }
-$VERSION = "1.843" ;
+$VERSION = "1.853" ;
$VERSION = eval $VERSION; # needed for dev releases
{
@@ -203,34 +203,34 @@ push @ISA, qw(Tie::Hash Exporter);
@EXPORT = qw(
$DB_BTREE $DB_HASH $DB_RECNO
- BTREEMAGIC
- BTREEVERSION
- DB_LOCK
- DB_SHMEM
- DB_TXN
- HASHMAGIC
- HASHVERSION
- MAX_PAGE_NUMBER
- MAX_PAGE_OFFSET
- MAX_REC_NUMBER
- RET_ERROR
- RET_SPECIAL
- RET_SUCCESS
- R_CURSOR
- R_DUP
- R_FIRST
- R_FIXEDLEN
- R_IAFTER
- R_IBEFORE
- R_LAST
- R_NEXT
- R_NOKEY
- R_NOOVERWRITE
- R_PREV
- R_RECNOSYNC
- R_SETCURSOR
- R_SNAPSHOT
- __R_UNUSED
+ BTREEMAGIC
+ BTREEVERSION
+ DB_LOCK
+ DB_SHMEM
+ DB_TXN
+ HASHMAGIC
+ HASHVERSION
+ MAX_PAGE_NUMBER
+ MAX_PAGE_OFFSET
+ MAX_REC_NUMBER
+ RET_ERROR
+ RET_SPECIAL
+ RET_SUCCESS
+ R_CURSOR
+ R_DUP
+ R_FIRST
+ R_FIXEDLEN
+ R_IAFTER
+ R_IBEFORE
+ R_LAST
+ R_NEXT
+ R_NOKEY
+ R_NOOVERWRITE
+ R_PREV
+ R_RECNOSYNC
+ R_SETCURSOR
+ R_SNAPSHOT
+ __R_UNUSED
);
@@ -268,7 +268,7 @@ sub tie_hash_or_array
if defined $arg[1] ;
$arg[4] = tied %{ $arg[4] }
- if @arg >= 5 && ref $arg[4] && $arg[4] =~ /=HASH/ && tied %{ $arg[4] } ;
+ if @arg >= 5 && ref $arg[4] && $arg[4] =~ /=HASH/ && tied %{ $arg[4] } ;
$arg[2] = O_CREAT()|O_RDWR() if @arg >=3 && ! defined $arg[2];
$arg[3] = 0666 if @arg >=4 && ! defined $arg[3];
@@ -280,10 +280,10 @@ sub tie_hash_or_array
}
if ($db_version > 1 and defined $arg[4] and $arg[4] =~ /RECNO/ and
- $arg[1] and ! -e $arg[1]) {
- open(FH, ">$arg[1]") or return undef ;
- close FH ;
- chmod $arg[3] ? $arg[3] : 0666 , $arg[1] ;
+ $arg[1] and ! -e $arg[1]) {
+ open(FH, ">$arg[1]") or return undef ;
+ close FH ;
+ chmod $arg[3] ? $arg[3] : 0666 , $arg[1] ;
}
DoTie_($tieHASH, @arg) ;
@@ -325,9 +325,9 @@ sub STORESIZE
my $current_length = $self->length() ;
if ($length < $current_length) {
- my $key ;
+ my $key ;
for ($key = $current_length - 1 ; $key >= $length ; -- $key)
- { $self->del($key) }
+ { $self->del($key) }
}
elsif ($length > $current_length) {
$self->put($length-1, "") ;
@@ -340,8 +340,8 @@ sub SPLICE
my $self = shift;
my $offset = shift;
if (not defined $offset) {
- warnings::warnif('uninitialized', 'Use of uninitialized value in splice');
- $offset = 0;
+ warnings::warnif('uninitialized', 'Use of uninitialized value in splice');
+ $offset = 0;
}
my $has_length = @_;
@@ -358,47 +358,47 @@ sub SPLICE
# the array.'
#
if ($offset < 0) {
- my $new_offset = $size + $offset;
- if ($new_offset < 0) {
- die "Modification of non-creatable array value attempted, "
- . "subscript $offset";
- }
- $offset = $new_offset;
+ my $new_offset = $size + $offset;
+ if ($new_offset < 0) {
+ die "Modification of non-creatable array value attempted, "
+ . "subscript $offset";
+ }
+ $offset = $new_offset;
}
if (not defined $length) {
- warnings::warnif('uninitialized', 'Use of uninitialized value in splice');
- $length = 0;
+ warnings::warnif('uninitialized', 'Use of uninitialized value in splice');
+ $length = 0;
}
if ($offset > $size) {
- $offset = $size;
- warnings::warnif('misc', 'splice() offset past end of array')
+ $offset = $size;
+ warnings::warnif('misc', 'splice() offset past end of array')
if $has_length ? $splice_end_array : $splice_end_array_no_length;
}
# 'If LENGTH is omitted, removes everything from OFFSET onward.'
if (not defined $length) {
- $length = $size - $offset;
+ $length = $size - $offset;
}
# 'If LENGTH is negative, leave that many elements off the end of
# the array.'
#
if ($length < 0) {
- $length = $size - $offset + $length;
-
- if ($length < 0) {
- # The user must have specified a length bigger than the
- # length of the array passed in. But perl's splice()
- # doesn't catch this, it just behaves as for length=0.
- #
- $length = 0;
- }
+ $length = $size - $offset + $length;
+
+ if ($length < 0) {
+ # The user must have specified a length bigger than the
+ # length of the array passed in. But perl's splice()
+ # doesn't catch this, it just behaves as for length=0.
+ #
+ $length = 0;
+ }
}
if ($length > $size - $offset) {
- $length = $size - $offset;
+ $length = $size - $offset;
}
# $num_elems holds the current number of elements in the database.
@@ -409,94 +409,94 @@ sub SPLICE
#
my @removed = ();
foreach (0 .. $length - 1) {
- my $old;
- my $status = $self->get($offset, $old);
- if ($status != 0) {
- my $msg = "error from Berkeley DB on get($offset, \$old)";
- if ($status == 1) {
- $msg .= ' (no such element?)';
- }
- else {
- $msg .= ": error status $status";
- if (defined $! and $! ne '') {
- $msg .= ", message $!";
- }
- }
- die $msg;
- }
- push @removed, $old;
-
- $status = $self->del($offset);
- if ($status != 0) {
- my $msg = "error from Berkeley DB on del($offset)";
- if ($status == 1) {
- $msg .= ' (no such element?)';
- }
- else {
- $msg .= ": error status $status";
- if (defined $! and $! ne '') {
- $msg .= ", message $!";
- }
- }
- die $msg;
- }
-
- -- $num_elems;
+ my $old;
+ my $status = $self->get($offset, $old);
+ if ($status != 0) {
+ my $msg = "error from Berkeley DB on get($offset, \$old)";
+ if ($status == 1) {
+ $msg .= ' (no such element?)';
+ }
+ else {
+ $msg .= ": error status $status";
+ if (defined $! and $! ne '') {
+ $msg .= ", message $!";
+ }
+ }
+ die $msg;
+ }
+ push @removed, $old;
+
+ $status = $self->del($offset);
+ if ($status != 0) {
+ my $msg = "error from Berkeley DB on del($offset)";
+ if ($status == 1) {
+ $msg .= ' (no such element?)';
+ }
+ else {
+ $msg .= ": error status $status";
+ if (defined $! and $! ne '') {
+ $msg .= ", message $!";
+ }
+ }
+ die $msg;
+ }
+
+ -- $num_elems;
}
# ...'and replaces them with the elements of LIST, if any.'
my $pos = $offset;
while (defined (my $elem = shift @list)) {
- my $old_pos = $pos;
- my $status;
- if ($pos >= $num_elems) {
- $status = $self->put($pos, $elem);
- }
- else {
- $status = $self->put($pos, $elem, $self->R_IBEFORE);
- }
-
- if ($status != 0) {
- my $msg = "error from Berkeley DB on put($pos, $elem, ...)";
- if ($status == 1) {
- $msg .= ' (no such element?)';
- }
- else {
- $msg .= ", error status $status";
- if (defined $! and $! ne '') {
- $msg .= ", message $!";
- }
- }
- die $msg;
- }
-
- die "pos unexpectedly changed from $old_pos to $pos with R_IBEFORE"
- if $old_pos != $pos;
-
- ++ $pos;
- ++ $num_elems;
+ my $old_pos = $pos;
+ my $status;
+ if ($pos >= $num_elems) {
+ $status = $self->put($pos, $elem);
+ }
+ else {
+ $status = $self->put($pos, $elem, $self->R_IBEFORE);
+ }
+
+ if ($status != 0) {
+ my $msg = "error from Berkeley DB on put($pos, $elem, ...)";
+ if ($status == 1) {
+ $msg .= ' (no such element?)';
+ }
+ else {
+ $msg .= ", error status $status";
+ if (defined $! and $! ne '') {
+ $msg .= ", message $!";
+ }
+ }
+ die $msg;
+ }
+
+ die "pos unexpectedly changed from $old_pos to $pos with R_IBEFORE"
+ if $old_pos != $pos;
+
+ ++ $pos;
+ ++ $num_elems;
}
if (wantarray) {
- # 'In list context, returns the elements removed from the
- # array.'
- #
- return @removed;
+ # 'In list context, returns the elements removed from the
+ # array.'
+ #
+ return @removed;
}
elsif (defined wantarray and not wantarray) {
- # 'In scalar context, returns the last element removed, or
- # undef if no elements are removed.'
- #
- if (@removed) {
- my $last = pop @removed;
- return "$last";
- }
- else {
- return undef;
- }
+ # 'In scalar context, returns the last element removed, or
+ # undef if no elements are removed.'
+ #
+ if (@removed) {
+ my $last = pop @removed;
+ return "$last";
+ }
+ else {
+ return undef;
+ }
}
elsif (not defined wantarray) {
- # Void context
+ # Void context
}
else { die }
}
@@ -543,11 +543,11 @@ sub get_dup
my $db = shift ;
my $key = shift ;
- my $flag = shift ;
- my $value = 0 ;
+ my $flag = shift ;
+ my $value = 0 ;
my $origkey = $key ;
my $wantarray = wantarray ;
- my %values = () ;
+ my %values = () ;
my @values = () ;
my $counter = 0 ;
my $status = 0 ;
@@ -555,16 +555,16 @@ sub get_dup
# iterate through the database until either EOF ($status == 0)
# or a different key is encountered ($key ne $origkey).
for ($status = $db->seq($key, $value, R_CURSOR()) ;
- $status == 0 and $key eq $origkey ;
+ $status == 0 and $key eq $origkey ;
$status = $db->seq($key, $value, R_NEXT()) ) {
# save the value or count number of matches
if ($wantarray) {
- if ($flag)
+ if ($flag)
{ ++ $values{$value} }
- else
+ else
{ push (@values, $value) }
- }
+ }
else
{ ++ $counter }
@@ -692,7 +692,7 @@ like version 1. This feature allows B<DB_File> scripts that were built
with version 1 to be migrated to version 2 or greater without any changes.
If you want to make use of the new features available in Berkeley DB
-2.x or greater, use the Perl module B<BerkeleyDB> instead.
+2.x or greater, use the Perl module L<BerkeleyDB|https://metacpan.org/pod/BerkeleyDB> instead.
B<Note:> The database file format has changed multiple times in Berkeley
DB version 2, 3 and 4. If you cannot recreate your databases, you
@@ -753,7 +753,7 @@ C<ffactor>, C<hash>, C<lorder> and C<nelem>.
To change one of these elements, just assign to it like this:
- $DB_HASH->{'cachesize'} = 10000 ;
+ $DB_HASH->{'cachesize'} = 10000 ;
The three predefined variables $DB_HASH, $DB_BTREE and $DB_RECNO are
usually adequate for most applications. If you do need to create extra
@@ -809,12 +809,12 @@ to Perl subs. Below are templates for each of the subs:
my ($data) = @_ ;
...
# return the hash value for $data
- return $hash ;
+ return $hash ;
}
sub compare
{
- my ($key, $key2) = @_ ;
+ my ($key, $key2) = @_ ;
...
# return 0 if $key1 eq $key2
# -1 if $key1 lt $key2
@@ -824,7 +824,7 @@ to Perl subs. Below are templates for each of the subs:
sub prefix
{
- my ($key, $key2) = @_ ;
+ my ($key, $key2) = @_ ;
...
# return number of bytes of $key2 which are
# necessary to determine that it is greater than $key1
@@ -1041,7 +1041,7 @@ code:
$DB_BTREE->{'flags'} = R_DUP ;
tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0666, $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' ;
@@ -1096,7 +1096,7 @@ Here is the script above rewritten using the C<seq> API method.
$DB_BTREE->{'flags'} = R_DUP ;
$x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0666, $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' ;
@@ -1167,7 +1167,7 @@ this:
$DB_BTREE->{'flags'} = R_DUP ;
$x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0666, $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" ;
@@ -1177,13 +1177,13 @@ this:
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" ;
and it will print:
@@ -1191,9 +1191,9 @@ and it will print:
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 => []
=head2 The find_dup() Method
@@ -1217,7 +1217,7 @@ Assuming the database from the previous example:
$DB_BTREE->{'flags'} = R_DUP ;
$x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0666, $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" ;
@@ -1256,7 +1256,7 @@ Again assuming the existence of the C<tree> database
$DB_BTREE->{'flags'} = R_DUP ;
$x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0666, $DB_BTREE
- or die "Cannot open $filename: $!\n";
+ or die "Cannot open $filename: $!\n";
$x->del_dup("Wall", "Larry") ;
@@ -1321,10 +1321,10 @@ and print the first matching key/value pair given a partial key.
$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" ;
@@ -1625,12 +1625,12 @@ Berkeley DB documentation.
To do this you need to store a copy of the object returned from the tie.
- $db = tie %hash, "DB_File", "filename" ;
+ $db = tie %hash, "DB_File", "filename" ;
Once you have done that, you can access the Berkeley DB API functions
as B<DB_File> methods directly like this:
- $db->put($key, $value, R_NOOVERWRITE) ;
+ $db->put($key, $value, R_NOOVERWRITE) ;
B<Important:> If you have saved a copy of the object returned from
C<tie>, the underlying database file will I<not> be closed until both
@@ -2012,11 +2012,11 @@ not be used.
=head2 Safe ways to lock a database
Starting with version 2.x, Berkeley DB has internal support for locking.
-The companion module to this one, B<BerkeleyDB>, provides an interface
+The companion module to this one, L<BerkeleyDB|https://metacpan.org/pod/BerkeleyDB>, provides an interface
to this locking functionality. If you are serious about locking
-Berkeley DB databases, I strongly recommend using B<BerkeleyDB>.
+Berkeley DB databases, I strongly recommend using L<BerkeleyDB|https://metacpan.org/pod/BerkeleyDB>.
-If using B<BerkeleyDB> isn't an option, there are a number of modules
+If using L<BerkeleyDB|https://metacpan.org/pod/BerkeleyDB> isn't an option, there are a number of modules
available on CPAN that can be used to implement locking. Each one
implements locking differently and has different goals in mind. It is
therefore worth knowing the difference, so that you can pick the right
@@ -2298,6 +2298,12 @@ version 1.85 of Berkeley DB.
I am sure there are bugs in the code. If you do find any, or can
suggest any enhancements, I would welcome your comments.
+=head1 SUPPORT
+
+General feedback/questions/bug reports should be sent to
+L<https://github.com/pmqs/DB_File/issues> (preferred) or
+L<https://rt.cpan.org/Public/Dist/Display.html?Name=DB_File>.
+
=head1 AVAILABILITY
B<DB_File> comes with the standard Perl source distribution. Look in
@@ -2307,11 +2313,11 @@ date, so the most recent version can always be found on CPAN (see
L<perlmodlib/CPAN> for details), in the directory
F<modules/by-module/DB_File>.
-This version of B<DB_File> will work with either version 1.x, 2.x or
-3.x of Berkeley DB, but is limited to the functionality provided by
-version 1.
+B<DB_File> is designed to work with any version of Berkeley DB, but is limited to the functionality provided by
+version 1. If you want to make use of the new features available in Berkeley DB
+2.x, or greater, use the Perl module L<BerkeleyDB|https://metacpan.org/pod/BerkeleyDB> instead.
-The official web site for Berkeley DB is F<http://www.oracle.com/technology/products/berkeley-db/db/index.html>.
+The official web site for Berkeley DB is L<http://www.oracle.com/technology/products/berkeley-db/db/index.html>.
All versions of Berkeley DB are available there.
Alternatively, Berkeley DB version 1 is available at your nearest CPAN
@@ -2319,7 +2325,7 @@ archive in F<src/misc/db.1.85.tar.gz>.
=head1 COPYRIGHT
-Copyright (c) 1995-2016 Paul Marquess. All rights reserved. This program
+Copyright (c) 1995-2020 Paul Marquess. All rights reserved. This program
is free software; you can redistribute it and/or modify it under the
same terms as Perl itself.
@@ -2328,7 +2334,7 @@ makes use of, namely Berkeley DB, is not. Berkeley DB has its own
copyright and its own license. Please take the time to read it.
Here are a few words taken from the Berkeley DB FAQ (at
-F<http://www.oracle.com/technology/products/berkeley-db/db/index.html>) regarding the license:
+L<http://www.oracle.com/technology/products/berkeley-db/db/index.html>) regarding the license:
Do I have to license DB to use it in Perl scripts?