NAME

Data::TagDB::Iterator - Work with Tag databases

VERSION

version v0.07

SYNOPSIS

use Data::TagDB;

Generic iterator for database entries

METHODS

new

my Data::TagDB::Iterator = XXX->new(...);

Returns a new iterator. Maybe called in sub-packages implementing actual iterators.

db

my Data::TagDB $db = $db->db;

Returns the current Data::TagDB object

next

my $entry = $iter->next;

Returns the next element or undef when there is no next element.

Needs to be implemented.

finish

$iter->finish;

Tells the iterator that you're done reading. May allow early freeing of backend data.

Needs to be implemented.

foreach

$iter->foreach(sub {
    my ($entry) = @_;
    # ...
});

Runs a function for each entry. Automatically finishes the iterator.

one

my $entry = $iter->one;

Returns one entry from the iterator and finishes. This is most useful when you expect there to be exactly one entry. This function dies if no entry is returned. So It is guaranteed that this function returns non-undef.

none

$iter->none;

This method dies if there is an entry left in the iterator. This finishes the iterator. This is most useful to assert that something is not present.

map

my Data::TagDB::Iterator $mapped = $iter->map('method');
# or:
my Data::TagDB::Iterator $mapped = $iter->map(sub { ... });

Returns a new iterator that contains the entries mapped by a filter. If the filter is a simple string it is as a method name to be called on the object.

collect

my @list = $iter->collect;
# or:
my @list = $iter->collect('method');
# or:
my @list = $iter->collect(sub { ... });

Reads all entries from an iterator and finishes. The entries are returned as a list. Optionally a filter can be applied. If the filter is a simple string it is as a method name to be called on the object.

AUTHOR

Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2024 by Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)