Bot::BasicBot::Pluggable::Store::Deep - use DBM::Deep to provide a storage backend


Bot-BasicBot-Pluggable documentation Contained in the Bot-BasicBot-Pluggable distribution.

Index


Code Index:

NAME

Top

Bot::BasicBot::Pluggable::Store::Deep - use DBM::Deep to provide a storage backend

VERSION

Top

version 0.93

SYNOPSIS

Top

  my $store = Bot::BasicBot::Pluggable::Store::Deep->new(
    file => "filename"
  );

  $store->set( "namespace", "key", "value" );

DESCRIPTION

Top

This is a Bot::BasicBot::Pluggable::Store that uses DBM::Deep to store the values set by modules.

AUTHOR

Top

Simon Wistow <simon@thegestalt.org>

COPYRIGHT

Top


Bot-BasicBot-Pluggable documentation Contained in the Bot-BasicBot-Pluggable distribution.

package Bot::BasicBot::Pluggable::Store::Deep;
BEGIN {
  $Bot::BasicBot::Pluggable::Store::Deep::VERSION = '0.93';
}
use warnings;
use strict;
use DBM::Deep;

use base qw( Bot::BasicBot::Pluggable::Store );

sub init {
    my $self = shift;
    delete $self->{type};
    $self->{file} ||= 'bot-basicbot.deep';
    $self->{_db} = DBM::Deep->new(%$self)
      || die "Couldn't connect to DB '$self->{file}'";
}

sub set {
    my ( $self, $namespace, $key, $value ) = @_;
    $self->{_db}->{$namespace}->{$key} = $value;
    return $self;
}

sub get {
    my ( $self, $namespace, $key ) = @_;
    return $self->{_db}->{$namespace}->{$key};
}

sub unset {
    my ( $self, $namespace, $key ) = @_;
    delete $self->{_db}->{$namespace}->{$key};
}

sub keys {
    my ( $self, $namespace, %opts ) = @_;

    # no idea why this works
    return CORE::keys %{ $self->{_db}->{$namespace} }
      unless exists $opts{res} && @{ $opts{res} };
    my $mod = $self->{_db}->{$namespace} || {};
    return $self->_keys_aux( $mod, $namespace, %opts );
}

sub namespaces {
    my ($self) = @_;
    return CORE::keys %{ $self->{_db} };
}

1;

__END__