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 new ( FILE [[, MODE ], OPTIONS ] )
35 Open the file with the given mode.
36
37 "FILE" may be the name of a file or an already open filehandle. If
38 "FILE" begins or ends with a "|" then "FILE" will be passed
39 directly to "open".
40
41 "MODE" can be any of the modes allowed for Perl's open() function,
42 potentially extended by PerlIO layers as described in perlopentut.
43 Alternatively, it can be one of the mode indicators "r", "r+", "w",
44 "w+", "a", "a+" known from C's fopen() function, which get mapped
45 to their Perl counterparts. If "MODE" is omitted, it defaults to
46 "r" for reading.
47
48 "OPTIONS" is a list of name/value pairs, recognizing:
49
50 encode => 'none' | 'canonical' | 'base64'
51 Some DN values in LDIF cannot be written verbatim and have to
52 be encoded in some way:
53
54 'none'
55 The default.
56
57 'canonical'
58 See "canonical_dn" in Net::LDAP::Util.
59
60 'base64'
61 Use base64.
62
63 onerror => 'die' | 'warn' | undef
64 Specify what happens when an error is detected.
65
66 'die'
67 "Net::LDAP::LDIF" will croak with an appropriate message.
68
69 'warn'
70 "Net::LDAP::LDIF" will warn with an appropriate message.
71
72 undef
73 "Net::LDAP::LDIF" will warn with an appropriate message if
74 "-w" is in effect. The method that was called will return
75 "undef".
76
77 change => 1
78 Write entry changes to the LDIF file instead of the entries
79 itself. I.e. write LDAP operations acting on the entries to
80 the file instead of the entries contents.
81
82 lowercase => 1
83 Convert attribute names to lowercase when writing.
84
85 sort => 1
86 Sort attribute names when writing entries according to the
87 rule: objectclass first then all other attributes
88 alphabetically sorted
89
90 version => '1'
91 Set the LDIF version to write to the resulting LDIF file.
92
93 According to RFC 2849 currently the only legal value for this
94 option is 1.
95
96 When this option is set Net::LDAP::LDIF tries to adhere more
97 strictly to the LDIF specification in RFC2489 in a few places.
98
99 The default is undef meaning no version information is written
100 to the LDIF file.
101
102 wrap => 78
103 Number of columns where output line wrapping shall occur.
104
105 Default is 78. Setting it to 40 or lower inhibits wrapping.
106
107 raw => REGEX
108 Use REGEX to denote the names of attributes that are to be
109 considered binary in search results.
110
111 When running on Perl 5.8 and this option is given Net::LDAP
112 converts all values of attributes not matching this REGEX into
113 Perl UTF-8 strings so that the regular Perl operators (pattern
114 matching, ...) can operate as one expects even on strings with
115 international characters.
116
117 If this option is not given or the version of Perl Net::LDAP is
118 running on is too old strings are encoded the same as in
119 earlier versions of perl-ldap.
120
121 Example: raw => qr/(?i:^jpegPhoto|;binary)/
122
124 read_entry ( )
125 Read one entry from the file and return it as a "Net::LDAP::Entry"
126 object.
127
128 eof ( )
129 Returns true when the end of the file is reached.
130
131 write_entry ( ENTRIES )
132 Write the entries to the LDIF file.
133
134 write_version ( )
135 If the object's version is defined, this method allows one to
136 explicitly write the version before an entry is written.
137
138 If not called explicitly, it gets called automatically when
139 writing the first entry.
140
141 version ( [ VERSION ] )
142 If called without arguments it returns the version of the LDIF file
143 or undef if no version has been set. If called with an argument it
144 sets the LDIF version to VERSION.
145
146 According to RFC 2849 currently the only legal value for VERSION is
147 1.
148
149 handle ( )
150 Returns the file handle the "Net::LDAP::LDIF" object reads from or
151 writes to.
152
153 done ( )
154 This method signals that the LDIF object is no longer needed. If a
155 file was opened automatically when the object was created it will
156 be closed. This method is called automatically via DESTROY when the
157 object goes out of scope.
158
159 error ( )
160 Returns error message if error was found.
161
162 error_lines ( )
163 Returns lines that resulted in error.
164
165 current_entry ( )
166 Returns the current "Net::LDAP::Entry" object.
167
168 current_lines ( )
169 Returns the lines that generated the current "Net::LDAP::Entry"
170 object.
171
172 next_lines ( )
173 Returns the lines that will generate the next "Net::LDAP::Entry"
174 object.
175
177 Graham Barr <gbarr@pobox.com>.
178
179 Please report any bugs, or post any suggestions, to the perl-ldap
180 mailing list <perl-ldap@perl.org>.
181
183 Copyright (c) 1997-2004 Graham Barr. All rights reserved. This program
184 is free software; you can redistribute it and/or modify it under the
185 same terms as Perl itself.
186
187
188
189perl v5.16.3 2018-10-30 Net::LDAP::LDIF(3)