The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Net::LDAP::Batch - perform a batch of LDAP actions


 use Net::LDAP::Batch;
 my $BaseDN = 'ou=People,dc=MyDomain';
 my $ldap   = make_and_bind_Net_LDAP_object();  # you write this
 my $batch = Net::LDAP::Batch->new( ldap => $ldap );
    add => [
            dn      => "cn=MyGroup,ou=Group,$BaseDN",
            attr    => [
                objectClass => [ 'top', 'posixGroup' ],
                cn          => 'MyGroup',
                gidNumber   => '1234'
    delete => [
            search  => [
                base    => "ou=Group,$BaseDN",
                scope   => 'sub',
                filter  => "(cn=MyOldGroup)"
    update => [
            search  => [
                base    => "ou=Group,$BaseDN",
                scope   => 'sub',
                filter  => "(cn=OtherGroup)"
            replace => { gidNumber => '5678' },
            delete  => { foo => [ 'bar' ] },

 $batch->do or die $batch->error;


Net::LDAP::Batch performs a series of actions against a LDAP server. If any of the actions fails, then all the actions in the batch are reverted.

Be advised: This is not a true ACID-compliant transaction feature, since no locking is performed. Instead it is simply a way to execute a series of actions without having to worry about checking return values, or error codes, or un-doing the changes should any of them fail. Of course, since no ACID compliance is claimed, anything could (and likely will) happen if there is more than one client attempting to make changes on the same server at the same time. You have been warned.



Create a batch instance.

You must pass in a valid Net::LDAP object that has already been bound to the server with whatever credentials are necessary to complete the actions you will specify.

You may optionally pass in an array ref of actions. See also the add_actions() method.


Get the array ref of Net::LDAP::Batch::Action objects in the batch. To set the array, use add_actions().

add_actions( actions )

Set the array of actions to be executed. actions may be either an array or array ref, and may either be key/value pairs as in the SYNOPSIS or Net::LDAP::Batch::Action objects. You may not mix the two types of values.

Returns the total number of actions in batch.


Sets the number of actions to zero. Returns the former contents of actions().


Perform the actions and rollback() if any are fatal. Same thing as calling:

 eval { $batch->execute };
 if ($@) {
     warn "batch failed: $@";
     $batch->rollback;  # could be fatal

The code above is nearly verbatim what do() actually does.


Calls execute() method on each action.


Calls rollback() method on each action.


Peter Karman, <karman at>


Please report any bugs or feature requests to bug-net-ldap-batch at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Net::LDAP::Batch

You can also look for information at:


The Minnesota Supercomputing Institute sponsored the development of this software.


Copyright 2008 by the Regents of the University of Minnesota. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.