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 { my $l = $_; $l =~ s/\.yml$//; $l } @uids;
+sub load_hash {
+ my ( $self, $file ) = @_;
+ LoadFile( $file );
}
+sub extension { '.yml' };
+
1;