On Feb 9, 2010, at 10:56 AM, Heiko Jansen wrote:
> Hi there,
> 
> using Net::LDAP I had a problem when I wanted to hand of a stringified 
> version 
> of a single result record (object of type Net::LDAP::Entry): it seems like 
> it's only possible to dump a record directly to a file handle 
> (Net::LDAP::Entry->dump)?!
> 
> So in case anyone else finds this useful (and in case I didn't miss 
> something) 
> I've appended a small patch to Net/LDAP/Entry.pm (and Net/LDAP/Entry.pod) 
> which provides a dumpstr() method to return a stringified record.

I am in two minds as whether to accept this as a change. As the docs state

    This method is intended for debugging purposes and does not treat binary 
attributes specially

    See Net::LDAP::LDIF on how to generate LDIF output

so this really should not be used for passing around entries

Also, anything that can dump to a filehandle can dump to a string.

  open(my $fh,">",\my $buffer);

  then pass $fh as the file handle

Having said that maybe Net::LDAP::Entry could use an ->ldif method

something like (untested)

sub ldif {
  my $self = shift;
  require Net::LDAP::LDIF;
  open(my $fh, ">", \my $buffer);
  my $changes = $self->changes ? 1 : 0;
  my $ldif = Net::LDAP::LDIF->new($fh,"w", changes => $changes);
  $ldif->write_entry($self);
  return $buffer;
}

Graham.

Reply via email to