camel-harness v1.1.3
camel-harness
Node.js - Electron - NW.js package for asynchronous handling of Perl scripts
Quick Start
npm install camel-harness
const camelHarness = require("camel-harness");
let perlTest = {};
perlTest.script = "/test/test.pl";
perlTest.stdoutFunction = function (stdout) {
console.log(stdout);
};
camelHarness.startScript(perlTest);Core Dependency
child_process
External Dependency
Perl interpreter identified by filename on PATH or full pathname
camel-harness npm package test will fail if no perl binary is available on PATH.
API
All settings of a Perl script executed by camel-harness are stored in a JavaScript object with an arbitrary name and the following object properties:
script
Stringfor Perl script full path or Perl code executed as an one-liner
This object property is mandatory.perlTest.script = "/full/path/to/test.pl";The
-einterpreter switch must be set when Perl code is executed in one-liner mode.
Perl code must not be surrounded in single quotes and all double quotes must be escaped.One-liner example:
let oneLiner = {}; oneLiner.interpreterSwitches = []; oneLiner.interpreterSwitches.push("-e"); oneLiner.script = "use English; print \"Perl $PERL_VERSION\";" oneLiner.stdoutFunction = function (stdout) { console.log(`${stdout}`); }; camelHarness.startScript(oneLiner);stdoutFunction
will be executed every time data is available on STDOUT
The only parameter passed to thestdoutFunctionis the STDOUTString.perlTest.stdoutFunction = function (stdout) { document.getElementById("DOM-element-id").textContent = stdout; };stderrFunction
will be executed every time data is available on STDERR
The only parameter passed to thestderrFunctionis the STDERRString.perlTest.stderrFunction = function (stderr) { console.log("Perl script STDERR:\n"); console.log(stderr); };errorFunction
will be executed on Perl script error
The only parameter passed to theerrorFunctionis the errorObject.The
errorFunctioncan generate a message when Perl interpreter is not found:perlTest.errorFunction = function (error) { if (error.code === "ENOENT") { console.log("Perl interpreter was not found."); } };exitFunction
will be executed when Perl script has ended
The only parameter passed to theexitFunctionis the exit codeString.The
exitFunctioncan generate a message when Perl script is not found:perlTest.exitFunction = function (exitCode) { if (exitCode === 2) { console.log("Perl script was not found."); } };perlInterpreter
Stringfor a Perl interpreter: either filename on PATH or full pathname
If noperlInterpreteris defined,perlbinary on PATH is used, if available.perlTest.interpreter = "/full/path/to/perl";interpreterSwitches
Arrayfor Perl interpreter switchesperlTest.interpreterSwitches = []; perlTest.interpreterSwitches.push("-W");scriptArguments
Arrayfor Perl script argumentsperlTest.scriptArguments = []; perlTest.scriptArguments.push("argument-one"); perlTest.scriptArguments.push("argument-two");options
Objectfor Perl script options passed to thechild_processcore module.
Click here for a full list of all availablechild_processoptions.options.cwd
Stringfor a new Perl script current working directoryperlTest.options = {}; perlTest.options.cwd = "/full/path/to/current-working-directory";;options.env
Objectfor a new Perl script environmentScript environment with an inherited PATH and a new variable:
perlTest.options = {}; perlTest.options.env = {}; perlTest.options.env.PATH = process.env.PATH; perlTest.options.env.TEST = "test";options.detached
Booleanoption for starting detached Perl processes like serversoptions.detachedmust be set totrueandoptions.stdiomust be set to"ignore"to
start a detached process without receiving anything from it.
A process detached with the above options can run even after its parent has ended.Example settings for a Perl server application:
let perlServer = {}; perlServer.script = "/path/to/perl-server-application"; perlServer.options = {}; perlServer.options.detached = true; perlServer.options.stdio = "ignore"; const camelHarness = require("camel-harness"); camelHarness.startScript(perlServer); perlServer.scriptHandler.unref();inputData
StringorFunctionsupplying user data as its return value.inputDatais written on script STDIN.inputDatafunction with no dependencies:perlTest.inputData = function () { let data = document.getElementById("input-box-id").value; return data; }
Interactive Scripts
camel-harness can also start and communicate with interactive scripts having their own event loops and capable of repeatedly receiving STDIN input. Use the following code to send data to an interactive script waiting for input on STDIN:
let data = document.getElementById("interactive-script-input").value;
perlTest.scriptHandler.stdin.write(data);camel-harness demo packages for Electron and NW.js include a Perl script that can be constantly fed with data from an HTML interface. Perl with the AnyEvent CPAN module has to be available on PATH.
Electron Demo
NW.js Demo
Credits
License
MIT 2016 - 2018
Dimitar D. Mitov
4 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago