TBD::Text - physical representation of tables as ordinary text files


   use TBD::Text;
   our @ISA = qw(... TBD::Text ...);


TBD::Text provides loading and storing operations for tables which are represented as ordinary text files (as opposed to DBM files, NIS maps or database tables). Because TBD::Text is an extension of TBD::CachingTable all accessing operations are provided as well.

Following parameters are expected to be passed to constructors. Modules which are derived from TBD::Text are expected to pass these parameters to TBD::Text::initialize1.


The database file where the table is to be loaded from and to be stored to.


The name of a temporary file that is used to create a new text file version. This file is renamed to filename by an atomic operation. For this to work, tmpfile must reside on the same file system as filename.


The name of a logfile where records about changes are to be added.


The input field separator which is to be given as regular expression.


The input record separator which is to be given as string.


The output field separator which is to be used on storing modificated tables back to the original file.


The output record separator -- usually identical to the input record separator.


A string which (or regular expression without leading ^) which matches comment lines which are to be ignored in the file. This string may be empty if no comments are used.


A string specifying the table name.


A pointer to a list of key field names.


A pointer to a list of field names. The order must reflect the order of fields in the input file.

The parameters fields, filename, ifs, irs, and tablename are mandatory. Reasonable defaults are provided for keyfields (first field name of fields), ofs (same as ifs), ors (same as irs), tmpfile (filename with ``.tmp'' appended), logfile (filename with ``.log'' appended), and comment (empty string).

The registration of a set of text file tables could be arranged as in following example:

   my %table = (
      Members => {
         ifs => ':',
         irs => "\n",
         keyfields => [qw(login)],
         fields => [qw(login name)],
      Documents => {
         ifs => '~',
         irs => "\n",
         keyfields => [qw(group shortname)],
         fields => [qw(group shortname login title)],
      # ...
   my $tabledir = "/some/path/where/your/tables/reside";
   foreach my $table (keys %table) {
      TBI->register($table, 'TBD::Text', {
         filename => "$tabledir/$table",
         tablename => $table,

Note that TBD::Text is an extension of TBD::Scanner, TBD::CachingTable, TBD::Dumper, and TBD::Locker. In addition, TBD::Text provides following methods:


loads (or re-loads) the table from the current file representation. This operation is required for read accesses.


returns true if reading operations are permitted.


locks the table for write operations. This lock will be held exclusively and will block all other parties that are using this implementation and try to lock the table as well.


saves the current state of the table back to the associated file and unlocks it. Read-only accesses are still permitted afterwards.


returns true if writing operations are permitted.


returns true if the contents of $field does not interfere with field and record separators, i.e. if it is save to be assigned to a field.


Andreas Borchert with contributions of Mathias Etter.