#!/usr/bin/env perl

# Here is an example how to access the data.

use strict;
use warnings;
use diagnostics;

use MLDBM qw(DB_File Storable);
use Fcntl;

my $file = $ARGV[0];

my %entries;
tie(%entries, 'MLDBM', $file, O_RDONLY, 0640) or die $!;

foreach my $id (keys %entries) {
    my $entry = $entries{$id};
    foreach my $field (('writer', 'date', 'title', 'rating', 'tags', 'comments')) {
        print $field;
        my $value = $entry->{$field};
        print " - ", $value, "\n" unless ref $value;

        if ($field eq 'tags') {
            print "\n";
            foreach my $val (@$value) {
                print "  tag: ", $val, "\n";
            }
        }

        if ($field eq 'comments') {
            print "\n";
            foreach my $id (keys %{$value}) {
                my $comment = $value->{$id};
                print "  $comment->{'writer'}, $comment->{'date'}, $comment->{'rating'}\n";
            }
        }

    }
    print "\n";
}
