use Hash::Merge to correctly handle update, This might actually move to
[perl-cwmp.git] / lib / CWMP / Store / YAML.pm
index 588060f..160cbe8 100644 (file)
@@ -6,6 +6,7 @@ use warnings;
 
 use Data::Dump qw/dump/;
 use YAML qw/LoadFile DumpFile/;
+use Hash::Merge qw/merge/;
 
 =head1 NAME
 
@@ -44,7 +45,13 @@ sub update_uid_state {
 
        my $file = "$dir/$uid.yml";
 
-       DumpFile( $file, $state ) || die "can't write $file: $!";
+       my $old_state = $self->get_state( $uid );
+
+       my $combined = merge( $state, $old_state );
+
+#      warn "## ",dump( $old_state, $state, $combined );
+
+       DumpFile( $file, $combined ) || die "can't write $file: $!";
 
 }
 
@@ -79,7 +86,7 @@ sub all_uids {
        my @uids = grep { /\.yml$/ && -f "$dir/$_" } readdir($d);
        closedir $d;
 
-       return map { s/\.yml$// } @uids;
+       return map { my $l = $_; $l =~ s/\.yml$//; $l } @uids;
 }
 
 1;