File: Deep.pm

package info (click to toggle)
libbot-basicbot-pluggable-perl 1.20-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 528 kB
  • sloc: perl: 3,141; makefile: 17
file content (82 lines) | stat: -rw-r--r-- 1,733 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package Bot::BasicBot::Pluggable::Store::Deep;
$Bot::BasicBot::Pluggable::Store::Deep::VERSION = '1.20';
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__

=head1 NAME

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

=head1 VERSION

version 1.20

=head1 SYNOPSIS

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

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

=head1 DESCRIPTION

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

=head1 AUTHOR

Simon Wistow <simon@thegestalt.org>

=head1 COPYRIGHT

Copyright 2005, Simon Wistow

This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.