r257@brr: dpavlin | 2007-11-24 03:16:39 +0100
[perl-cwmp.git] / lib / CWMP / Store / YAML.pm
index 8c88573..6b5ea15 100644 (file)
@@ -5,7 +5,7 @@ use strict;
 use warnings;
 
 use Data::Dump qw/dump/;
-use YAML qw/LoadFile DumpFile/;
+use YAML::Syck;
 use Hash::Merge qw/merge/;
 use Carp qw/confess/;
 
@@ -17,11 +17,17 @@ CWMP::Store::YAML - use YAML as storage
 
 =head2 open
 
+  $store->open({
+       path => 'var/',
+       debug => 1,
+       clean => 1,
+  });
+
 =cut
 
 my $path;
 
-my $debug = 1;
+my $debug = 0;
 
 sub open {
        my $self = shift;
@@ -37,9 +43,16 @@ sub open {
 
        if ( ! -e $path ) {
                mkdir $path || die "can't create $path: $!";
-               warn "created $path directory\n";
+               warn "created $path directory\n" if $debug;
+       } elsif ( $args->{clean} ) {
+               warn "removed old $path\n" if $debug;
+               foreach my $uid ( $self->all_uids ) {
+                       my $file = "$path/$uid.yml";
+                       unlink $file || die "can't remove $file: $!";
+               }
        }
 
+
 }
 
 =head2 update_uid_state