%#
%# comments - returns a hashref of pic name -> comment; uses cached if possible
%#  The comments are assumed to be read from a file in the directory given
%#  named ".comments" and containing comments in the following format:
%#
%# ** filename.jpg
%# comments, perhaps with <b>HTML tags</b>
%# more comments until you get to the 
%# ** next-file.gif
%# and so on
%#
%# example: %comments = %{$m->comp('/m/pics/comments', 'doodle')};
%#
<%perl>
    my ($path) = @_;
    my ($file, $hr, $current, $o);

    $file = $r->lookup_uri($path)->filename . "/.comments";

    if (($o = $m->cache->get_object($file)) && 
	    $o->get_created_at > (stat($file))[9]) {
	$hr = $o->get_data;
    } else {
	$hr = {};

	open(COMMENTS, $file);
	$_ = <COMMENTS>;
	while (/^\*\*\s+(.+)$/) {
	    $current = $1;
	    while (($_ = <COMMENTS>) !~ /^\*\*/) {
		last unless length;
		$hr->{$current} .= $_;
	    }
	}
	close(COMMENTS);

	$m->cache->set($file, $hr);
    }

    return $hr;
</%perl>
