Catmandu::Store(3) Namespace for packages that can make data persistent

SYNOPSIS


use Catmandu::Store::DBI;
my $store = Catmandu::Store::DBI->new(data_source => 'DBI:mysql:database=test');
my $obj1 = $store->bag->add({ name => 'Patrick' });
printf "obj1 stored as %s\n" , $obj1->{_id};
# Force an id in the store
my $obj2 = $store->bag->add({ _id => 'test123' , name => 'Nicolas' });
my $obj3 = $store->bag->get('test123');
$store->bag->delete('test123');
$store->bag->delete_all;
# Some stores can be searched
my $hits = $store->bag->search(query => 'name:Patrick');

DESCRIPTION

A Catmandu::Store is a stub for Perl packages that can store data into databases or search engines. The database as a whole is called a 'store'. Databases also have compartments (e.g. tables) called Catmandu::Bag-s. Some stores can be searched using Catmandu::Searchable methods.

METHODS

new(%store_args, bag_class => $class, default_bag => $name, bags => { $bagname => \%bag_args })

Create a new Catmandu::Store. Optionally provide the class name of a sub-class of Catmandu::Bag, and the name of the default bag ('data'). Startup parameters can be provided for each $bagname using the 'bags' parameter. E.g.

 my $store = Catmandu::Store::Hash->new(
                bags => {myBag => {plugins => ['Datestamps']}});
 # $store->bag('myBag') will now contain Datestamps
 
 my $bag_class = "Catmandu::Store::Hash::Bag"
 my $store = Catmandu::Store::Hash->new(
                bag_class => $bag_class->with_plugins('Datestamps')
             );
 
 # All $store->bag(...)'s will now contain Datestamps

bag($name)

Create or retieve a bag with name $name. Returns a Catmandu::Bag.

log

Return the current logger. Can be used when creating your own Stores.

E.g.

    package Catmandu::Store::Hash;
    ...
    sub generator {
        my ($self) = @_;
        $self->log->debug("generating record");
        ...
    }

See also: Catmandu for activating the logger in your main code.