r140@llin (orig r139): dpavlin | 2007-10-27 12:13:01 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 27 Oct 2007 22:54:28 +0000 (22:54 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 27 Oct 2007 22:54:28 +0000 (22:54 +0000)
 all low-level store plugins now take path as argument

git-svn-id: https://perl-cwmp.googlecode.com/svn/trunk@155 836a5e1a-633d-0410-964b-294494ad4392

lib/CWMP/Store/DBMDeep.pm
lib/CWMP/Store/YAML.pm
t/05-store.t

index 0c3c6d3..985a124 100644 (file)
@@ -6,6 +6,7 @@ use warnings;
 
 use DBM::Deep;
 use Data::Dump qw/dump/;
+use Carp qw/confess/;
 
 =head1 NAME
 
@@ -24,15 +25,20 @@ my $debug = 1;
 sub open {
        my $self = shift;
 
-       warn "open ",dump( @_ );
+       my $args = shift;
 
-       my $path = 'state.db';
+       $debug = $args->{debug};
+       my $path = $args->{path} || confess "no path?";
+
+       warn "open ",dump( $args ) if $debug;
+
+       $path = "$path/state.db" if ( -d $args->{path} );
 
        $db = DBM::Deep->new(
                file => $path,
                locking => 1,
                autoflush => 1,
-       );
+       ) || confess "can't open $path: $!";
 
 }
 
index 160cbe8..8c88573 100644 (file)
@@ -7,6 +7,7 @@ use warnings;
 use Data::Dump qw/dump/;
 use YAML qw/LoadFile DumpFile/;
 use Hash::Merge qw/merge/;
+use Carp qw/confess/;
 
 =head1 NAME
 
@@ -18,18 +19,25 @@ CWMP::Store::YAML - use YAML as storage
 
 =cut
 
-my $dir = 'yaml';
+my $path;
 
 my $debug = 1;
 
 sub open {
        my $self = shift;
 
-       warn "open ",dump( @_ );
+       my $args = shift;
 
-       if ( ! -e $dir ) {
-               mkdir $dir || die "can't create $dir: $!";
-               warn "created $dir directory\n";
+       $debug = $args->{debug};
+       $path = $args->{path} || confess "no path?";
+
+       warn "open ",dump( $args ) if $debug;
+
+       $path = "$path/yaml";
+
+       if ( ! -e $path ) {
+               mkdir $path || die "can't create $path: $!";
+               warn "created $path directory\n";
        }
 
 }
@@ -43,7 +51,7 @@ sub open {
 sub update_uid_state {
        my ( $self, $uid, $state ) = @_;
 
-       my $file = "$dir/$uid.yml";
+       my $file = "$path/$uid.yml";
 
        my $old_state = $self->get_state( $uid );
 
@@ -64,7 +72,7 @@ sub update_uid_state {
 sub get_state {
        my ( $self, $uid ) = @_;
 
-       my $file = "$dir/$uid.yml";
+       my $file = "$path/$uid.yml";
 
        if ( -e $file ) {
                return LoadFile( $file );
@@ -82,8 +90,8 @@ sub get_state {
 sub all_uids {
        my $self = shift;
 
-       opendir(my $d, $dir) || die "can't opendir $dir: $!";
-       my @uids = grep { /\.yml$/ && -f "$dir/$_" } readdir($d);
+       opendir(my $d, $path) || die "can't opendir $path: $!";
+       my @uids = grep { /\.yml$/ && -f "$path/$_" } readdir($d);
        closedir $d;
 
        return map { my $l = $_; $l =~ s/\.yml$//; $l } @uids;
index e458d42..fb42380 100755 (executable)
@@ -17,7 +17,7 @@ BEGIN {
 ok(my $abs_path = abs_path($0), "abs_path");
 $abs_path =~ s!/[^/]*$!/!;     #!fix-vim
 
-my $path = "$abs_path/var/state.db";
+my $path = "$abs_path/var/";
 
 unlink $path if -e $path;