From e5bd377477a7e2e5483366f872949469640a83f5 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sat, 5 Aug 2017 20:14:49 -0700 Subject: [PATCH] Add ability to clear HashObject; rename load/save --- PBot/Channels.pm | 4 ++-- PBot/HashObject.pm | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/PBot/Channels.pm b/PBot/Channels.pm index 41a89079..058a2425 100644 --- a/PBot/Channels.pm +++ b/PBot/Channels.pm @@ -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 { diff --git a/PBot/HashObject.pm b/PBot/HashObject.pm index f8b4b8eb..5cd53fb3 100644 --- a/PBot/HashObject.pm +++ b/PBot/HashObject.pm @@ -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}."; }