view release on metacpan or search on metacpan
examples/ldap-abook.conf view on Meta::CPAN
179180181182183184185186187188189190191192193194195196197198199/>
<abookentry
driver=
"HTML"
/>
<abooknew
driver=
"HTML"
/>
<phonelist
driver=
"HTML"
write_format="Tr(td([
$fullname
. (
$description
?
"
; (
$description
)
"
; :
''
),
table(Tr([
map
{(
$attributes
{
$_
}) ? td([
$_
,
$attributes
{
$_
}]) :
''
} (
'Home'
,
'Work'
,
'Pager'
,
'Mobile'
) ]))]))"
intra_attr_sep=
"<br>"
/>
<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
181920212223242526272829303132333435363738<p>More of these will be added in the future.
<ul>
<li><a href=
"http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi?cvsroot=perl-abook"
>perl-abook-tech CVS</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
376377378379380381382383384385386387388389390391392393394395396
@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
353354355356357358359360361362363364365366367368369370371372373
$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
415416417418419420421422423424425426427428429430431432433434435
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
481482483484485486487488489490491492493494495496497498499500501=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
151617181920212223242526272829303132333435AddressBook::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
373839404142434445464748495051525354555657
'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
707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117@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
126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157#$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
678910111213141516171819202122232425=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
436437438439440441442443444445446447448449450451452453454455
$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>