UPDATE 2023-03-27: This page is obsolete, as it refers to a prior version of this blog. However, it may be of historical interest.

I’ve been using the entries_cache_meta plugin by Jason Thaxter, mainly for the convenience of specifying the modification date within the entry file. After a while I decided I’d like to also use its “meta” capability, i.e., the ability to specify arbitrary variables in the entry header along with the modification time, e.g.,

The entry title
meta-mtime: 2005/01/17 12:18:00
meta-foo: Whatever you want

The entry text begins here . . .

and then reference the variables as, e.g., $meta::foo within the story template (as is possible with Rael Dornfest’s original meta plugin). Unfortunately, I couldn’t get this to work at all.

After a bit of debugging I managed to find out what the problem was: The plugin code for the story subroutine attempts to take the cached meta values for the current story and stuff them into the “meta” namespace, so that they can be accessed as, e.g., $meta::foo. However the code doesn’t correctly access the cached set of meta values for the entry; it uses as a cache key the value of the variable $filename as passed to the story subroutine, but this variable is simply the basename of the entry file (e.g., “foo"). What it should be using is the full absolute pathname of the entry file, e.g., /blosxom/data/abc/foo.txt.

The fix is very simple: use the standard Blosxom variables $blosxom::datadir and $blosxom::file_extension and the variable $path (also passed to the story subroutine) along with $filename to recreate the entry file’s absolute pathname. For full details see the one-line patch itself.

A final note: The documentation for the entries_cache_meta plugin claims as a special feature that

By combining the meta-tag functionality with the entries cache, it becomes possible to write or use plugins that access meta-values outside the story hook. For example, you could use this plugin to write another one showing the most recent entry for each author defined in meta tags.

The documentation doesn’t expand on how this would be possible, and in my confusion I was thinking that this was done using $meta::foo variables; this is not correct. The problem is that entry-specific meta variables have a unique meaning and value only in the context of a single entry. For example, one entry file might have a line meta-foo: abc and another file a line meta-foo: xyz; hence $meta::foo would have the value ’abc’ in the context of the first entry (e.g., when processing a story template for that entry) and the value ’xyz’ in the context of the second entry. Outside the context of those two entries (e.g., when processing a head template) it doesn’t make sense to refer to $meta::foo.

Now having said that, with the entries_cache_meta plugin it is in fact possible to make use of cached meta values outside the context of an entry, since the variable %entries_cache_meta::cache is populated as soon as the entries subroutine is run. For example, a plugin could loop over all the entries to be displayed and determine how many entries were by a particular author, as determined by a “meta-author” field in the entry files:

my %num_by;                   # number of entries for each author
for my $entry (keys %entries_cache_meta::cache) {
    $entries_cache_meta::cache{$entry}{’author’}
        and $num_by{$entries_cache_meta::cache{$entry}{’author’}}++
}

The results could then be used to customize the head section of the page (e.g., to identify the most prolific author).