Can anybody tell me what is wrong with the code below? I can't figure
out. It is supposed to delete all leaf entries found in a subtree.

Line 43 is the first line of the topmost for loop:
    my $entry = $msg->entry( $i );
-- 
        Claude

#############################################################################
$ ./test_ng0.pl
Can't locate object method "entry" via package "Net::LDAP::Delete" at
        ./test_ng0.pl line 43, <DATA> chunk 283 (#1)
    
    (F) You called a method correctly, and it correctly indicated a package
    functioning as a class, but that package doesn't define that particular
    method, nor does any of its base classes.  See perlobj.
    
Uncaught exception from user code:
        Can't locate object method "entry" via package "Net::LDAP::Delete" at 
./test_ng0.pl line 43, <DATA> chunk 283.
        main::wipeLeaves('Net::LDAP=HASH(0x403df6a8)') called at ./test_ng0.pl line 25
#############################################################################

use diagnostics;
use strict;
use Net::LDAP;

# removed variable assignments

my $ldap = Net::LDAP->new( $LDAPhost, async => 0 )
  or die "- Cannot create LDAP object: $@";
my $msg = $ldap->bind( $usr, password => $pwd );

$msg->code && die " - Cannot bind $usr to $LDAPhost: ", $msg->error  ;
wipeLeaves( $ldap );
$msg = $ldap->unbind;

sub wipeLeaves( $ ) {
  my $ldap = shift @_;
  my $msg = $ldap->search( base   => $base,
                           scope  => 'sub',
                           filter => '(objectClass=*)',
                           attrs  => [ 'hasSubordinates' ],
                         );
  my $max = $msg->count;

  for ( my $i = 0 ; $i < $max ; $i++ ) {
    my $entry = $msg->entry( $i );
    foreach my $attr ( $entry->attributes ) {
      my $val = $entry->get_value( $attr );
      if ( ( $attr eq 'hasSubordinates' ) && ( $val =~ /false/i ) ) {
        # it is a leaf, remove it
        $entry->changetype( 'delete' );
        $entry->delete();
        $msg = $entry->update( $ldap );
        $msg->code && die "- Cannot delete entry: ", $msg->error, "\n";
      }
    }
  }
}

Reply via email to