Data::Remember::YAML - a frozen memory brain plugin for Data::Remember


Data-Remember documentation Contained in the Data-Remember distribution.

Index


Code Index:

NAME

Top

Data::Remember::YAML - a frozen memory brain plugin for Data::Remember

SYNOPSIS

Top

  use Data::Remember YAML => file => 'brain.yml';

  my $blah = recall 'something';

DESCRIPTION

Top

This brain plugin uses YAML::Syck to load and store information for Data::Remember. To use this module you must specify the "file" argument to tell the module where to load the data from.

METHODS

Top

new file => FILENAME

Pass the name of the file to use to load the data from. The "file" argument is required.

load FILENAME

Reloads the information from the YAML file or loads information from a different YAML file. The FILENAME argument is optional, if not given the file loaded will be the one that was given when the brain was originally created.

dump FILENAME

Dumps the informaiton from the configuration file or saves information into another file. The FILENAME argument is optional, if not given the file saved to will be the one that was given when the brain was originally created.

SEE ALSO

Top

Data::Remember, Data::Remember::Memory

AUTHOR

Top

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Data-Remember documentation Contained in the Data-Remember distribution.
use strict;
use warnings;

package Data::Remember::YAML;
use base qw/ Data::Remember::Memory /;

our $VERSION = '0.000001';

use Carp;
use YAML::Syck ();

sub new {
    my $class = shift;
    my %args  = @_;

    croak 'You must specify a "file" to load the data from.'
        unless $args{file};

    my $brain;
    if (-f $args{file}) {
        $brain = YAML::Syck::LoadFile($args{file});
    }
    else {
        carp qq{Empty brain, "$args{file}" is not a file.};
        $brain = {};
    }

    bless { 
        brain => $brain,
        file  => $args{file},
    }, $class;
}

sub load {
    my $self = shift;
    my $file = shift || $self->{file};

    $self->{brain} = YAML::Syck::LoadFile($file);
}

sub dump {
    my $self = shift;
    my $file = shift || $self->{file};

    YAML::Syck::DumpFile($file, $self->{brain});
}

1;