Bug 313787
Make the Entry getValues method return the first value in a scalar context
This makes it easier to get a single value. It is often the case that there is
only a single value, and some attributes are single valued. This avoids having
to use the idiom
$foo = ($entry->getValues('attr'))[0];
to dereference the array. The size('attr') method can be used to get the
number of values.
Just use the wantarray function to see if this is a scalar or an array context.
Return the first value in a scalar context.
The POD has been updated as well.
git-svn-id: svn://10.0.0.236/branches/devel-branch-1_4_2@182993 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#############################################################################
|
||||
# $Id: Entry.pm,v 1.13.2.6 2005-01-05 03:08:12 leif%ogre.com Exp $
|
||||
# $Id: Entry.pm,v 1.13.2.7 2005-10-25 19:27:54 richm%stanfordalumni.org Exp $
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License
|
||||
# Version 1.1 (the "License"); you may not use this file except in
|
||||
@@ -713,6 +713,7 @@ sub setValues
|
||||
#############################################################################
|
||||
# Get the entire array of attribute values. This returns the array, not
|
||||
# the pointer to the array...
|
||||
# in a scalar context, returns the first attribute
|
||||
#
|
||||
sub getValues
|
||||
{
|
||||
@@ -722,7 +723,7 @@ sub getValues
|
||||
return unless (defined($attr) && ($attr ne ""));
|
||||
return unless defined($self->{$attr});
|
||||
|
||||
return @{$self->{$attr}};
|
||||
return (wantarray ? @{$self->{$attr}} : $self->{$attr}->[0]);
|
||||
}
|
||||
*getValue = \*getValues;
|
||||
|
||||
@@ -1179,9 +1180,14 @@ indicates we should normalize the DN before returning it to the caller.
|
||||
=item B<getValues>
|
||||
|
||||
Returns an entire array of values for the attribute specified. Note that
|
||||
this returns an array, and not a pointer to an array.
|
||||
this returns an array, and not a pointer to an array. In a scalar
|
||||
context, this returns the first value. This is different - this method
|
||||
used to always return an array, which meant the array size in a scalar
|
||||
context. If you need to get the array size, use the B<size> method
|
||||
described below.
|
||||
|
||||
@someArray = $entry->getValues("description");
|
||||
$scalval = $entry->getValues("cn");
|
||||
|
||||
=item B<hasValue>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user