From: Graham B. <gb...@po...> - 2002-04-25 08:46:13
|
On Wed, Apr 24, 2002 at 06:45:31PM +0200, Norbert Klasen wrote: > Hi Graham, > I put the #xxxx issue in a separate mail. > > >> --- Util.pm-0.25_01 Tue Apr 23 20:35:04 2002 > >> +++ Util.pm Tue Apr 23 21:16:17 2002 > >> @@ -231,8 +231,8 @@ > > > >> sub canonical_dn($%) { > >> - my $dn = shift or return ''; > >> + my $dn = shift; > >> + return $dn unless $dn; # empty DN or undef > > > > $dn = "0" ? > > This is another case to consider. > > > This should be return $dn unless $dn and length $dn; > > return $dn if $dn eq '' || !defined $dn ; # empty DN or undef > > This handles undef, '' and "0" (leads to an error later). Yes, mine needs a defined added, which will make it -w clean too. > > Does it really make sense for ldap_explode_dn todo the reverse ? > > I added a reverse option to ldap_explode_dn and though it would be a good > idea to use it from canonical_dn as well. Am I missing something? I am just not sure what the benefit of having reverse in ldap_explode_dn is ? It was only ever in canonical_dn to make sorting DNs easier. It anywan want the output of explode in reverse, then they can call reverse. > >> sub ldap_explode_dn($%) { > >> - my $dn = shift or return; > >> + my @emptydn = (); #empty DN array for scalar context > >> + my $dn = shift; > >> + return wantarray ? [] : \@emptydn if $dn eq ''; > > > > This does not make sense. You are returning a scalar ref > > when wantarray is true. Did you mean > > > > return wantarray ? () : [] if $dn eq ''; > > I'm not that familar with these elements of Perl so it tell you what a I > actually had in mind: The return value of ldap_explode_dn should give the > user an indication, whether an invalid DN was passed in. The problem is now > that the (valid) empty DN '' explodes to an empty array. In the scalar > context one can return undef or a reference to an empty array but I don't > know to express this in list context. Yup this is a common problem with context sensetive subs. If the user cares about it they need to call it in a scalar context. > >> my %opt = @_; > >> > >> my (@dn, %rdn); > >> + $dn =~ s/^<(.*)>$/$1/; #remove brackets > > > > why ? where is it defined that DNs have <> brackets ? > > There is a test case <UID=jsmith,O=example,C=US> in the ldapbis document. I > don't know where such could be defined. Kurt? OK, fine. Graham. |