mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-11 20:42:38 +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 {
|
sub load_channels {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
$self->{channels}->load_hash();
|
$self->{channels}->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub save_channels {
|
sub save_channels {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
$self->{channels}->save_hash();
|
$self->{channels}->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub channels {
|
sub channels {
|
||||||
|
@ -57,7 +57,7 @@ sub load_hash_add {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub load_hash {
|
sub load {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $filename;
|
my $filename;
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ sub load_hash {
|
|||||||
$self->{pbot}->{logger}->log("Done.\n");
|
$self->{pbot}->{logger}->log("Done.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sub save_hash {
|
sub save {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $filename;
|
my $filename;
|
||||||
|
|
||||||
@ -142,6 +142,11 @@ sub save_hash {
|
|||||||
close(FILE);
|
close(FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub clear {
|
||||||
|
my $self = shift;
|
||||||
|
$self->{hash} = {};
|
||||||
|
}
|
||||||
|
|
||||||
sub find_hash {
|
sub find_hash {
|
||||||
my ($self, $keyword, $arguments) = @_;
|
my ($self, $keyword, $arguments) = @_;
|
||||||
|
|
||||||
@ -216,7 +221,7 @@ sub set {
|
|||||||
$value = $self->hash->{$hash_index}{$key};
|
$value = $self->hash->{$hash_index}{$key};
|
||||||
} else {
|
} else {
|
||||||
$self->hash->{$hash_index}{$key} = $value;
|
$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.");
|
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};
|
delete $self->hash->{$hash_index}{$key};
|
||||||
$self->save_hash();
|
$self->save();
|
||||||
|
|
||||||
return "[$self->{name}] $hash_index: '$key' unset.";
|
return "[$self->{name}] $hash_index: '$key' unset.";
|
||||||
}
|
}
|
||||||
@ -243,7 +248,7 @@ sub add {
|
|||||||
my ($self, $index_key, $hash) = @_;
|
my ($self, $index_key, $hash) = @_;
|
||||||
|
|
||||||
if($self->load_hash_add($index_key, $hash, 0)) {
|
if($self->load_hash_add($index_key, $hash, 0)) {
|
||||||
$self->save_hash();
|
$self->save_();
|
||||||
} else {
|
} else {
|
||||||
return "Error occurred adding new $self->{name} object.";
|
return "Error occurred adding new $self->{name} object.";
|
||||||
}
|
}
|
||||||
@ -263,7 +268,7 @@ sub remove {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete $self->hash->{$hash_index};
|
delete $self->hash->{$hash_index};
|
||||||
$self->save_hash();
|
$self->save();
|
||||||
|
|
||||||
return "'$hash_index' removed from $self->{name}.";
|
return "'$hash_index' removed from $self->{name}.";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user