1Net::LDAP::LDIF(3) User Contributed Perl Documentation Net::LDAP::LDIF(3)
2
3
4
6 Net::LDAP::LDIF - LDIF reading and writing
7
9 use Net::LDAP::LDIF;
10
11 $ldif = Net::LDAP::LDIF->new( "file.ldif", "r", onerror => 'undef' );
12 while ( not $ldif->eof ( ) ) {
13 $entry = $ldif->read_entry ( );
14 if ( $ldif->error ( ) ) {
15 print "Error msg: ", $ldif->error ( ), "\n";
16 print "Error lines:\n", $ldif->error_lines ( ), "\n";
17 } else {
18 # do stuff
19 }
20 }
21 $ldif->done ( );
22
24 Net::LDAP::LDIF provides a means to convert between Net::LDAP::Entry
25 objects and LDAP entries represented in LDIF format files. Reading and
26 writing are supported and may manipulate single entries or lists of
27 entries.
28
29 As when reading an entire file into memory with perl normally, take
30 into account the possibility of memory use when loading an LDIF file in
31 one go.
32
34 By default, Net::LDAP::LDIF supports reading attribute values from URLs
35 of type "file://".
36
37 When Gisle Aas' LWP module package is installed, Net::LDAP::LDIF uses
38 it to also support reading data from the URL types supported by these
39 modules; most prominently "http://", "https://", and "ftp://"
40 resources. This extended feature is dynamically detected at runtime.
41
43 new ( FILE [[, MODE ], OPTIONS ] )
44 Open the file with the given mode.
45
46 "FILE" may be the name of a file or an already open filehandle. If
47 "FILE" begins or ends with a "|" then "FILE" will be passed
48 directly to "open".
49
50 "MODE" can be any of the modes allowed for Perl's open() function,
51 potentially extended by PerlIO layers as described in perlopentut.
52 Alternatively, it can be one of the mode indicators "r", "r+", "w",
53 "w+", "a", "a+" known from C's fopen() function, which get mapped
54 to their Perl counterparts. If "MODE" is omitted, it defaults to
55 "r" for reading.
56
57 "OPTIONS" is a list of name/value pairs, recognizing:
58
59 encode => 'none' | 'canonical' | 'base64'
60 Some DN values in LDIF cannot be written verbatim and have to
61 be encoded in some way:
62
63 'none'
64 The default.
65
66 'canonical'
67 See "canonical_dn" in Net::LDAP::Util.
68
69 'base64'
70 Use base64.
71
72 onerror => 'die' | 'warn' | undef
73 Specify what happens when an error is detected.
74
75 'die'
76 "Net::LDAP::LDIF" will croak with an appropriate message.
77
78 'warn'
79 "Net::LDAP::LDIF" will warn with an appropriate message.
80
81 undef
82 "Net::LDAP::LDIF" will warn with an appropriate message if
83 "-w" is in effect. The method that was called will return
84 "undef".
85
86 change => 1
87 Write entry changes to the LDIF file instead of the entries
88 itself. I.e. write LDAP operations acting on the entries to
89 the file instead of the entries contents.
90
91 lowercase => 1
92 Convert attribute names to lowercase when writing.
93
94 sort => 1
95 Sort attribute names when writing entries according to the
96 rule: objectclass first then all other attributes
97 alphabetically sorted
98
99 version => '1'
100 Set the LDIF version to write to the resulting LDIF file.
101
102 According to RFC 2849 currently the only legal value for this
103 option is 1.
104
105 When this option is set Net::LDAP::LDIF tries to adhere more
106 strictly to the LDIF specification in RFC2489 in a few places.
107
108 The default is undef meaning no version information is written
109 to the LDIF file.
110
111 wrap => 78
112 Number of columns where output line wrapping shall occur.
113
114 Default is 78. Setting it to 40 or lower inhibits wrapping.
115
116 raw => REGEX
117 Use REGEX to denote the names of attributes that are to be
118 considered binary when reading.
119
120 When this option is given, Net::LDAP converts all values of
121 attributes not matching this REGEX into Perl UTF-8 strings so
122 that the regular Perl operators (pattern matching, ...) can
123 operate as one expects even on strings with international
124 characters.
125
126 If this option is not given, attribute values are treated as
127 byte strings.
128
129 Example: raw => qr/(?i:^jpegPhoto|;binary)/
130
132 read_entry ( )
133 Read one entry from the file and return it as a "Net::LDAP::Entry"
134 object.
135
136 eof ( )
137 Returns true when the end of the file is reached.
138
139 write_entry ( ENTRY [, OPTIONS ], ... )
140 Write entries to the LDIF file.
141
142 The arguments accepted are a list of entries, optionally
143 interspersed with options belonging to the preceding entry.
144
145 For each entry, "OPTIONS" is a list of key-value pairs,
146 recognizing:
147
148 control => CONTROL
149 control => [ CONTROL, ... ]
150 See "CONTROLS" in Net::LDAP.
151
152 write_version ( )
153 If the object's version is defined, this method allows one to
154 explicitly write the version before an entry is written.
155
156 If not called explicitly, it gets called automatically when
157 writing the first entry.
158
159 version ( [ VERSION ] )
160 If called without arguments it returns the version of the LDIF file
161 or undef if no version has been set. If called with an argument it
162 sets the LDIF version to VERSION.
163
164 According to RFC 2849 currently the only legal value for VERSION is
165 1.
166
167 handle ( )
168 Returns the file handle the "Net::LDAP::LDIF" object reads from or
169 writes to.
170
171 done ( )
172 This method signals that the LDIF object is no longer needed. If a
173 file was opened automatically when the object was created it will
174 be closed. This method is called automatically via DESTROY when the
175 object goes out of scope.
176
177 error ( )
178 Returns error message if error was found.
179
180 error_lines ( )
181 Returns lines that resulted in error.
182
183 current_entry ( )
184 Returns the current "Net::LDAP::Entry" object.
185
186 current_lines ( )
187 Returns the lines that generated the current "Net::LDAP::Entry"
188 object.
189
190 next_lines ( )
191 Returns the lines that will generate the next "Net::LDAP::Entry"
192 object.
193
195 Graham Barr <gbarr@pobox.com>.
196
197 Please report any bugs, or post any suggestions, to the perl-ldap
198 mailing list <perl-ldap@perl.org>.
199
201 Copyright (c) 1997-2004 Graham Barr. All rights reserved. This program
202 is free software; you can redistribute it and/or modify it under the
203 same terms as Perl itself.
204
205
206
207perl v5.28.1 2015-04-02 Net::LDAP::LDIF(3)