AddressBook

 view release on metacpan or  search on metacpan

examples/ldap-abook.conf  view on Meta::CPAN

179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/>
<abookentry
        driver="HTML"
/>
<abooknew
        driver="HTML"
/>
<phonelist
        driver="HTML"
        write_format="Tr(td([$fullname . ($description ? &quot; ($description)&quot; : ''),
                         table(Tr([map{($attributes{$_}) ? td([$_,$attributes{$_}]) : '' } ('Home','Work','Pager','Mobile') ]))]))"
        intra_attr_sep="&lt;br&gt;"
/>
<LDAP
        objectclass="abookPerson"
        hostname="localhost"
        base="o=abook"
        dn_calculate="'cn='.$cn"
        username="cn=Manager,o=abook"
        password="secret"
        key_fields = "cn"

html/index.html  view on Meta::CPAN

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<p>More of these will be added in the future.
<ul>
  <li><a href="http://perl-abook.sourceforge.net/ChangeLog">Change History</a>
  <li><a href="http://www.sourceforge.net/projects/perl-abook">perl-abook project page</a>
  <li><a href="http://sourceforge.net/mail/?group_id=9692">perl-abook-tech mailing list</a>
</ul>
<hr>
<h3>Features</h3>
<ul>
  <li>Configurable attribute mapping
  <li>Simple methods for moving entries between backend databases.
  <li>Entries can be <a href=AddressBook.html#sync>synchronized</a> between backend
databases of different types.
  <li>Attributes can be calculated "on the fly" (e.g. based on other attributes).
</ul>
<hr>
<h3>Requirements</h3>
<p>The following perl library modules are required:
<ul>
  <li>XML::DOM

lib/AddressBook.pm  view on Meta::CPAN

376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
  @names = $abook->get_cannonical_attribute_names;
 
Returns a list of valid cannonical attribute names
 
=cut
 
sub get_cannonical_attribute_names {
  my $self=shift;
  my $class = ref $self || croak "Not a method call.";
  my @fields = $self->get_attribute_names;
  my @names = map {$self->{config}->{db2generic}->{$self->{db_name}}->{$_}} @fields;
  return @names;
}
 
1;
__END__
 
=head1 AUTHOR
 
Mark A. Hershberger, <mah@everybody.org>
David L. Leigh, <dleigh@sameasiteverwas.net>

lib/AddressBook/DB/BBDB.pm  view on Meta::CPAN

353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
      $zip = $1;
      if ($2) {
        $zip = "($zip $2)";
      }
    } elsif ($zip =~ m/^(\S+) (\S+)$/) {
      $zip = "(\"$1\" \"$2\")";
    } else {
      $zip = quoted_stringify($zip);
    }
    local($_);
    my @fields = map {quoted_stringify($_)} @$i[0..5];
    push @address, "[@fields $zip]";
  }
  push @result, "(@address)";
} else {
  push @result, 'nil';
}
 
