\section{NAME\label{NAME-entry}}


Net::LDAP::Entry - An LDAP entry object

\section{SYNOPSIS\label{SYNOPSIS-entry}\index{synopsis of Net::LDAP::Entry}}
\begin{verbatim}
 use Net::LDAP;
\end{verbatim}
\begin{verbatim}
 $ldap = Net::LDAP->new ( $host );
 $mesg = $ldap->search ( @search_args );
\end{verbatim}
\begin{verbatim}
 my $max = $mesg->count;
 for ( $i = 0 ; $i < $max ; $i++ ) {
   my $entry = $mesg->entry ( $i );
   foreach my $attr ( $entry->attributes ) {
     print join( "\n ", $attr, $entry->get_value( $attr ) ), "\n";
   }
 }
\end{verbatim}
\begin{verbatim}
 # or
\end{verbatim}
\begin{verbatim}
 use Net::LDAP::Entry;
\end{verbatim}
\begin{verbatim}
 $entry = Net::LDAP::Entry->new;
\end{verbatim}
\begin{verbatim}
 $entry->add (
   attr1 => 'value1',
   attr2 => [ qw(value1 value2) ]
 );
\end{verbatim}
\begin{verbatim}
 $entry->delete ( 'unwanted' );
\end{verbatim}
\begin{verbatim}
 $entry->replace (
   attr1 => 'newvalue'
   attr2 => [ qw(new values) ]
 );
\end{verbatim}
\begin{verbatim}
 $entry->update ( $ldap ); # update directory server
\end{verbatim}
\begin{verbatim}
 $entry2 = $entry->clone; # copies entry
\end{verbatim}
\section{DESCRIPTION\label{DESCRIPTION-entry}\index{description of Net::LDAP::Entry}}


The \textbf{Net::LDAP::Entry} object represents a single entry in the
directory.  It is a container for attribute-value pairs.



A \textbf{Net::LDAP::Entry} object can be used in two situations. The first
and probably most common use is in the result of a search to the
directory server.



The other is where a new object is created locally and then a single
command is sent to the directory server to add, modify or replace an
entry. Entries for this purpose can also be created by reading an LDIF
file with the \emph{Net::LDAP::LDIF} module.

\section{CONSTRUCTORS\label{CONSTRUCTORS-entry}\index{constructors for Net::LDAP::Entry}}
\begin{description}
  
\item[new ()]\index{new() --- Net::LDAP::Entry constructor} \mbox{}

Create a new entry object with the changetype set to \texttt{'add'}


\item[clone ()] \index{clone() --- Net::LDAP::Entry copy constructor}\mbox{}

Returns a copy of the \textbf{Net::LDAP::Entry} object.

\end{description}
\section{METHODS\label{METHODS-entry}\index{methods for Net::LDAP::Entry}}
\begin{description}

\item[add ( ATTR =$>$ VALUE, ... )]\index{add() --- Net::LDAP::Entry method} \mbox{}

Add more attributes or values to the entry. Each \texttt{VALUE} should be a
string if only a single value is wanted in the attribute, or a
reference to an array of strings if multiple values are wanted. The
values given will be added to the values which already exist for the
given attributes.

\begin{verbatim}
 $entry->add ( 'sn' => 'Barr' );
\end{verbatim}
\begin{verbatim}
 $entry->add ( 'street' => [ '1 some road','nowhere' ] );
\end{verbatim}


\textbf{NOTE}: these changes are local to the client and will not appear on
the directory server until the \texttt{update} method is called.


\item[attributes ( OPTIONS )]\index{attributes() --- Net::LDAP::Entry method} \mbox{}

Return a list of attributes in this entry

\begin{description}

\item[nooptions =$>$ 1] \mbox{}

Return a list of the attribute names excluding any options. For
example for the entry

\begin{verbatim}
  name: Graham Barr
  name;en-us: Bob
  jpeg;binary: **binary data**
\end{verbatim}


then

\begin{verbatim}
  @values = $entry->attributes;
  print "default: @values\n";
\end{verbatim}
\begin{verbatim}
  @values = $entry->attributes ( nooptions => 1 );
  print "nooptions: @values\n";
\end{verbatim}


will output

\begin{verbatim}
  default: name name;en-us jpeg;binary
  nooptions: name jpeg
\end{verbatim}
\end{description}

\item[changetype ()] \index{changetype() --- Net::LDAP::Entry accessor
    method}\mbox{}

Returns the type of operation that would be performed when the update
method is called.


\item[changetype ( TYPE )]\index{changetype() --- Net::LDAP::Entry mutator
    method} \mbox{}

Set the type of operation that will be performed when the update
method is called to \texttt{TYPE}.



Possible values for \texttt{TYPE} are

\begin{description}

\item[add] \mbox{}

The update method will call the add method on the client object, which
will result in the entry being added to the directory server.


\item[delete] \mbox{}

The update method will call the delete method on the client object,
which will result in the entry being removed from the directory
server.


\item[modify] \mbox{}

The update method will call the modify method on the client object,
which will result in any changes that have been made locally being
made to the entry on the directory server.


