beancount-tools-in-Perl/bean-query-daemon-lib.pl
Bradley M. Kuhn 42800427f6 bean-query daemon: initial version.
This is a very basic daemon to run bean-query so that other Perl programs
can call it.  The speed savings is not really there yet, as to get that, it
would need to leave bean-query running, perhaps timing out and reloading
files as needed.  That's the long term plan.

Right now, all that this is useful for is to run another Perl process that
wants to submit and receive answers to bean-query.
2020-06-15 14:26:31 -07:00

36 lines
1.1 KiB
Perl

# License: AGPLv3-or-later
# see files COPYRIGHT, LICENSE, and AGPL-3.0.txt included in canonical repository for details.
# https://k.sfconservancy.org/NPO-Accounting/beancount-tools-in-Perl
use strict;
use warnings;
our %BEANCOUNT_QUERY;
my $IPC_GLUE = 'BeAn';
sub BeancountQueryInitialize {
my %options = (create => 0, exclusive => 0, mode => 0600, destroy => 0);
tie %BEANCOUNT_QUERY, 'IPC::Shareable', $IPC_GLUE, { %options } or
die "BEANCOUNT_QUERY: tie failed: is the goffy beancount server running?\n";
}
sub BeancountQuerySubmit($) {
my($question) = @_;
(tied %BEANCOUNT_QUERY)->shlock;
$BEANCOUNT_QUERY{fifoName} = undef;
$BEANCOUNT_QUERY{question} = $question;
(tied %BEANCOUNT_QUERY)->shunlock;
while (not defined $BEANCOUNT_QUERY{fifoName}) { sleep 1; }
die "Ceci n'est pas une pipe: BEANCOUNT_QUERY{fifoName}, $BEANCOUNT_QUERY{fifoName}:$!"
unless (-p $BEANCOUNT_QUERY{fifoName});
(tied %BEANCOUNT_QUERY)->shlock;
return $BEANCOUNT_QUERY{fifoName};
}
sub BeancountQueryComplete {
$BEANCOUNT_QUERY{question} = undef;
(tied %BEANCOUNT_QUERY)->shunlock;
}
1;