Net::LDAP::LDIF(3)
π NAME π
Net::LDAP::LDIF β LDIF reading and writing. Yup bestie, this is the Net::LDAP::LDIF(3) page in User Contributed Perl Documentation, and we're about to make LDIF make sense. π
β¨ SYNOPSIS β¨
Okay so here's the example, and yes the code stays exactly as it is because code is sacred:
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 gives you a way to convert between Net::LDAP::Entry objects and LDAP entries represented in LDIF format files. Reading and writing are both supported, and it can manipulate single entries or lists of entries. Obsessed.
Also, heads up: just like when you read an entire file into memory with perl normally, take into account the possibility of memory use when loading an LDIF file in one go. No cap, that's the memory vibe check. π
π¦ SPECIAL FEATURES π¦
By default, Net::LDAP::LDIF supports reading attribute values from URLs of type file://.
When Gisle Aas' LWP module package is installed, Net::LDAP::LDIF uses it to also support reading data from the URL types supported by these modules β most prominently http://, https://, and ftp:// resources. This extended feature is dynamically detected at runtime. Literally detected at runtime, iykyk. β¨
π CONSTRUCTOR π
new ( FILE [[, MODE ], OPTIONS ] )
Open the file with the given mode. Cute. Here's the breakdown:
FILEmay be the name of a file or an already open filehandle. IfFILEbegins or ends with a|thenFILEwill be passed directly toopen. Yes, that's a pipe vibe.MODEcan be any of the modes allowed for Perl'sopen()function, potentially extended by PerlIO layers as described inperlopentut. Alternatively, it can be one of the mode indicatorsr,r+,w,w+,a,a+known from C'sfopen()function, which get mapped to their Perl counterparts. IfMODEis omitted, it defaults torfor reading.OPTIONSis a list of name/value pairs, recognizing: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'β seecanonical_dninNet::LDAP::Util.'base64'β use base64.
onerror => 'die' | 'warn' | 'undef'β specify what happens when an error is detected:'die'βNet::LDAP::LDIFwill croak with an appropriate message.'warn'βNet::LDAP::LDIFwill warn with an appropriate message.'undef'βNet::LDAP::LDIFwill warn with an appropriate message if-wis in effect. The method that was called will returnundef. Note this value is the string'undef', not theundefvalue. Bestie, read that twice.
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:objectclassfirst then all other attributes alphabetically sorted.version => '1'β set the LDIF version to write to the resulting LDIF file.wrap => 78β number of columns where output line wrapping shall occur.- Default is
78. Setting it to40or lower inhibits wrapping.
- Default is
raw => REGEXβ useREGEXto denote the names of attributes that are to be considered binary when reading.- When this option is given,
Net::LDAPconverts all values of attributes not matching thisREGEXinto 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, attribute values are treated as byte strings.
- Example:
- When this option is given,
raw => qr/(?i:^jpegPhoto|;binary)/
π METHODS π
read_entry ( )β read one entry from the file and return it as aNet::LDAP::Entryobject. In scalar mode, theNet::LDAP::Entryobject is returned alone, while in list mode a list is returned consisting of theNet::LDAP::Entryobject as first element followed by allNet::LDAP::Controlobjects that were part of the LDIF entry. See RFC 2849 for details.eof ( )β returns true when the end of the file is reached.write_entry ( ENTRY [, OPTIONS ], ... )β write entries to the LDIF file. The arguments accepted are a list of entries, optionally interspersed with options belonging to the preceding entry. For each entry,OPTIONSis a list of key-value pairs, recognizing:control => CONTROLcontrol => [ CONTROL, ... ]
See CONTROLS in Net::LDAP.
write_version ( )β if the object's version is defined, this method allows one to explicitly write the version before an entry is written. If not called explicitly, it gets called automatically when writing the first entry.version ( [ VERSION ] )β if called without arguments it returns the version of the LDIF file orundefif no version has been set. If called with an argument it sets the LDIF version toVERSION. According to RFC 2849 currently the only legal value forVERSIONis1.handle ( )β returns the file handle theNet::LDAP::LDIFobject reads from 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 viaDESTROYwhen 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 currentNet::LDAP::Entryobject.current_lines ( )β returns the lines that generated the currentNet::LDAP::Entryobject.next_lines ( )β returns the lines that will generate the nextNet::LDAP::Entryobject.
π AUTHOR π
The icon behind this is 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.
Bestie, that's the whole Net::LDAP::LDIF(3) manual page. Source/version: perl v5.42.0; date: 2024-01-02. Mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-ldap 0.68-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms