Hi David, On Tuesday 02 August 2005 02:05, David Wood wrote: > However, if I test with the attached simple test program and test data, > I get the following output: > > Person1,+1 098 7654321 > Person2,+1 123 4567890 > Can't call method "exists" on an undefined value at demo.pl line 25, > <GEN0> line 25. > > > With the unpatched LDIF.pm I didn't get the "can't call method ..." error.
You are right. this change in behaviour was unintended. The attched improved patch should fix it. > Also, recently there was a patch posted to this list to fix the > "lowercase" arg to Net::LDAP::LDIF->new and it looks like your patch > either doesn't include or rebreaks that fix. I don't think so. The patch to fix the unwented automatic lowercasing when reading from Net::LDAP::LDIF was a bug in Net::LDAP::Entry.pm My patch to Net::LDAP::LDAP.pm does not affect this patch You can check this with the modified versions of your files that I have attached also. Please test and provide feedback CU Peter -- Peter Marschall eMail: [EMAIL PROTECTED]
--- lib/Net/LDAP/LDIF.pm 2005-04-26 00:54:39.000000000 +0200
+++ lib/Net/LDAP/LDIF.pm 2005-08-06 18:20:42.000000000 +0200
@@ -9,7 +9,7 @@
require Net::LDAP::Entry;
use vars qw($VERSION);
-$VERSION = "0.16";
+$VERSION = "0.16_01";
my %mode = qw(w > r < a >>);
@@ -79,35 +79,49 @@
sub _read_lines {
my $self = shift;
- my @ldif;
+ my $fh = $self->{'fh'};
+ my @ldif = ();
+ my $entry = '';
+ my $in_comment = 0;
+ my $entry_completed = 0;
+ my $ln;
- {
- local $/ = "";
- my $fh = $self->{'fh'};
- my $ln;
- do { # allow comments separated by blank lines
- $ln = $self->{_next_lines} || scalar <$fh>;
- unless ($ln) {
- $self->{_next_lines} = '';
- $self->{_current_lines} = '';
- $self->eof(1);
- return;
- }
- $ln =~ s/\n //sg;
- $ln =~ s/^#.*\n//mg;
- chomp($ln);
- $self->{_current_lines} = $ln;
- } until ($self->{_current_lines} || $self->eof());
- chomp(@ldif = split(/^/, $ln));
- do {
- $ln = scalar <$fh> || '';
- $self->eof(1) unless $ln;
- $ln =~ s/\n //sg;
- $ln =~ s/^#.*\n//mg;
- chomp($ln);
- $self->{_next_lines} = $ln;
- } until ($self->{_next_lines} || $self->eof());
+ return @ldif if ($self->eof());
+
+ while (defined($ln = $self->{_buffered_line} || scalar <$fh>)) {
+ delete($self->{_buffered_line});
+ if ($ln =~ /^#/o) { # ignore 1st line of comments
+ $in_comment = 1;
+ }
+ else {
+ if ($ln =~ /^[ \t]/o) { # append wrapped line (if not in a comment)
+ $entry .= $ln if (!$in_comment);
+ }
+ else {
+ $in_comment = 0;
+ if ($ln =~ /^\r?\n$/o) {
+ # ignore empty line on start of entry
+ # empty line at non-empty entry indicate entry completion
+ $entry_completed++ if (length($entry));
+ }
+ else {
+ if ($entry_completed) {
+ $self->{_buffered_line} = $ln;
+ last;
+ }
+ else {
+ # append non-empty line
+ $entry .= $ln;
+ }
+ }
+ }
+ }
}
+ $self->eof(1) if (!defined($ln));
+ $entry =~ s/\r?\n //sgo; # un-wrap wrapped lines
+ $entry =~ s/\r?\n\t/ /sgo; # OpenLDAP extension !!!
+ @ldif = split(/^/, $entry);
+ map { s/\r?\n$//; } @ldif;
@ldif;
}
@@ -177,7 +191,7 @@
my $dn = shift @ldif;
- if (length($1)) {
+ if (length($1)) { # $1 is the optional colon from above
eval { require MIME::Base64 };
if ($@) {
$self->_error($@, @ldif);
demo.pl
Description: Perl program
# xxx version: 1 # xxx #xxx ###x #x #x #x dn: cn=Person1,mail=whatever objectclass: top objectclass: person objectclass: organizationalPerson objectclass: inetOrgPerson objectclass: mozillaAbPersonObsolete givenName: Person1 cn: Person1 mail: whatever modifytimestamp: 0Z homePhone: +1 098 7654321 homephone: +1 098 7654320 #xxxx #x dn: cn=Person2,mail=whatever objectclass: top objectclass: person objectclass: organizationalPerson objectclass: inetOrgPerson objectclass: mozillaAbPersonObsolete givenName: Person2 sn: Person2 cn: Person2 mail: whatever modifytimestamp: 0Z homePhone: +1 123 4567890 homephone: +1 123 4567891 #xxx #xxx #x dn: cn=Person3,mail=whatever objectclass: top objectclass: person objectclass: organizationalPerson objectclass: inetOrgPerson objectclass: mozillaAbPersonObsolete givenName: Person3 sn: Person3 cn: Person3 mail: whatever modifytimestamp: 0Z homePhone: +1 123 4567890 # EOF # no, here is EOF
