man Net::LDAP::LDIF () - LDIF reading and writing

NAME

Net::LDAP::LDIF - LDIF reading and writing

SYNOPSIS

 use Net::LDAP::LDIF;

 $ldif = Net::LDAP::LDIF->new( "file.ldif", "r", onerror => 'undef' );
 while( not $ldif->eof ( ) ) {
   $entry = $ldif->read_entry ( );
   if ( $ldif->error ( ) ) {
     print "Error msg: ", $ldif->error ( ), "\n";
     print "Error lines:\n", $ldif->error_lines ( ), "\n";
   } else {
     # do stuff
   }
 }
 $ldif->done ( );

DESCRIPTION

Net::LDAP::LDIF provides a means to convert between Net::LDAP::Entry objects and LDAP entries represented in LDIF format files. Reading and writing are supported and may manipulate single entries or lists of entries.

As when reading an entire file into memory with perl normally, take into account the possibility of memory use when loading an LDIF file in one go.

CONSTRUCTOR

new ( FILE )
Open the file read-only. CWFILE may be the name of a file or an already open filehandle. If CWFILE begins or ends with a CW| then CWFILE will be passed directly to CWopen.
new ( FILE, MODE, OPTIONS )
Open the file with the given CWMODE, eg w or a. CWFILE may be the name of a file or an already open filehandle. If CWFILE begins or ends with a CW| then CWFILE will be passed directly to CWopen.
encode => 'none' | 'canonical' | 'base64'
Some DN values in LDIF cannot be written verbatim and have to be encoded in some way:
'none'
The default.
'canonical'
See canonical_dn in Net::LDAP::Util.
'base64'
Use base64.
onerror => 'die' | 'warn' | undef
Specify what happens when an error is detected.
'die'
CWNet::LDAP::LDIF will croak with an appropriate message.
'warn'
CWNet::LDAP::LDIF will warn with an appropriate message.
undef
CWNet::LDAP::LDIF will warn with an appropriate message if CW-w is in effect. The method that was called will return CWundef.
change => 1
Write entry changes to the LDIF file instead of the entries itself. I.e. write LDAP operations acting on the entries to the file instead of the entries contents.
lowercase => 1
Convert attribute names to lowercase when writing.
sort => 1
Sort attribute names when writing entries according to the rule: objectclass first then all other attributes alphabetically sorted
version => '1'
Set the LDIF version to write to the resulting LDIF file. According to RFC 2849 currently the only legal value for this option is 1. When this option is set Net::LDAP::LDIF tries to adhere more strictly to the LDIF specification in RFC2489 in a few places. The default is undef meaning no version information is written to the LDIF file.
wrap => 78
Number of columns where output line wrapping shall occur. Default is 78. Setting it to 40 or lower inhibits wrapping.

METHODS

read_entry ( )
Read one entry from the file and return it as a CWNet::LDAP::Entry object.
eof ( )
Returns true when the end of the file is reached.
write_entry ( ENTRIES )
Write the entries to the LDIF file.
write_version ( )
If the object's version is defined, this method allows to explicitely write the version before an entry is written. If not called explicitely, it gets called automatically when writing the first entry.
version ( [ VERSION ] )
If called without arguments it returns the version of the LDIF file or undef if no version has been set. If called with an argument it sets the LDIF version to VERSION. According to RFC 2849 currently the only legal value for VERSION is 1.
handle ( )
Returns the file handle the CWNet::LDAP::LDIF object reads fromi or writes to.
done ( )
This method signals that the LDIF object is no longer needed. If a file was opened automatically when the object was created it will be closed. This method is called automatically via DESTROY when the object goes out of scope.
error ( )
Returns error message if error was found.
error_lines ( )
Returns lines that resulted in error.
current_entry ( )
Returns the current CWNet::LDAP::Entry object.
current_lines ( )
Returns the lines that generated the current CWNet::LDAP::Entry object.
next_lines ( )
Returns the lines that will generate the next CWNet::LDAP::Entry object.

AUTHOR

Graham Barr <gbarr@pobox.com>.

Please report any bugs, or post any suggestions, to the perl-ldap mailing list <perl-ldap@perl.org>.

COPYRIGHT

Copyright (c) 1997-2004 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.