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
37 $debug = $args->{debug};
38 $path = $args->{path} || confess "no path?";
40 warn "open ",dump( $args ) if $debug;
45 mkdir $path || die "can't create $path: $!";
46 warn "created $path directory\n" if $debug;
47 } elsif ( $args->{clean} ) {
48 warn "removed old $path\n" if $debug;
49 foreach my $uid ( $self->all_uids ) {
50 my $file = "$path/$uid.yml";
51 unlink $file || die "can't remove $file: $!";
58 =head2 update_uid_state
60 $store->update_uid_state( $uid, $state );
64 sub update_uid_state {
65 my ( $self, $uid, $state ) = @_;
67 my $file = "$path/$uid.yml";
69 my $old_state = $self->get_state( $uid );
71 my $combined = merge( $state, $old_state );
73 # warn "## ",dump( $old_state, $state, $combined );
75 DumpFile( $file, $combined ) || die "can't write $file: $!";
81 $store->get_state( $uid );
86 my ( $self, $uid ) = @_;
88 my $file = "$path/$uid.yml";
91 return LoadFile( $file );
99 my @uids = $store->all_uids;
106 opendir(my $d, $path) || die "can't opendir $path: $!";
107 my @uids = grep { /\.yml$/ && -f "$path/$_" } readdir($d);
110 return map { my $l = $_; $l =~ s/\.yml$//; $l } @uids;