1 # Dobrica Pavlinusic, <dpavlin@rot13.org> 10/26/07 21:37:12 CEST
2 package CWMP::Store::YAML;
7 use Data::Dump qw/dump/;
8 use YAML qw/LoadFile DumpFile/;
9 use Hash::Merge qw/merge/;
14 CWMP::Store::YAML - use YAML as storage
31 $debug = $args->{debug};
32 $path = $args->{path} || confess "no path?";
34 warn "open ",dump( $args ) if $debug;
39 mkdir $path || die "can't create $path: $!";
40 warn "created $path directory\n";
45 =head2 update_uid_state
47 $store->update_uid_state( $uid, $state );
51 sub update_uid_state {
52 my ( $self, $uid, $state ) = @_;
54 my $file = "$path/$uid.yml";
56 my $old_state = $self->get_state( $uid );
58 my $combined = merge( $state, $old_state );
60 # warn "## ",dump( $old_state, $state, $combined );
62 DumpFile( $file, $combined ) || die "can't write $file: $!";
68 $store->get_state( $uid );
73 my ( $self, $uid ) = @_;
75 my $file = "$path/$uid.yml";
78 return LoadFile( $file );
86 my @uids = $store->all_uids;
93 opendir(my $d, $path) || die "can't opendir $path: $!";
94 my @uids = grep { /\.yml$/ && -f "$path/$_" } readdir($d);
97 return map { my $l = $_; $l =~ s/\.yml$//; $l } @uids;