/[cwmp]/google/branches/store-pluggable/lib/CWMP/Store/YAML.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /google/branches/store-pluggable/lib/CWMP/Store/YAML.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 139 by dpavlin, Fri Oct 26 21:41:42 2007 UTC revision 140 by dpavlin, Sat Oct 27 10:13:01 2007 UTC
# Line 7  use warnings; Line 7  use warnings;
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
8  use YAML qw/LoadFile DumpFile/;  use YAML qw/LoadFile DumpFile/;
9  use Hash::Merge qw/merge/;  use Hash::Merge qw/merge/;
10    use Carp qw/confess/;
11    
12  =head1 NAME  =head1 NAME
13    
# Line 18  CWMP::Store::YAML - use YAML as storage Line 19  CWMP::Store::YAML - use YAML as storage
19    
20  =cut  =cut
21    
22  my $dir = 'yaml';  my $path;
23    
24  my $debug = 1;  my $debug = 1;
25    
26  sub open {  sub open {
27          my $self = shift;          my $self = shift;
28    
29          warn "open ",dump( @_ );          my $args = shift;
30    
31          if ( ! -e $dir ) {          $debug = $args->{debug};
32                  mkdir $dir || die "can't create $dir: $!";          $path = $args->{path} || confess "no path?";
33                  warn "created $dir directory\n";  
34            warn "open ",dump( $args ) if $debug;
35    
36            $path = "$path/yaml";
37    
38            if ( ! -e $path ) {
39                    mkdir $path || die "can't create $path: $!";
40                    warn "created $path directory\n";
41          }          }
42    
43  }  }
# Line 43  sub open { Line 51  sub open {
51  sub update_uid_state {  sub update_uid_state {
52          my ( $self, $uid, $state ) = @_;          my ( $self, $uid, $state ) = @_;
53    
54          my $file = "$dir/$uid.yml";          my $file = "$path/$uid.yml";
55    
56          my $old_state = $self->get_state( $uid );          my $old_state = $self->get_state( $uid );
57    
# Line 64  sub update_uid_state { Line 72  sub update_uid_state {
72  sub get_state {  sub get_state {
73          my ( $self, $uid ) = @_;          my ( $self, $uid ) = @_;
74    
75          my $file = "$dir/$uid.yml";          my $file = "$path/$uid.yml";
76    
77          if ( -e $file ) {          if ( -e $file ) {
78                  return LoadFile( $file );                  return LoadFile( $file );
# Line 82  sub get_state { Line 90  sub get_state {
90  sub all_uids {  sub all_uids {
91          my $self = shift;          my $self = shift;
92    
93          opendir(my $d, $dir) || die "can't opendir $dir: $!";          opendir(my $d, $path) || die "can't opendir $path: $!";
94          my @uids = grep { /\.yml$/ && -f "$dir/$_" } readdir($d);          my @uids = grep { /\.yml$/ && -f "$path/$_" } readdir($d);
95          closedir $d;          closedir $d;
96    
97          return map { my $l = $_; $l =~ s/\.yml$//; $l } @uids;          return map { my $l = $_; $l =~ s/\.yml$//; $l } @uids;

Legend:
Removed from v.139  
changed lines
  Added in v.140

  ViewVC Help
Powered by ViewVC 1.1.26