1 package CWMP::Store::HASH;
6 use Data::Dump qw/dump/;
7 use Hash::Merge qw/merge/;
12 CWMP::Store::HASH - base class for hash based storage engines
35 $debug = $args->{debug};
36 $path = $args->{path} || confess "no path?";
38 warn "open ",dump( $args ) if $debug;
40 $path = $self->full_path( $path );
43 mkdir $path || die "can't create $path: $!";
44 warn "created $path directory\n" if $debug;
45 } elsif ( $args->{clean} ) {
46 warn "removed old $path\n" if $debug;
47 foreach my $uid ( $self->all_uids ) {
48 my $file = $self->file( $uid );
49 unlink $file || die "can't remove $file: $!";
56 =head2 update_uid_state
58 $store->update_uid_state( $uid, $state );
62 sub update_uid_state {
63 my ( $self, $uid, $state ) = @_;
65 my $file = $self->file( $uid );
67 my $old_state = $self->get_state( $uid );
69 my $combined = merge( $state, $old_state );
71 # warn "## ",dump( $old_state, $state, $combined );
73 $self->save_hash( $file, $combined ) || die "can't write $file: $!";
79 $store->get_state( $uid );
84 my ( $self, $uid ) = @_;
86 my $file = $self->file( $uid );
89 return $self->load_hash( $file );
97 my @uids = $store->all_uids;
104 my $ext = $self->extension;
105 warn "## extension: $ext";
107 opendir(my $d, $path) || die "can't opendir $path: $!";
108 my @uids = grep { $_ =~ m/\Q$ext\E$/ && -f "$path/$_" } readdir($d);
111 return map { my $l = $_; $l =~ s/\Q$ext\E$//; $l } @uids;