AddressBook - Abstract class for using AddressBooks
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);
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.
Create a new AddressBook object.
AddressBook->new(source=$source,\%args)
See the appropriate backend documentation for constructor details.
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.
$abook->search(attr=>\%filter); while ($entry=$abook->read) { print $entry->dump; }
\%filter is a list of cannonical attribute/value pairs.
$entry=$abook->read;
Returns an AddressBook::Entry object
$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
$abook->add($entry)
$abook->delete($entry)
$abook->truncate
Removes all records from the database.
@names = $abook->get_attribute_names;
Returns a list of valid backend-specific attribute names
@names = $abook->get_cannonical_attribute_names;
Returns a list of valid cannonical attribute names
Mark A. Hershberger, <mah@everybody.org> David L. Leigh, <dleigh@sameasiteverwas.net>
The perl-abook home page at http://perl-abook.sourceforge.net
AddressBook::Config AddressBook::Entry
To install AddressBook, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AddressBook
CPAN shell
perl -MCPAN -e shell install AddressBook
For more information on module installation, please visit the detailed CPAN module installation guide.