Various Tools for interacting with Beancount commands and files in the Perl language
Find a file
Bradley M. Kuhn d6914c481c
Switch from IPC::Run to Expect module; set PAGER to /usr/bin/cat
After some efforts to make this current incarnation of the daemon
work for situations with excessively long output, I discovered two
problems.

First, bean-query seems to always use a pager in interactive mode,
and it seems impossible to dissuade bean-query from this behavior
without an upstream change to Beancount.  As such, my first effort
was to force the pager to be `/usr/bin/cat`, which I thought would be
sufficient to solve the problem entirely.

After that change coupled with much debugging with IPC::Run, I found
that detecting the beancount> prompt using a regular expression of
/^\s*beancount\s*\>\s*/m, or similar efforts with simply
/\s*beancount\s*/ or other versions like /\s*beancount\s*\>\s*$/ms
/\s*beancount\s*\>\s*$/s, simply would not detect the end of the
string, so the process hung on this line in the main loop:

    pump $runningBeanQuery until $rbcOut =~ /^\s*beancount\s*\>\s*/m;

Ironically, when there is *not* copious output, that line worked just
fine.  It was baffling.

I switched to Expect, and found the exact same behavior with:

    $runningBeanQuery->expect(undef, -re => '^\s*beancount\s*\>\s*')

with that line, it works fine in the StartRunningBeanQuery()
subroutine, but when used in the main loop, Expect never finds that
string.  Again, I tried it with various regexes as specified above to
no avail.

*However*, merely changing the line to:

    $runningBeanQuery->expect(undef, 'beancount>')

(i.e., not using the regex feature in the Expect library), fixed the
problem entirely.

My working theory is some complex interaction bug between the IO::Pty
module, regular expression matching, and output timing (since this
problem only shows up when there is copious output).  I think in
particular the fact that bean-query creates a subprocess for the
`PAGER` command in the pty when the output is copious is somehow
related to the problem.

Regardless, this solution now works in all the cases where I'm using
the daemon, so I'm not investigating further.
2020-08-17 08:58:25 -07:00
AGPL-3.0.txt GNU Affero General Public License 3.0 as published by the FSF 2020-06-15 12:06:34 -07:00
bean-query-daemon-lib.pl Don't try to cleanup data in client when FIFO doesn't appear. 2020-06-16 13:37:42 -07:00
bean-query-goofy-daemon.plx Switch from IPC::Run to Expect module; set PAGER to /usr/bin/cat 2020-08-17 08:58:25 -07:00
COPYRIGHT Add copyright information for this repository. 2020-06-15 12:48:05 -07:00
LICENSE LICENSE of this project is AGPL-3.0-or-later. 2020-06-15 12:47:50 -07:00
README.md bean-query daemon: initial version. 2020-06-15 14:26:31 -07:00

Beancount Tools Written in Perl

These are various tools written in Perl to interact with Beancount project.

bean-query-goofy-daemon.plx

This daemon uses Perl's IPC::Shareable library to take queries as a daemon for Beancount's bean-query. Note that this daemon is not particularly secure, as it has the same security flaws inherent in IPC::Shareable and use of named pipes (as it uses mkfifo from Perl's POSIX library underneath.

bean-query-daemon-lib.pl

This file defines three functions to use in client scripts that want to talk to bean-query-goofy-daemon.plx.

It's not an actual Perl library; just use require in Perl to load it.

[comment]: Local variables: [comment]: mode: markdown [comment]: eval: (visual-line-mode t) [comment]: eval: (auto-fill-mode -1) [comment]: End: