3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 10:59:29 +01:00

DualIndexHashObject: get_keys: ensure index actually exists

This commit is contained in:
Pragmatic Software 2020-03-04 13:25:41 -08:00
parent 6c4f56f9df
commit c467f92904

View File

@ -6,6 +6,9 @@
# extends the HashObject with an additional index key. Provides case-insensitive # extends the HashObject with an additional index key. Provides case-insensitive
# access to both index keys, while preserving original case when displaying the # access to both index keys, while preserving original case when displaying the
# keys. # keys.
#
# Data is stored in working memory for lightning fast performance. If you have
# a huge amount of data, consider DualIndexSQLiteObject instead.
# This Source Code Form is subject to the terms of the Mozilla Public # This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
@ -272,10 +275,18 @@ sub get_keys {
my ($self, $primary_index, $secondary_index) = @_; my ($self, $primary_index, $secondary_index) = @_;
return keys %{$self->{hash}} if not defined $primary_index; return keys %{$self->{hash}} if not defined $primary_index;
my $lc_primary_index = lc $primary_index;
if (not defined $secondary_index) { if (not defined $secondary_index) {
return grep { $_ ne '_name' } keys %{$self->{hash}->{lc $primary_index}}; return () if not exists $self->{hash}->{$lc_primary_index};
return grep { $_ ne '_name' } keys %{$self->{hash}->{$lc_primary_index}};
} }
my $lc_secondary_index = lc $secondary_index;
return () if not exists $self->{hash}->{$lc_primary_index}
or not exists $self->{hash}->{$lc_primary_index}->{$lc_secondary_index};
return grep { $_ ne '_name' } keys %{$self->{hash}->{lc $primary_index}->{lc $secondary_index}}; return grep { $_ ne '_name' } keys %{$self->{hash}->{lc $primary_index}->{lc $secondary_index}};
} }
@ -363,7 +374,12 @@ sub remove {
else { return "$self->{name}: [$name1] $name2.$data_index does not exist."; } else { return "$self->{name}: [$name1] $name2.$data_index does not exist."; }
} }
# for compatibility with SQLite object # for compatibility with DualIndexSQLiteObject
sub create_metadata { } sub create_metadata { }
# todo:
sub get_each { }
sub get_next { }
sub get_all { }
1; 1;