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
40 $debug = $args->{debug};
41 $path = $args->{path} || confess "no path?";
43 warn "open ",dump( $args ) if $debug;
45 $path = $self->full_path( $path );
48 mkdir $path || die "can't create $path: $!";
49 warn "created $path directory\n" if $debug;
50 } elsif ( $args->{clean} ) {
51 warn "removed old $path\n" if $debug;
52 foreach my $uid ( $self->all_uids ) {
53 my $file = $self->file( $uid );
54 unlink $file || die "can't remove $file: $!";
61 =head2 update_uid_state
63 my $new_state = $store->update_uid_state( $uid, $state );
67 sub update_uid_state {
68 my ( $self, $uid, $state ) = @_;
70 my $file = $self->file( $uid );
72 my $old_state = $self->get_state( $uid );
74 my $combined = merge( $state, $old_state );
76 # warn "## ",dump( $old_state, $state, $combined );
78 $self->save_hash( $file, $combined ) || die "can't write $file: $!";
85 $store->get_state( $uid );
90 my ( $self, $uid ) = @_;
92 my $file = $self->file( $uid );
95 return $self->load_hash( $file );
103 my @uids = $store->all_uids;
110 my $ext = $self->extension;
111 warn "## extension: $ext";
113 opendir(my $d, $path) || die "can't opendir $path: $!";
114 my @uids = grep { $_ =~ m/\Q$ext\E$/ && -f "$path/$_" } readdir($d);
117 return map { my $l = $_; $l =~ s/\Q$ext\E$//; $l } @uids;