Example: Working with locks (Perl)

# This example demonstrates locking an element, but 
# locking other CCVOBObjects works in a similar way.
# This example also demonstrates using variant arrays from Perl.

use Win32::OLE;
use Win32::OLE::Variant;

# Connect to the top-level ClearCase application object 
$cc = Win32::OLE->new('ClearCase.Application') or die "Could not create Application object\n";

# Get a CCElement object from the top-level application object 
my $elem = $cc->Element("m:\\carol_main\\caroltest\\testelem.c");

# Create an array of users ("jo" and "caroly") to exempt from the lock
my $exemptusers = Variant(VT_ARRAY|VT_BSTR, 2);
$exemptusers->Put(["jo", "caroly"]);

# Create a lock on the element, but do not make the element obsolete. 
$elem->CreateLock("locking from example script", false, $exemptusers);

# Print some information about the lock 
# Note: the example does no error checking, but you should check for errors! 
my $elemlock = $elem->Lock;
my $record = $elemlock->CreationRecord;

# Get the list of exempt users 
my $users = $elemlock->ExemptUsersStringArray;
my $strusers = "";
$first = 1;
for (@$users) {
if ($first == 0) {
$strusers = $strusers . ", " . $_;
} else {
$strusers = $_;
$first = 0;
}
}

# Print out other lock information 
print("Lock created by ", $record->UserLoginName, " at ", $record->Date,
" and has ", $elemlock->NumberOfExemptUsers, " exempt users: ",
$strusers);

# Now change the list of exempt users, using a declared array  
my @names = ("bill", "eric", "caroly");
my $arr = Variant(VT_ARRAY|VT_BSTR, 3);
$arr->Put([$names]);
$elemlock->SetExemptUsersStringArray($arr);

# Unlock it 
$elemlock->Remove;

Feedback