X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FCWMP%2FStore%2FYAML.pm;h=7be49eef9a0a7327a24b04aa99f05daa61553d9a;hb=ab3c8b6b75a3c7fb9ddc5a0c474fb1aa7269bc83;hp=588060fd320144df16c6158ae0c96f8f36c523b8;hpb=94d44753b14c178db4c33388f88e59e1de81c016;p=perl-cwmp.git diff --git a/lib/CWMP/Store/YAML.pm b/lib/CWMP/Store/YAML.pm index 588060f..7be49ee 100644 --- a/lib/CWMP/Store/YAML.pm +++ b/lib/CWMP/Store/YAML.pm @@ -4,82 +4,43 @@ package CWMP::Store::YAML; use strict; use warnings; -use Data::Dump qw/dump/; -use YAML qw/LoadFile DumpFile/; +use CWMP::Store::HASH; +use base qw/CWMP::Store::HASH/; + +use YAML::Syck; =head1 NAME CWMP::Store::YAML - use YAML as storage -=head1 METHODS - -=head2 open - =cut -my $dir = 'yaml'; - -my $debug = 1; - -sub open { - my $self = shift; - - warn "open ",dump( @_ ); - - if ( ! -e $dir ) { - mkdir $dir || die "can't create $dir: $!"; - warn "created $dir directory\n"; - } - -} - -=head2 update_uid_state - - $store->update_uid_state( $uid, $state ); - -=cut - -sub update_uid_state { - my ( $self, $uid, $state ) = @_; - - my $file = "$dir/$uid.yml"; - - DumpFile( $file, $state ) || die "can't write $file: $!"; +my $full_path; +sub full_path { + my ( $self, $path ) = @_; + $full_path = "$path/yaml"; + warn "## full_path: $full_path" if $debug; + return $full_path; } -=head2 get_state - - $store->get_state( $uid ); - -=cut - -sub get_state { +sub file { my ( $self, $uid ) = @_; - - my $file = "$dir/$uid.yml"; - - if ( -e $file ) { - return LoadFile( $file ); - } - - return; + my $file = "$full_path/$uid" . $self->extension; + warn "## file -> $file" if $debug; + return $file; } -=head2 all_uids - - my @uids = $store->all_uids; - -=cut - -sub all_uids { - my $self = shift; - - opendir(my $d, $dir) || die "can't opendir $dir: $!"; - my @uids = grep { /\.yml$/ && -f "$dir/$_" } readdir($d); - closedir $d; +sub save_hash { + my ( $self, $file, $hash ) = @_; + DumpFile( $file, $hash ); +} - return map { s/\.yml$// } @uids; +sub load_hash { + my ( $self, $file ) = @_; + LoadFile( $file ); } +sub extension { '.yml' }; + 1;