summaryrefslogtreecommitdiff
path: root/lib/VNDB/Func.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r--lib/VNDB/Func.pm18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 02489980..b4848796 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -13,6 +13,7 @@ our @EXPORT = (@VNDBUtil::EXPORT, qw|
childtags charspoil imgpath imgurl fmtvote
json_encode json_decode script_json
mtvoiced mtani mtvnlen mtrlstat mtvnlstat mtbloodt
+ form_compare
|);
@@ -237,5 +238,22 @@ sub mtrlstat { !$_[0] ? mt '_unknown' : mt '_rlist_status_'.$_[0]; }
sub mtvnlstat{ !$_[0] ? mt '_unknown' : mt '_vnlist_status_'.$_[0]; }
sub mtbloodt { $_[0] eq 'unknown' ? mt '_unknown' : mt '_bloodt_'.$_[0]; }
+
+# Compare the keys in %$old with the keys in %$new. Returns 1 if a difference was found, 0 otherwise.
+sub form_compare {
+ my($old, $new) = @_;
+ for my $k (keys %$old) {
+ my($o, $n) = ($old->{$k}, $new->{$k});
+ return 1 if !defined $n || ref $o ne ref $n;
+ if(!ref $o) {
+ return 1 if $o ne $n;
+ } else { # 'json' template
+ return 1 if @$o != @$n;
+ return 1 if grep form_compare($o->[$_], $n->[$_]), 0..$#$o;
+ }
+ }
+ return 0;
+}
+
1;