I added something to my blogger I picked up from brian d foy's journal: Namely the ability to get all new journal entries in one go. I mean, how hard can that be? So I just thought I'd use MLDBM to store the entries as returned by the SOAP-call under their ID:
my $db = "$ENV{HOME}/.up/recent";
return if ! -e $db;
tie %RECENT, "MLDBM", $db, O_RDWR if ! tied %RECENT;
my @entries;
while () {
my $id = $RECENT{next_entry};
my $ret = $S->get_entry($id);
last if ! $ret;
last if _had_error($ret) or ! (my $entry = $ret->result);
_preprocess($entry->{body});
push @entries, { id => $id,
subject => $entry->{subject},
nick => $entry->{nickname}, };
$RECENT{$id} = $entry;
$RECENT{next_entry} = $id + 1;
}
return \@entries;
I have another little script that just resets the tied hash to its start id. That's because I need to test it often and I must be able to re-run it as often as like.
Odd is: Sometimes I am able to dump the tied hash using Data::Dumper
but sometimes the output is basically empty (save for the 'next_entry' key). Yet, the records can be retrieved from this seemingly empty hash. It doesn't seem to be possible either to clear the tied hash using %hash = ()
....or at least not all the time.
I am really sick of these inconsistencies so I'll probably drop MLDBM altogether. Instead I'll either use Storable::freeze()/dump()
to serialize each entry in its own file or use some the kind of spool format used by news-servers.
The above code had many other side-effects. _preprocess()
behaved oddly. It's a function where I change $_[0]
in place, like replacing some tags and also piping it through html2text
. This also works half of the time even though it used to work before. Now I occasionally accumulate some zombies through IPC::Open2, non-breaking whitespaces disappear and so on and so forth. I have no idea why my code turned into this kind of poltergeist.