1 package CWMP::Store::HASH;
11 use Data::Dump qw/dump/;
12 use Hash::Merge qw/merge/;
17 CWMP::Store::HASH - base class for hash based storage engines
42 $debug = $args->{debug};
43 $path = $args->{path} || confess "no path?";
45 warn "open ",dump( $args ) if $debug;
47 $path = $self->full_path( $path );
50 mkdir $path || die "can't create $path: $!";
51 warn "created $path directory\n" if $debug;
52 } elsif ( $args->{clean} && ! $cleaned ) {
53 warn "removed old $path\n" if $debug;
54 foreach my $uid ( $self->all_uids ) {
55 my $file = $self->file( $uid );
56 unlink $file || die "can't remove $file: $!";
64 =head2 update_uid_state
66 my $new_state = $store->update_uid_state( $uid, $state );
70 sub update_uid_state {
71 my ( $self, $uid, $state ) = @_;
73 my $file = $self->file( $uid );
75 my $old_state = $self->get_state( $uid );
77 my $combined = merge( $state, $old_state );
79 # warn "## ",dump( $old_state, $state, $combined );
81 $self->save_hash( $file, $combined ) || die "can't write $file: $!";
88 $store->get_state( $uid );
93 my ( $self, $uid ) = @_;
95 my $file = $self->file( $uid );
98 return $self->load_hash( $file );
107 $store->set_state( $uid, $state );
112 my ( $self, $uid, $state ) = @_;
113 my $file = $self->file( $uid );
114 return $self->save_hash( $file, $state );
120 my @uids = $store->all_uids;
127 my $ext = $self->extension;
128 #warn "## extension: $ext";
130 opendir(my $d, $path) || die "can't opendir $path: $!";
131 my @uids = grep { $_ =~ m/\Q$ext\E$/ && -f "$path/$_" } readdir($d);
134 return map { my $l = $_; $l =~ s/\Q$ext\E$//; $l } @uids;