NAME
AddressBook - Abstract class for using AddressBooks
SYNOPSIS
use AddressBook;
$a = AddressBook->new(source => "LDAP:localhost");
$b = AddressBook->new(source => "DBI:CSV:f_dir=/tmp/data");
$c = AddressBook->new(source => "PDB");
$a->search(name => "hersh");
$entry = $a->read;
$b->add($entry);
$entry = AddressBook::Entry->new(attr=>{name => "dleigh"});
$c->write($entry);
AddressBook::sync(master=>$a,slave=>$c);
DESCRIPTION
AddressBook provides a unified interface to access various databases for keeping track of contacts. Included with this module are several backends:
AddressBook::DB::LDAP
AddressBook::DB::LDIF
AddressBook::DB::DBI
AddressBook::DB::PDB
AddressBook::DB::Text
AddressBook::DB::HTML
More will be added in the future.
new
Create a new AddressBook object.
AddressBook->new(source=$source,\%args)
See the appropriate backend documentation for constructor details.
sync
AddressBook::sync(master=>$master_db, slave=>$slave_db)
AddressBook::sync(master=>$master_db, slave=>$slave_db,debug=>1)
Synchronizes the "master" and "slave" databases. The "master" database type must be one that supports random-access methods. The "slave" database type must be one that supports sequential-access methods.
When the 'debug' option is true, debug messages will be printed to stdout. The msg_function paramater, if included, should be a subroutine reference which will be called with a status message is the argument.
For each record in the slave, look for a corresponding record in the master, using the key_fields of each.
-
If no match is found, the entry is added to the master.
-
If multiple matches are found, an error occurrs.
-
If one match is found, then:
-
If the records match, nothing is done.
-
If the records do not match, then:
-
If the slave record's timestamp is newer, the master's entry is merged (see below) with the slave entry's data.
-
If the master record's timestamp is newer, nothing is done.
-
-
-
The slave database is truncated.
Each record of the master is added to the slave
The 'merging' of the master and slave entries involves taking each attribute in the slave's entry and replacing the corresponding attribute in the master's entry. Note that attributes that are deleted only on the slave are therefore effectively ignored during synchronization.
Similarly, deletions made on the slave database are effectively ignored during synchronization.
search
$abook->search(attr=>\%filter);
while ($entry=$abook->read) {
print $entry->dump;
}
\%filter is a list of cannonical attribute/value pairs.
read
$entry=$abook->read;
Returns an AddressBook::Entry object
update
$abook->update(filter=>\%filter,entry=>$entry)
\%filter is a list of cannonical attriute/value pairs used to identify the entry to be updated.
$entry is an AddressBook::Entry object
add
$abook->add($entry)
$entry is an AddressBook::Entry object
delete
$abook->delete($entry)
$entry is an AddressBook::Entry object
truncate
$abook->truncate
Removes all records from the database.
get_attribute_names
@names = $abook->get_attribute_names;
Returns a list of valid backend-specific attribute names
get_cannonical_attribute_names
@names = $abook->get_cannonical_attribute_names;
Returns a list of valid cannonical attribute names
AUTHOR
Mark A. Hershberger, <mah@everybody.org> David L. Leigh, <dleigh@sameasiteverwas.net>
SEE ALSO
The perl-abook home page at http://perl-abook.sourceforge.net
AddressBook::Config AddressBook::Entry
AddressBook::DB::LDAP AddressBook::DB::LDIF AddressBook::DB::DBI AddressBook::DB::PDB AddressBook::DB::Text AddressBook::DB::HTML