| 1 | package AnyDBM_File; |
| 2 | |
| 3 | use vars qw(@ISA); |
| 4 | @ISA = qw(NDBM_File DB_File GDBM_File SDBM_File ODBM_File) unless @ISA; |
| 5 | |
| 6 | my $mod; |
| 7 | for $mod (@ISA) { |
| 8 | if (eval "require $mod") { |
| 9 | @ISA = ($mod); # if we leave @ISA alone, warnings abound |
| 10 | return 1; |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | die "No DBM package was successfully found or installed"; |
| 15 | #return 0; |
| 16 | |
| 17 | =head1 NAME |
| 18 | |
| 19 | AnyDBM_File - provide framework for multiple DBMs |
| 20 | |
| 21 | NDBM_File, DB_File, GDBM_File, SDBM_File, ODBM_File - various DBM implementations |
| 22 | |
| 23 | =head1 SYNOPSIS |
| 24 | |
| 25 | use AnyDBM_File; |
| 26 | |
| 27 | =head1 DESCRIPTION |
| 28 | |
| 29 | This module is a "pure virtual base class"--it has nothing of its own. |
| 30 | It's just there to inherit from one of the various DBM packages. It |
| 31 | prefers ndbm for compatibility reasons with Perl 4, then Berkeley DB (See |
| 32 | L<DB_File>), GDBM, SDBM (which is always there--it comes with Perl), and |
| 33 | finally ODBM. This way old programs that used to use NDBM via dbmopen() |
| 34 | can still do so, but new ones can reorder @ISA: |
| 35 | |
| 36 | BEGIN { @AnyDBM_File::ISA = qw(DB_File GDBM_File NDBM_File) } |
| 37 | use AnyDBM_File; |
| 38 | |
| 39 | Having multiple DBM implementations makes it trivial to copy database formats: |
| 40 | |
| 41 | use POSIX; use NDBM_File; use DB_File; |
| 42 | tie %newhash, 'DB_File', $new_filename, O_CREAT|O_RDWR; |
| 43 | tie %oldhash, 'NDBM_File', $old_filename, 1, 0; |
| 44 | %newhash = %oldhash; |
| 45 | |
| 46 | =head2 DBM Comparisons |
| 47 | |
| 48 | Here's a partial table of features the different packages offer: |
| 49 | |
| 50 | odbm ndbm sdbm gdbm bsd-db |
| 51 | ---- ---- ---- ---- ------ |
| 52 | Linkage comes w/ perl yes yes yes yes yes |
| 53 | Src comes w/ perl no no yes no no |
| 54 | Comes w/ many unix os yes yes[0] no no no |
| 55 | Builds ok on !unix ? ? yes yes ? |
| 56 | Code Size ? ? small big big |
| 57 | Database Size ? ? small big? ok[1] |
| 58 | Speed ? ? slow ok fast |
| 59 | FTPable no no yes yes yes |
| 60 | Easy to build N/A N/A yes yes ok[2] |
| 61 | Size limits 1k 4k 1k[3] none none |
| 62 | Byte-order independent no no no no yes |
| 63 | Licensing restrictions ? ? no yes no |
| 64 | |
| 65 | |
| 66 | =over 4 |
| 67 | |
| 68 | =item [0] |
| 69 | |
| 70 | on mixed universe machines, may be in the bsd compat library, |
| 71 | which is often shunned. |
| 72 | |
| 73 | =item [1] |
| 74 | |
| 75 | Can be trimmed if you compile for one access method. |
| 76 | |
| 77 | =item [2] |
| 78 | |
| 79 | See L<DB_File>. |
| 80 | Requires symbolic links. |
| 81 | |
| 82 | =item [3] |
| 83 | |
| 84 | By default, but can be redefined. |
| 85 | |
| 86 | =back |
| 87 | |
| 88 | =head1 SEE ALSO |
| 89 | |
| 90 | dbm(3), ndbm(3), DB_File(3), L<perldbmfilter> |
| 91 | |
| 92 | =cut |