\item[moddn/modrdn] \mbox{}

The update method will call the moddn method on the client object,
which will result in any DN changes that have been made locally being
made to the entry on the directory server. These DN changes are
specified by setting the entry attributes newrdn, deleteoldrdn, and
(optionally) newsuperior.

\end{description}

\item[delete ()]\index{delete() --- Net::LDAP::Entry method} \mbox{}

Delete the entry from the server on the next call to \texttt{update}.


\item[delete ( ATTR =$>$ [ VALUE, ... ], ... )] \mbox{}

Delete the values of given attributes from the entry. Values are
references to arrays; passing a reference to an empty array is the
same as passing \texttt{undef}, and will result in the entire attribute
being deleted. For example:

\begin{verbatim}
 $entry->delete ( 'mail' => [ 'foo.bar@example.com' ] );
 $entry->delete ( 'description' => [ ], 'streetAddress' => [ ] );
\end{verbatim}


\textbf{NOTE}: these changes are local to the client and will not appear on
the directory server until the \texttt{update} method is called.


\item[dn ()]\index{dn() --- Net::LDAP::Entry method} \mbox{}

Get the DN of the entry.


\item[dn ( DN )] \index{delete() --- Net::LDAP::Entry method}\mbox{}

Set the DN for the entry, and return the previous value.



\textbf{NOTE}: these changes are local to the client and will not appear on
the directory server until the \texttt{update} method is called.


\item[exists ( ATTR )]\index{exists() --- Net::LDAP::Entry method} \mbox{}

Returns \texttt{TRUE} if the entry has an attribute called \texttt{ATTR}.


\item[get\_value ( ATTR, OPTIONS )]\index{get\_value() --- Net::LDAP::Entry method} \mbox{}

Get the values for the attribute \texttt{ATTR}. In a list context returns
all values for the given attribute, or the empty list if the attribute
does not exist. In a scalar context returns the first value for the
attribute or undef if the attribute does not exist.

\begin{description}

\item[alloptions =$>$ 1] \mbox{}

The result will be a hash reference. The keys of the hash will be the
options and the hash value will be the values for those attributes.
For example if an entry had:

\begin{verbatim}
 name: Graham Barr
 name;en-us: Bob
\end{verbatim}


Then a get for attribute "name" with alloptions set to a true value

\begin{verbatim}
 $ref = $entry->get_value ( 'name', alloptions => 1 );
\end{verbatim}


will return a hash reference that would be like

\begin{verbatim}
 {
   ''       => [ 'Graham Barr' ],
   ';en-us' => [ 'Bob' ]
 }
\end{verbatim}

\item[asref =$>$ 1] \mbox{}

The result will be a reference to an array containing all the values
for the attribute, or \texttt{undef} if the attribute does not exist.

\begin{verbatim}
 $scalar = $entry->get_value ( 'name' );
\end{verbatim}


\$scalar will be the first value for the \texttt{name} attribute, or \texttt{undef}
if the entry does not contain a \texttt{name} attribute.

\begin{verbatim}
 $ref = $entry->get_value ( 'name', asref => 1 );
\end{verbatim}


\$ref will be a reference to an array, which will have all the values
for the \texttt{name} attribute. If the entry does not have an attribute
called \texttt{name} then \$ref will be \texttt{undef}.

\end{description}


\textbf{NOTE}: In the interest of performance the array references returned
by \texttt{get\_value} are references to structures held inside the entry
object. These values and thier contents should \textbf{NOT} be modified
directly.


\item[replace ( ATTR =$>$ VALUE, ... )]\index{replace() --- Net::LDAP::Entry method} \mbox{}

Similar to \texttt{add}, except that the values given will replace any
values that already exist for the given attributes.



\textbf{NOTE}: these changes are local to the client and will not appear on
the directory server until the \texttt{update} method is called.


\item[update ( CLIENT )]\index{update() --- Net::LDAP::Entry method} \mbox{}

Update the directory server with any changes that have been made
locally to the attributes of this entry. This means any calls that
have been made to add, replace or delete since the last call to
changetype or update was made.



This method can also be used to modify the DN of the entry on the
server, by specifying moddn or modrdn as the changetype, and setting
the entry attributes newrdn, deleteoldrdn, and (optionally)
newsuperior.



\texttt{CLIENT} is a \texttt{Net::LDAP} object where the update will be sent to.



The result will be an object of type \emph{Net::LDAP::Message} as returned
by the add, modify or delete method called on CLIENT.

\end{description}
\section{SEE ALSO\label{SEE_ALSO}\index{see also for Net::LDAP::Entry}}


\emph{Net::LDAP},
\emph{Net::LDAP::LDIF}

\section{AUTHOR}\label{AUTHOR-Entry}


Graham Barr $<$gbarr@pobox.com$>$.



Please report any bugs, or post any suggestions, to the perl-ldap
mailing list $<$perl-ldap@perl.org$>$.

\section{COPYRIGHT}\label{COPYRIGHT-Entry}


Copyright (c) 1997-2000 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.



\textit{\$Id: Entry.pod,v 1.12 2003/08/01 19:00:39 chrisridd Exp \$}