if (@$net) {
  my @net;
  foreach $i (@$net) {

lib/AddressBook/DB/BBDB.pm  view on Meta::CPAN

415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
  return $result;
}
 
########################################################################
 
sub note_names {
  my $self = shift;
  my $notes = $self->part('notes');
  return () unless @$notes;
  local ($_);
  my @fields = map { $_->[0] } @$notes;
  return @fields;
}
 
sub simple {
  my ($file,$bbdb) = @_;
  local ($_);
  if (@_ == 1) {                #we're reading
    open(INFILE,$file) or croak "Error opening file: $!";
    <INFILE>;
    $_ = <INFILE>; s/\(([^)])\)/$1/;

lib/AddressBook/DB/BBDB.pm  view on Meta::CPAN

481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
=head1 SYNOPSIS
 
  use BBDB;
  my $x = new BBDB();
  $x->decode($string);
  my $str = $x->encode();
  # At this point, subject to the BUGS below
  # $str is the same as $string
 
  my $allR = BBDB::simple('/home/henry/.bbdb');
  map { print $_->part('first')} @$allR;   # print out all the first names
 
 
=head1 DESCRIPTION
 
 
=head2 Data Format
 
The following is the data layout for a BBDB record.  I have created a
sample record with my own data.  Each field is just separated by a
space.  I have added comments to the right

lib/AddressBook/DB/HTML.pm  view on Meta::CPAN

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
AddressBook::DB::HTML currently supports only the sequential write method. 
 
Behavior can be modified using the following options:
 
=over 4
 
=item write_format
 
The write_format string is eval'd to determine how the entry is written.  The default write_format string is:
 
  'table(Tr([map{td(["$_:",$attributes{$_}])} keys %attributes]))'
 
This displays the entry in a table with attribute names on the left and values on the right.
As can be seen, CGI.pm tag-generating functions can be used in format strings. The "%attributes"
hash is available for use.  The keys of %attributes are HTML backend attribute names, and the
values are the corresponding attribute values.  Specific attributes can also be referenced by
name using a scalar with the same name as the attribute.   For example,
 
  'Name: $Name'
 
Assuming that "Name" is a valid HTML attribute, this format string will display entry names.

lib/AddressBook/DB/HTML.pm  view on Meta::CPAN

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  'Name: $attributes{Name}'
 
The HTML backend recognizes the string "keys %attributes", and substitues an expression which
ensures that the "order" meta-attribute is obeyed.
 
=item form_format
 
The form_format string is eval'd to construct an html entry form.  The default form_format string is:
 
  table(Tr({-valign=>"TOP"},[map{td([$_,$attributes{$_}])} keys %attributes]))
 
Which generates a table of fields with labels on the left.  The input type is based on the attribute type,
eg. "text" attributes appear as text input fields, "boolean" attributes appear as checkbox inputs, etc...
The default values of the entry fields are the current values of the entry's attributes.
 
=item intra_attr_sep
 
The string to use in joining multiple instances of the same attribute.  The default is "<br>"
 
=back

lib/AddressBook/DB/HTML.pm  view on Meta::CPAN

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@ISA = qw(AddressBook);
 
sub new {
  my $class = shift;
  my $self = {};
  bless ($self,$class);
  my %args = @_;
  foreach (keys %args) {
    $self->{$_} = $args{$_};
  }
  unless ($self->{write_format}) {$self->{write_format} = 'table(Tr({-valign=>"TOP"},[map{td(["$_:",$attributes{$_}])} keys %attributes]))'}
  unless ($self->{form_format}) {$self->{form_format} = 'table(Tr({-valign=>"TOP"},[map{td([$_,$attributes{$_}])} keys %attributes]))'}
  unless ($self->{intra_attr_sep}) {$self->{intra_attr_sep} = '<br>'}
  return $self;
}
 
sub write {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  my $entry = shift;
  my ($format,$ret,%attributes,$key,$url,$desc);
  $entry->calculate;
  my $attr = $entry->get(db=>$self->{db_name});
  foreach $key (keys %{$attr}) {
    if ($attr->{$key}->{meta}->{type} =~ /^(text|textblock|boolean|date|phone)$/) {
      $attributes{$key} = join ($self->{intra_attr_sep},@{$attr->{$key}->{value}});
    } elsif ($attr->{$key}->{meta}->{type} eq "url") {
      $attributes{$key} = join ($self->{intra_attr_sep},
                              map {a({-href=>$_},$_)} @{$attr->{$key}->{value}});
    } elsif ($attr->{$key}->{meta}->{type} eq "lurl") {
      $attributes{$key} = join ($self->{intra_attr_sep},
                              map {
                                ($url,$desc) = split (/\s+/, $_, 2);
                                $desc ||= $url;
                                a({-href=>$url},$desc)} @{$attr->{$key}->{value}});
    } elsif ($attr->{$key}->{meta}->{type} eq "email") {
      $attributes{$key} = join ($self->{intra_attr_sep},
                              map {a({-href=>"mailto:$_"},$_)} @{$attr->{$key}->{value}});
    }
  }
  $format = $self->{write_format};
  foreach (values %{$self->{config}->{db2generic}->{$self->{db_name}}}) {
    $format =~ s/\$($_)/\$attributes{$1}/g;
  }
  my @attributes = (sort {$attr->{$a}->{meta}->{order} <=> $attr->{$b}->{meta}->{order}} (keys %attributes));
  $format =~ s'keys %attributes'@attributes'g;
  eval qq{\$ret = $format}; warn "Syntax error in HTML backend \"write_format\": $@" if $@;
  return $ret;

lib/AddressBook/DB/HTML.pm  view on Meta::CPAN

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#$entry->calculate;
my $attr = $entry->get(db=>$self->{db_name});
my %attributes = %{$entry->get(db=>$self->{db_name},values_only=>1)};
foreach $key (keys %attributes) {
  if ($attr->{$key}->{meta}->{type} =~ /^(text|url|lurl|email|date|phone)$/) {
    if ($attr->{$key}->{meta}->{read_only} =~ /yes/i) {
      $result{$key} = join ($self->{intra_attr_sep},
                            @{$attributes{$key}});
    } else {
      $result{$key} = join ($self->{intra_attr_sep},
                            map {textfield(-name=>$key,
                                           -size=>30,
                                           -override=>1,
                                           -default=>$_)} @{$attributes{$key}});
    }
  } elsif ($attr->{$key}->{meta}->{type} eq "textblock") {
    if ($attr->{$key}->{meta}->{read_only} =~ /yes/i) {
      $result{$key} = join ($self->{intra_attr_sep},
                            @{$attributes{$key}});
    } else {
      $result{$key} = join ($self->{intra_attr_sep},
                            map {textarea(-name=>$key,
                                           -columns=>30,
                                           -rows=>10,
                                           -override=>1,
                                           -default=>$_)} @{$attributes{$key}});
    }
  } elsif ($attr->{$key}->{meta}->{type} eq "select") {
    if ($attr->{$key}->{meta}->{read_only} =~ /yes/i) {
      $result{$key} = join ($self->{intra_attr_sep},
                                @{$attributes{$key}});
    } else {

lib/AddressBook/Entry.pm  view on Meta::CPAN

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
=head1 SYNOPSIS
 
An AddressBook::Entry object contains an addressbook entry's attributes,
attribute metadata, and information about how to translate the attributes between
different backend databases.  An Entry's attributes can be accessed  using
either cannonical attribute names, or database-specific names.
 
=head1 DESCRIPTION
 
The following examples assume  a configuration file which maps the cannonical
attribute named "lastname" to the ldap attribute named "sn" and the cannonical
attribute named "firstname" to the ldap attribute named "givenname".  For example,
 
  <field name="lastname">       
    <db type="LDAP" name="sn">
  </field>
  <field name="firstname">
    <db type="LDAP" name="givenname">
  </field>

lib/AddressBook/Entry.pm  view on Meta::CPAN

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
    print $entry->dump
 
Returns the (cannonical) attribute names and values.  Primarily used for
debugging purposes.
 
=cut
 
sub dump {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  return map {"$_ -> ". join(", ", @{$self->{attr}->{$_}}). "\n"}
    keys %{$self->{attr}}
}
1;
__END__
 
=head1 AUTHOR
 
Mark A. Hershberger, <mah@everybody.org>
David L. Leigh, <dleigh@sameasiteverwas.net>



( run in 0.263 second using v1.01-cache-2.11-cpan-e5176c747c2 )