Nicolas Steenlant > Catmandu-0.1002 > Catmandu::Bag

Download:
Catmandu-0.1002.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source   Latest Release: Catmandu-0.9209

NAME ^

Catmandu::Bag - A Catmandu::Store comparment to persist data

SYNOPSIS ^

    my $store = Catmandu::Store::DBI->new(data_source => 'DBI:mysql:database=test');

    my $store = Catmandu::Store::DBI->new(
            data_source => 'DBI:mysql:database=test',
            bags => { data => { fixes => [ ... ] } },
            bag_class => Catmandu::Bag->with_plugins('Datestamps')
            );
    
    # Use the default bag...
    my $bag = $store->bag;

    # Or a named bag...
    my $bag = $store->bag('journals');

    # Every bag is an iterator...
    $bag->each(sub { ... });
    $bag->take(10)->each(sub { ... });

    $bag->add($hash);
    $bag->add_many($iterator);
    $bag->add_many([ $hash, $hash , ...]);

    # Commit changes...
    $bag->commit;

    my $obj = $bag->get($id);
    $bag->delete($id);

    $bag->delete_all; 

METHODS ^

new(fixes => [...])

Create a new Bag with optionally an array of fixes for each item.

add($hash)

Add one hash to the store or updates an existing hash by using its '_id' key. Returns the stored hash on success or undef on failure.

add_many($array)

add_many($iterator)

Add or update one or more items to the store.

get($id)

Retrieves the item with identifier $id from the store.

delete($id)

Deletes the item with identifier $id from the store.

delete_all

Deletes all items from the store.

commit

Commit changes.

log

Return the current logger.

CLASS METHODS ^

with_plugins($plugin)

with_plugins(\@plugins)

Plugins are a kind of fixes that should be available for each bag. E.g. the Datestamps plugin will automatically store into each bag item the fields 'date_updated' and 'date_created'. The with_plugins accept one or an array of plugin classnames and returns a subclass of the Bag with the plugin methods implemented.

SEE ALSO ^

Catmandu::Iterable, Catmandu::Searchable, Catmandu::Fix, Catmandu::Pluggable

syntax highlighting: