AddressBook
view release on metacpan or search on metacpan
lib/AddressBook/DB/PDB.pm view on Meta::CPAN
A list of PDB field names (not cannonical names) which can be used to uniquely
identify a database record. Ideally the "id" field of PDB records would be used here,
but currently it is not. "Name,First name" is recommended.
=item phone_display
A perl statment which, when eval'd, returns a comma-delimited list of "phone labels".
Valid phone labels are: Work,Home,Fax,Other,E-Mail,Main,Pager,Mobile. The result of
the eval'd phone_display will be used to determine which phone label is default shown
in the PalmOS address list. The first label in the comma-delimited list is used unless
the record has no value for that label, in which case the second label is used unless
it also has no value, in which case the third is used, and so on....
In the phone_display string, other attributes may be referenced as "$<attr>".
For example, if you want the priority of default phone lables to be "Work,Home,E-Mail"
for all records in the "Business" category, and the priority to be "Home,Work,E-Mail"
for all records in all other categories, you could use the following:
phone_display = "($category eq 'Business')
? 'Work,Home,E-Mail'
: 'Home,Work,E-Mail'"
=item intra_attr_sep_char
The character to use when joining multi-valued fields. The default is ' & '.
=back
Any of these options can be specified in the constructor, or in the configuration file.
=cut
use strict;
use PDA::Pilot;
use AddressBook;
use Carp;
use Date::Manip;
use vars qw($VERSION @ISA);
$VERSION = '0.13';
@ISA = qw(AddressBook);
=head2 new
$a = AddressBook->new(source => "PDB");
$a = AddressBook->new(source => "PDB",
port => "/dev/pilot");
If a "pdb" parameter is supplied, it will be used as a reference to an already
created PDA::Pilot::DLP::DBPtr object. Otherwise, if a "port" is supplied,
the user will be prompted to press the hotsync button to establish the connection.
=cut
sub new {
my $class = shift;
my $self = {};
bless ($self,$class);
my %args = @_;
foreach (keys %args) {
$self->{$_} = $args{$_};
}
if (! $self->{pdb}) {
if (! $self->{dlp}) {
my $socket = PDA::Pilot::openPort($self->{port});
print "Now press the HotSync button\n";
$self->{dlp} = PDA::Pilot::accept($socket);
}
$self->{pdb} = $self->{dlp}->open("AddressDB");
}
if (! $self->{pdb}) {
croak "Error: No port, dlp, or pdb specified";
}
$self->reset;
unless (defined $self->{intra_attr_sep_char}) {
$self->{intra_attr_sep_char} = ' & ';
}
return $self;
# croak("PDB file backends are not currently implemented");
# if (-e $self->{file}) {
# $self->{pdb} = PDA::Pilot::File::open($self->{file};
# } else {
# croak("File: ".$self->file." does not exist");
# my $info;
# $info->{name}="AddressDB";
# $info->{type}="DATA";
# $self->{pdb} = PDA::Pilot::File::create($self->{file},$info);
# }
}
sub reset {
my $self = shift;
my $class = ref $self || croak "Not a method call";
$self->{index} = 0;
$self->_read_appinfo;
#$self->_remove_deleted_records;
}
sub read {
my $self = shift;
my $class = ref $self || croak "Not a method call";
my %reverse_category_hash = reverse %{$self->{category_hash}};
my ($i,%attr,$found);
if ($self->{index} < $self->{pdb}->getRecords) {
my $record = PDA::Pilot::Address::Unpack($self->{pdb}->getRecord($self->{index}++));
if ($record->{deleted}) {
$self->{pdb}->deleteRecord($record->{id});
return ($self->read);
}
my %labels = %{$self->_insert_phone_labels($record->{phoneLabel})};
for ($i=0;$i<=$#{$record->{entry}};$i++) {
if (defined $record->{entry}->[$i]) {
@{$attr{$labels{$i}}} = split /$self->{intra_attr_sep_char}/ ,$record->{entry}->[$i];
}
}
my $entry = AddressBook::Entry->new(config=>$self->{config},
( run in 2.171 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )