Subject: | Enhancement for Net::LDAP::Search |
Date: | Mon, 19 Aug 2013 16:29:41 +0200 |
To: | bug-perl-ldap [...] rt.cpan.org |
From: | Stefan <bugs [...] innuce.ch> |
Hi there
I modified sorted() so you can sort ascending and descending. Maybe
you can merge it into trunk (i should not break the original function):
you can activate descending sorts over
$result->sortorder(1);
--snip--
sub sortorder {
my $self = shift;
my $order = shift;
if ($order == 1){
$self->{sortorder}=1;
} else {
$self->{sortorder}=0;
}
}
sub sorted {
my $self = shift;
$self->sync unless exists $self->{resultCode};
$self->{sortorder} = 0 if (!$self->{sortorder};
return unless exists $self->{entries} && ref($self->{entries});
return @{$self->{entries}} unless @{$self->{entries}} > 1;
require Net::LDAP::Util;
if ($self->{sortorder} == 0){
map { $_->[0] } sort {
my $v;
my $i = 2;
foreach my $attr (@_) {
$v = ($a->[$i] ||= join("\000", @{$a->[0]->get_value($attr, asref
=> 1) || []}))
cmp
($b->[$i] ||= join("\000", @{$b->[0]->get_value($attr, asref
=> 1) || []}))
and last;
$i++;
}
$v ||= ($a->[1] ||= Net::LDAP::Util::canonical_dn( $a->[0]->dn,
"reverse" => 1, separator => "\0"))
cmp
($b->[1] ||= Net::LDAP::Util::canonical_dn( $b->[0]->dn,
"reverse" => 1, separator => "\0"));
}
map { [ $_ ] } @{$self->{entries}};
} else {
map { $_->[0] } sort {
my $v;
my $i = 2;
foreach my $attr (@_) {
$v = ($b->[$i] ||= join("\000", @{$b->[0]->get_value($attr, asref
=> 1) || []}))
cmp
($a->[$i] ||= join("\000", @{$a->[0]->get_value($attr, asref
=> 1) || []}))
and last;
$i++;
}
$v ||= ($a->[1] ||= Net::LDAP::Util::canonical_dn( $a->[0]->dn,
"reverse" => 1, separator => "\0"))
cmp
($b->[1] ||= Net::LDAP::Util::canonical_dn( $b->[0]->dn,
"reverse" => 1, separator => "\0"));
}
map { [ $_ ] } @{$self->{entries}};
}
}
-- snip
Cheers
Stefan