mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-24 11:42:35 +01:00
Add ability to clear HashObject; rename load/save
This commit is contained in:
parent
aa65839827
commit
e5bd377477
@ -120,13 +120,13 @@ sub is_active_op {
|
||||
sub load_channels {
|
||||
my $self = shift;
|
||||
|
||||
$self->{channels}->load_hash();
|
||||
$self->{channels}->load();
|
||||
}
|
||||
|
||||
sub save_channels {
|
||||
my $self = shift;
|
||||
|
||||
$self->{channels}->save_hash();
|
||||
$self->{channels}->save();
|
||||
}
|
||||
|
||||
sub channels {
|
||||
|
@ -57,7 +57,7 @@ sub load_hash_add {
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub load_hash {
|
||||
sub load {
|
||||
my $self = shift;
|
||||
my $filename;
|
||||
|
||||
@ -118,7 +118,7 @@ sub load_hash {
|
||||
$self->{pbot}->{logger}->log("Done.\n");
|
||||
}
|
||||
|
||||
sub save_hash {
|
||||
sub save {
|
||||
my $self = shift;
|
||||
my $filename;
|
||||
|
||||
@ -142,6 +142,11 @@ sub save_hash {
|
||||
close(FILE);
|
||||
}
|
||||
|
||||
sub clear {
|
||||
my $self = shift;
|
||||
$self->{hash} = {};
|
||||
}
|
||||
|
||||
sub find_hash {
|
||||
my ($self, $keyword, $arguments) = @_;
|
||||
|
||||
@ -216,7 +221,7 @@ sub set {
|
||||
$value = $self->hash->{$hash_index}{$key};
|
||||
} else {
|
||||
$self->hash->{$hash_index}{$key} = $value;
|
||||
$self->save_hash();
|
||||
$self->save();
|
||||
}
|
||||
|
||||
return "[$self->{name}] $hash_index: '$key' " . (defined $value ? "set to '$value'" : "is not set.");
|
||||
@ -234,7 +239,7 @@ sub unset {
|
||||
}
|
||||
|
||||
delete $self->hash->{$hash_index}{$key};
|
||||
$self->save_hash();
|
||||
$self->save();
|
||||
|
||||
return "[$self->{name}] $hash_index: '$key' unset.";
|
||||
}
|
||||
@ -243,7 +248,7 @@ sub add {
|
||||
my ($self, $index_key, $hash) = @_;
|
||||
|
||||
if($self->load_hash_add($index_key, $hash, 0)) {
|
||||
$self->save_hash();
|
||||
$self->save_();
|
||||
} else {
|
||||
return "Error occurred adding new $self->{name} object.";
|
||||
}
|
||||
@ -263,7 +268,7 @@ sub remove {
|
||||
}
|
||||
|
||||
delete $self->hash->{$hash_index};
|
||||
$self->save_hash();
|
||||
$self->save();
|
||||
|
||||
return "'$hash_index' removed from $self->{name}.";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user