AddressBook
view release on metacpan or search on metacpan
lib/AddressBook.pm view on Meta::CPAN
sub sync {
my %args = @_;
my $master = $args{master};
my $slave = $args{slave};
unless ($master->{key_fields} && $slave->{key_fields}) {
croak "Key fields must be defined for both master and slave backends";
}
$slave->reset;
my ($entry,$filter,$key,$count,@non_keys, $slave_entry_attrs,
%slave_keys,$master_entry,$flag,$master_tmp,$slave_tmp,$msg);
foreach $key (split ',', $slave->{key_fields}) {
$slave_keys{$key} = "";
}
foreach (grep {! exists $slave_keys{$_}} $slave->get_attribute_names) {
push @non_keys, $_;
}
my (%seen, @master_only, @slave_only);
@seen{$slave->get_cannonical_attribute_names} = ();
foreach ($master->get_cannonical_attribute_names) {
push (@master_only,$_) unless exists $seen{$_};
lib/AddressBook.pm view on Meta::CPAN
$slave_tmp->delete(attrs=>\@slave_only);
if (AddressBook::Entry::compare($slave_tmp,$master_tmp)) {
$msg = "**entries match**\n";
if ($args{debug}) {print $msg}
if ($args{msg_function}) {&{$args{msg_function}}($msg)}
} else {
$msg = "slave entry timestamp: " . $entry->{timestamp} . "\n";
$msg .= "master entry timestamp: " . $master_entry->{timestamp} . "\n";
if ($args{debug}) {print $msg}
if ($args{msg_function}) {&{$args{msg_function}}($msg)}
$flag = Date_Cmp($entry->{timestamp},$master_entry->{timestamp});
if ($flag < 0) {
$msg = "**master is newer**\n";
if ($args{debug}) {print $msg}
if ($args{msg_function}) {&{$args{msg_function}}($msg)}
} else {
$msg = "**slave is newer - updating master**\n";
if ($args{debug}) {print $msg}
if ($args{msg_function}) {&{$args{msg_function}}($msg)}
$slave_entry_attrs = $entry->get(values_only=>1);
$master_entry->replace(attr=>$slave_entry_attrs);
$master->update(entry=>$master_entry,filter=>$filter->{attr}) || croak $master->code;
lib/AddressBook/DB/PDB.pm view on Meta::CPAN
my $self = shift;
my $class = ref $self || croak "Not a method call";
$self->pdb->Write($self->{filename});
}
1;
__END__
=head2 Timestamps
For syncronization purposes, all records which have the "modified" flag set are
timestamped with the current time. All records with have the "modified" flag
unset are timestamped with "0" (very, very old).
=head1 Deleted Records
PDB records which have the "deleted" flag set are removed as part of the initialization
process. The "archive" flag is ignored.
=head1 Categories
For convienience, a record's category is treated like any other attribute. New
categories are created as necessary. Moving a record to a new category will achieve
the expected result during synchronization.
However, because renaming a category does
not cause affected records to be marked as "modified", category renaming operations will
be lost during synchronization.
( run in 0.728 second using v1.01-cache-2.11-cpan-94b05bcf43c )