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