mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-25 12:12:34 +01:00
HashObject: improve error messages for removing non-existing items
This commit is contained in:
parent
20695d5f73
commit
fae9e866ee
@ -158,9 +158,12 @@ sub unset {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete $self->{hash}->{$lc_index}->{$key};
|
if (defined delete $self->{hash}->{$lc_index}->{$key}) {
|
||||||
$self->save;
|
$self->save;
|
||||||
return "[$self->{name}] $self->{hash}->{$lc_index}->{_name}: $key unset.";
|
return "[$self->{name}] $self->{hash}->{$lc_index}->{_name}: $key unset.";
|
||||||
|
} else {
|
||||||
|
return "[$self->{name}] $self->{hash}->{$lc_index}->{_name}: $key does not exist.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub exists {
|
sub exists {
|
||||||
@ -208,15 +211,22 @@ sub remove {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (defined $data_index) {
|
if (defined $data_index) {
|
||||||
delete $self->{hash}->{$lc_index}->{$data_index};
|
if (defined delete $self->{hash}->{$lc_index}->{$data_index}) {
|
||||||
delete $self->{hash}->{$lc_index} if keys(%{$self->{hash}->{$lc_index}}) == 1;
|
delete $self->{hash}->{$lc_index} if keys(%{$self->{hash}->{$lc_index}}) == 1;
|
||||||
$self->save unless $dont_save;
|
$self->save unless $dont_save;
|
||||||
return "$self->{hash}->{$lc_index}->{_name}.$data_index removed from $self->{name}";
|
return "$self->{hash}->{$lc_index}->{_name}.$data_index removed from $self->{name}";
|
||||||
|
} else {
|
||||||
|
return "$self->{name}: $self->{hash}->{$lc_index}->{_name}.$data_index does not exist.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $data = delete $self->{hash}->{$lc_index};
|
my $data = delete $self->{hash}->{$lc_index};
|
||||||
|
if (defined $data) {
|
||||||
$self->save unless $dont_save;
|
$self->save unless $dont_save;
|
||||||
return "$data->{_name} removed from $self->{name}.";
|
return "$data->{_name} removed from $self->{name}.";
|
||||||
|
} else {
|
||||||
|
return "$self->{name}: $data_index does not exist.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user