=head1 NAME Net::LDAP::LDIF - LDIF reading and writing =head1 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 ( ); =head1 DESCRIPTION B provides a means to convert between L 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. =head1 CONSTRUCTOR =over 4 =item new ( FILE ) Open the file read-only. C may be the name of a file or an already open filehandle. If C begins or ends with a C<|> then C will be passed directly to C. =item new ( FILE, MODE, OPTIONS ) Open the file with the given C, eg "w" or "a". C may be the name of a file or an already open filehandle. If C begins or ends with a C<|> then C will be passed directly to C. =over 4 =item encode =E 'none' | 'canonical' | 'base64' Some DN values in LDIF cannot be written verbatim and have to be encoded in some way: =over 4 =item 'none' The default. =item 'canonical' See L. =item 'base64' Use base64. =back =item onerror =E 'die' | 'warn' | undef Specify what happens when an error is detected. =over 4 =item 'die' C will croak with an appropriate message. =item 'warn' C will warn with an appropriate message. =item undef C will warn with an appropriate message if C<-w> is in effect. The method that was called will return C. =back =item change =E 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. =item lowercase =E 1 Convert attribute names to lowercase when writing. =item sort =E 1 Sort attribute names when writing entries according to the rule: objectclass first then all other attributes alphabetically sorted =item version =E '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 I<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 I meaning no version information is written to the LDIF file. =item wrap =E 78 Number of columns where output line wrapping shall occur. Default is 78. Setting it to 40 or lower inhibits wrapping. =item raw =E REGEX Use REGEX to denote the names of attributes that are to be considered binary in search results. When running on Perl 5.8 and this option is given Net::LDAP converts all values of attributes not matching this REGEX into Perl UTF-8 strings so that the regular Perl operators (pattern matching, ...) can operate as one expects even on strings with international characters. If this option is not given or the version of Perl Net::LDAP is running on is too old strings are encodeed the same as in earlier versions of perl-ldap. Example: raw =E qr/(?i:^jpegPhoto|;binary)/ =back =back =head1 METHODS =over 4 =item read_entry ( ) Read one entry from the file and return it as a C object. =item eof ( ) Returns I when the end of the file is reached. =item write_entry ( ENTRIES ) Write the entries to the LDIF file. =item 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. =item 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 I<1>. =item handle ( ) Returns the file handle the C object reads from or writes to. =item 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. =item error ( ) Returns error message if error was found. =item error_lines ( ) Returns lines that resulted in error. =item current_entry ( ) Returns the current C object. =item current_lines ( ) Returns the lines that generated the current C object. =item next_lines ( ) Returns the lines that will generate the next C object. =back =head1 AUTHOR Graham Barr Egbarr@pobox.comE. Please report any bugs, or post any suggestions, to the perl-ldap mailing list Eperl-ldap@perl.orgE. =head1 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. =cut