Skip to content

Commit 13e285a

Browse files
committed
better tempfile handling for interactive scripts
1 parent 81778ce commit 13e285a

File tree

10 files changed

+125
-330
lines changed

10 files changed

+125
-330
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ Perl Executing Browser (PEB) is an HTML5 user interface for [Perl 5](https://www
1717
* REQUIREMENTS
1818
* [Compile-Time Requirements](./doc/REQUIREMENTS.md#compile-time-requirements)
1919
* [Runtime Requirements](./doc/REQUIREMENTS.md#runtime-requirements)
20-
* [Files and Folders](./doc/FILES.md)
20+
* FILES AND FOLDERS
21+
* [Application Filename](./doc/FILES.md#application-filename)
22+
* [Application Files and Folders](./doc/FILES.md#application-files-and-folders)
2123
* SETTINGS
22-
* [Application Filename](./doc/SETTINGS.md#application-filename)
2324
* [Global Settings API](./doc/SETTINGS.md#global-settings-api)
2425
* [Perl Scripts API](./doc/SETTINGS.md#perl-scripts-api)
2526
* [Files and Folders Dialogs API](./doc/SETTINGS.md#files-and-folders-dialogs-api)

doc/FILES.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Perl Executing Browser - Files and Folders
22

3-
PEB is created to work from any directory without installation and all paths used by PEB are relative to the directory of the PEB executable, labeled as ``{PEB_executable_directory}`` within this documentation. Only one folder and two file names are hard-coded in C++ code for compatibility with the [Electron](http://electron.atom.io/) framework.
3+
PEB is created to work from any directory without installation and all file paths used by PEB are relative to the directory of the PEB executable, labeled as ``{PEB_executable_directory}`` within this documentation.
4+
5+
## Application Executable
6+
7+
The executable binary file of the browser, ``peb`` or ``peb.exe`` by default, can be renamed with no restrictions or additional adjustments. It can take the name of the PEB-based application it is going to run.
8+
9+
## Application Files and Folders
10+
11+
The following PEB files and folders are hard-coded in C++ code for faster application startup. The PEB application directory is compatible with the application directory of the [Electron](http://electron.atom.io/) framework.
412

513
A minimal ``{PEB_executable_directory}`` looks like this:
614

doc/INTERACTIVE.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Perl Executing Browser - Interactive Perl Scripts
22

3-
PEB interactive Perl scripts are able to receive user input multiple times after the script is started by waiting for new data coming either on STDIN or in a temporary file. Many interactive scripts can be started simultaneously in one PEB instance. One script may be started in many instances, provided that each of them has a JavaScript settings object with an unique name.
3+
PEB interactive Perl scripts are able to receive user input multiple times after the script is started by waiting for new data on STDIN or in a temporary file. Many interactive scripts can be started simultaneously in one PEB instance. One script may be started in many instances, provided that each of them has a JavaScript settings object with an unique name.
44

55
## Requirements for Interactive Perl Scripts
66

@@ -32,10 +32,14 @@ PEB interactive Perl scripts are able to receive user input multiple times after
3232

3333
## Examples of Interactive Perl Scripts
3434

35-
The [index.htm of the demo package](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/index.html) demonstrates how to start automatically one Perl interactive script using STDIN input in two instances.
35+
The [index.htm](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/index.html) file of the demo package demonstrates how to start automatically one Perl interactive script in two instances.
3636

37-
The [interactive.pl script of the demo package](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/perl-scripts/interactive.pl) is an example of a Perl interactive script using STDIN input.
37+
The [interactive.pl](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/perl-scripts/interactive.pl) script of the demo package is an example of a Perl interactive script using STDIN input.
3838

39-
The [index-windows.htm of the demo package](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/index-windows.html) demonstrates how to start automatically one Perl interactive script using a temporary file in two instances.
39+
The [interactive-tempfile.pl](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/perl-scripts/interactive-tempfile.pl) script of the demo package is an example of a Perl interactive script using a temporary file. This script creates a temporary file on startup and sends to PEB its full path in the following JSON format:
4040

41-
The [interactive-windows.pl](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/perl-scripts/interactive-windows.pl) script of the demo package is an example of a Perl interactive script using a temporary file. This script creates a temporary file on startup and sends back to PEB its full path. PEB sends data to the interactive script by forwarding this path and a message text to the STDIN of a helper script, [messenger.pl](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/perl-scripts/messenger.pl). The helper script writes all data received from PEB in the temporary file. The interactive script checks periodically its temporary file for any new messages.
41+
```json
42+
{"tempfile":"/path/to/tempfile"}
43+
```
44+
45+
PEB sends data to the script by writing in its temporary file and the script checks periodically its temporary file for new messages.

doc/SETTINGS.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
# Perl Executing Browser - Settings
22

3-
## Application Filename
4-
5-
The executable binary file of the browser, ``peb`` or ``peb.exe`` by default, can be renamed with no restrictions or additional adjustments. It can take the name of the PEB-based application it is going to run.
6-
73
## Global Settings API
84

95
All global PEB settings are stored in a single JavaScript object named ``pebSettings``. This name is mandatory and hard-coded in C++ code. If ``pebSettings`` JavaScript object is not found, no Perl scripts can be started.
106

117
```javascript
128
var pebSettings = {};
139
pebSettings.perlInterpreter = 'perl/bin/perl';
14-
pebSettings.onStartScripts = ['interactive_one', 'interactive_two'];
10+
pebSettings.autoStartScripts = ['interactive_one', 'interactive_two'];
1511
pebSettings.cutLabel = "Custom Cut Label";
1612
pebSettings.copyLabel = "Custom Copy Label";
1713
pebSettings.pasteLabel = "Custom Paste Label";
@@ -23,7 +19,6 @@ pebSettings.noLabel = "Custom No Label";
2319
pebSettings.closeConfirmation =
2420
'Text was entered in a form and it is going to be lost!\n' +
2521
'Are you sure you want to close the window?';
26-
pebSettings.onExitScripts = ['messenger_one', 'messenger_two'];
2722
```
2823

2924
The ``pebSettings`` JavaScript object may have the following properties:
@@ -34,7 +29,7 @@ The ``pebSettings`` JavaScript object may have the following properties:
3429
``{PEB_executable_directory}/resources/app`` as a root folder.
3530
If a relocatable Perl interpreter is not configured, PEB will use the first Perl interpreter on PATH.
3631

37-
* **onStartScripts**
32+
* **autoStartScripts**
3833
``Array`` of Perl scripts that are started immediately after a local page is loaded
3934

4035
* **cutLabel**
@@ -64,9 +59,6 @@ The ``pebSettings`` JavaScript object may have the following properties:
6459
* **closeConfirmation**
6560
``String`` displayed in a JavaScript Confirm popup box when the close button is pressed, but unsaved data in local HTML forms is detected. If no ``closeConfirmation`` object property is found, PEB shuts down all running Perl scripts and exits.
6661

67-
* **onExitScripts**
68-
``Array`` of Perl scripts that are invoked before application exit
69-
7062
## Perl Scripts API
7163

7264
Every Perl script run by PEB has a JavaScript settings object with an arbitrary name and fixed object properties. The name of the JavaScript settings object with a ``.script`` extension forms a pseudo link used to start the Perl script.
@@ -138,7 +130,7 @@ A JavaScript settings object for a Perl script run by PEB has the following prop
138130

139131
* **inputData**
140132
``String`` or ``Function`` supplying user data as its return value
141-
``inputData`` is written on script STDIN.
133+
``inputData`` is written on script STDIN or in temporary file.
142134

143135
``inputData`` function with no dependencies:
144136

@@ -151,7 +143,7 @@ A JavaScript settings object for a Perl script run by PEB has the following prop
151143

152144
* **exitData**
153145
``String`` or ``Function`` supplying script exit command as its return value
154-
``exitData`` is written on script STDIN.
146+
``exitData`` is written on script STDIN or in temporary file.
155147

156148
## Files and Folders Dialogs API
157149

resources/app/index-windows.html

Lines changed: 0 additions & 216 deletions
This file was deleted.

resources/app/index.html

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// PEB page settings:
2727
var pebSettings = {}; // 'pebSettings' object name is hard-coded.
2828
pebSettings.perlInterpreter = 'perl/bin/perl';
29-
pebSettings.onStartScripts = ['interactive_one', 'interactive_two'];
29+
pebSettings.autoStartScripts = ['interactive_one', 'interactive_two'];
3030
pebSettings.cutLabel = '- Cut -';
3131
pebSettings.copyLabel = '- Copy -';
3232
pebSettings.pasteLabel = '- Paste -';
@@ -38,15 +38,14 @@
3838
pebSettings.closeConfirmation =
3939
'Text was entered in a form and it is going to be lost!\n' +
4040
'Are you sure you want to close the application?';
41-
pebSettings.onExitScripts = ['interactive_one', 'interactive_two'];
4241

4342
// PEB settings objects for auto-started Perl interactive scripts:
4443
var interactive_one = {};
45-
interactive_one.scriptRelativePath = 'perl-scripts/interactive.pl';
44+
interactive_one.scriptRelativePath = 'perl-scripts/interactive-tempfile.pl';
4645

4746
interactive_one.inputData = function() {
4847
var data = {}
49-
data.mode = "unix-epoch";
48+
data.mode = "unix_epoch";
5049
data.user_input = document.getElementById("interactive-one-input").value;
5150
$('#form-one').trigger('reset');
5251
return JSON.stringify(data);
@@ -66,17 +65,16 @@
6665

6766
interactive_one.exitData = function() {
6867
var data = {}
69-
data.mode = "unix-epoch";
70-
data.user_input = "peb-exit";
68+
data.user_input = "exit";
7169
return JSON.stringify(data);
7270
}
7371

7472
var interactive_two = {};
75-
interactive_two.scriptRelativePath = 'perl-scripts/interactive.pl';
73+
interactive_two.scriptRelativePath = 'perl-scripts/interactive-tempfile.pl';
7674

7775
interactive_two.inputData = function() {
7876
var data = {}
79-
data.mode = "local-time";
77+
data.mode = "local_time";
8078
data.user_input = document.getElementById("interactive-two-input").value;
8179
$('#form-two').trigger('reset');
8280
return JSON.stringify(data);
@@ -96,8 +94,7 @@
9694

9795
interactive_two.exitData = function() {
9896
var data = {}
99-
data.mode = "unix-epoch";
100-
data.user_input = "peb-exit";
97+
data.user_input = "exit";
10198
return JSON.stringify(data);
10299
}
103100
</script>

0 commit comments

Comments
 (0)