From cf2c250686ddacaf76f3213bad82a0cf5d12db06 Mon Sep 17 00:00:00 2001
From: Nigel Kukard <nkukard@lbsd.net>
Date: Sun, 29 Dec 2013 11:43:10 +0000
Subject: [PATCH] Added function to generate changes between hashes

---
 opentrafficshaper/utils.pm | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/opentrafficshaper/utils.pm b/opentrafficshaper/utils.pm
index 88589fd..0a0b338 100644
--- a/opentrafficshaper/utils.pm
+++ b/opentrafficshaper/utils.pm
@@ -27,6 +27,7 @@ our (@ISA,@EXPORT,@EXPORT_OK);
 @ISA = qw(Exporter);
 @EXPORT = qw(
 	prettyUndef
+	getHashChanges
 	toHex
 	isVariable
 	isUsername
@@ -53,6 +54,27 @@ sub prettyUndef
 }
 
 
+# Function to return the changes between two hashes using a list of keys
+sub getHashChanges
+{
+	my ($orig,$new,$keys) = @_;
+
+
+	my $changed = { };
+
+	foreach my $key (@{$keys}) {
+		# We can only do this if we have a new value
+		if (defined($new->{$key})) {
+			if (!defined($orig->{$key}) || $orig->{$key} ne $new->{$key}) {
+				$changed->{$key} = $new->{$key};
+			}
+		}
+	}
+
+	return $changed;
+}
+
+
 # Return hex representation of a decimal
 sub toHex
 {
-- 
GitLab