NAME

Bot::BasicBot::Pluggable::Store - base class for the back-end pluggable store

VERSION

version 1.10

SYNOPSIS

my $store = Bot::BasicBot::Pluggable::Store->new( option => "value" );

my $namespace = "MyModule";

for ( $store->keys($namespace) ) {
  my $value = $store->get($namespace, $_);
  $store->set( $namespace, $_, "$value and your momma." );
}

Store classes should subclass this and provide some persistent way of storing things.

METHODS

new()

Standard new method, blesses a hash into the right class and puts any key/value pairs passed to it into the blessed hash. If called with an hash argument as its first argument, new_from_hashref will be run with the hash as its only argument. See "new_from_hashref" for the possible keys and values. You can also pass a string and it will try to call new_from_hashref with a hash reference { type => $string }. Calls load() to load any internal variables, then init, which you can also override in your module.

new_from_hashref( $hashref )

Intended to be called as class method to dynamically create a store object. It expects a hash reference as its only argument. The only required hash element is a string specified by type. This should be either a fully qualified classname or a colonless string that is appended to Bot::BasicBot::Pluggable::Store. All other arguments are passed down to the real object constructor.

init()

Called as part of new class construction, before load().

load()

Called as part of new class construction, after init().

save()

Subclass me. But, only if you want to. See ...Store::Storable.pm as an example.

keys($namespace,[$regex])

Returns a list of all store keys for the passed $namespace.

If you pass $regex then it will only pass the keys matching $regex

get($namespace, $variable)

Returns the stored value of the $variable from $namespace.

set($namespace, $variable, $value)

Sets stored value for $variable to $value in $namespace. Returns store object.

unset($namespace, $variable)

Removes the $variable from the store. Returns store object.

namespaces()

Returns a list of all namespaces in the store.

dump()

Dumps the complete store to a huge Storable scalar. This is mostly so you can convert from one store to another easily, i.e.:

my $from = Bot::BasicBot::Pluggable::Store::Storable->new();
my $to   = Bot::BasicBot::Pluggable::Store::DBI->new( ... );
$to->restore( $from->dump );

dump is written generally so you don't have to re-implement it in subclasses.

restore($data)

Restores the store from a dump().

AUTHOR

Mario Domgoergen <mdom@cpan.org>

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

SEE ALSO

Bot::BasicBot::Pluggable

Bot::BasicBot::Pluggable::Module