Skip to content

Commit f7980d5

Browse files
committed
faster termination of Perl scripts on browser exit
1 parent 1403a4d commit f7980d5

File tree

18 files changed

+135
-278
lines changed

18 files changed

+135
-278
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Perl Executing Browser (PEB) is an HTML5 user interface for [Perl 5](https://www
2121
* [Runtime Requirements](./doc/REQUIREMENTS.md#runtime-requirements)
2222
* [CONSTANTS](./doc/CONSTANTS.md)
2323
* [Files and Folders](./doc/CONSTANTS.md#files-and-folders)
24-
* [Functional Pseudo Filenames](./doc/CONSTANTS.md#functional-pseudo-filenames)
24+
* [Functional Pseudo Filename](./doc/CONSTANTS.md#functional-pseudo-filename)
2525
* [SETTINGS](./doc/SETTINGS.md)
2626
* [Application Filename](./doc/SETTINGS.md#application-filename)
2727
* [HTML Page API](./doc/SETTINGS.md#html-page-api)
@@ -68,8 +68,8 @@ in the documentation of this project are to be interpreted as described in [RFC
6868

6969
* **4.** Write a ``{PEB_executable_directory}/resources/app/index.html`` with
7070
a [settings JavaScript object](./doc/SETTINGS.md#perl-scripts-api) for every Perl script you want to use.
71-
Local Perl scripts can be called from your HTML page by one of the [three possible methods](./doc/SETTINGS.md#perl-scripts-api).
72-
[Selecting files or folders with their full paths](./doc/SETTINGS.md#selecting-files-and-folders) is also possible.
71+
Start local Perl scripts by [clicking a link or submitting a form to a special URL](./doc/SETTINGS.md#perl-scripts-api).
72+
[Select files or folders with their full paths by clicking a link to a special URL](./doc/SETTINGS.md#selecting-files-and-folders).
7373

7474
## Design Objectives
7575

doc/CONSTANTS.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ A typical ``{PEB_executable_directory}`` looks like this:
4848
If this file is found during application startup, it is used as the icon of the application and all dialog boxes.
4949
If this file is not found, the default icon embedded in the resources of the browser binary is used.
5050

51-
## Functional Pseudo Filenames
51+
## Functional Pseudo Filename
5252

53-
* **About PEB dialog:** ``about-browser.function``
54-
* **About Qt dialog:** ``about-qt.function``
53+
* **About dialog:** ``about.function``

doc/SETTINGS.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,22 @@ The ``pebSettings`` JavaScript object may have the following properties:
6060

6161
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.
6262

63-
There are three methods to start a local Perl script:
63+
There are two methods to start a local Perl script:
6464

65-
* **Clicking a link to a script pseudo link:**
65+
* **Clicking a link to a pseudo link:**
6666

6767
```html
6868
<a href="test.script">Start Perl script</a>
6969
```
7070

71-
* **Submitting a form to a script pseudo link:**
71+
* **Submitting a form to a pseudo link:**
7272

7373
```html
7474
<form action="test.script">
7575
<input type="submit" value="Start Perl script">
7676
</form>
7777
```
7878

79-
* **Calling a JavaScript function with a script pseudo link:**
80-
81-
```javascript
82-
peb.startScript('test.script');
83-
```
84-
85-
This method creates an invisible form and submits it to the script pseudo link.
86-
8779
An example of a JavaScript settings object for a Perl script run by PEB:
8880

8981
```javascript
@@ -148,13 +140,12 @@ A JavaScript settings object for a Perl script run by PEB has the following prop
148140

149141
## Interactive Perl Scripts
150142

151-
Each PEB interactive Perl script must have its own event loop waiting constantly for new data on STDIN or in a temporary file for a bidirectional connection with PEB. 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 an uniquely named JavaScript settings object.
143+
Each PEB interactive Perl script must have its own event loop waiting constantly for new data on STDIN or in a temporary file for a bidirectional connection with PEB. 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.
152144

153145
A PEB interactive Perl script should have the following features:
154146

155147
* **No buffering**
156148
PEB interactive scripts should run with no output buffering preventing output before the script has ended.
157-
158149
Output buffering could be disabled using the following code:
159150

160151
```perl
@@ -164,8 +155,7 @@ A PEB interactive Perl script should have the following features:
164155
```
165156

166157
* **Failsafe print**
167-
Failsafe print is necessary for a graceful shutdown of Perl scripts on normal PEB exit and when PEB unexpectedly crashes. When the close button is pressed, PEB closes the STDOUT and STDERR channels of all running Perl scripts and within 3 seconds they must detect their inability to print messages and exit or any unresponsive scripts will be killed.
168-
158+
Failsafe print is necessary to shut down PEB Perl scripts when PEB unexpectedly crashes.
169159
Failsafe print could be implemented using the following code:
170160

171161
```perl

resources/app/index-windows.html

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
// PEB settings objects for auto-started Perl interactive scripts:
2626
var messenger_one = {};
2727
messenger_one.scriptRelativePath = 'perl-scripts/messenger.pl';
28-
2928
messenger_one.message = {};
29+
3030
messenger_one.inputData = function() {
3131
messenger_one.message.user_input =
3232
document.getElementById("interactive-one-input").value;
@@ -36,8 +36,8 @@
3636

3737
var messenger_two = {};
3838
messenger_two.scriptRelativePath = 'perl-scripts/messenger.pl';
39-
4039
messenger_two.message = {};
40+
4141
messenger_two.inputData = function() {
4242
messenger_two.message.user_input =
4343
document.getElementById("interactive-two-input").value;
@@ -108,7 +108,8 @@
108108
<nav class="navbar navbar-default navbar-fixed-top">
109109
<div class="container">
110110
<div class="navbar-header">
111-
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
111+
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
112+
data-target="#navbar" aria-expanded="false" aria-controls="navbar">
112113
<span class="sr-only">Toggle navigation</span>
113114
<span class="icon-bar"></span>
114115
<span class="icon-bar"></span>
@@ -119,7 +120,10 @@
119120
<div id="navbar" class="navbar-collapse collapse">
120121
<ul class="nav navbar-nav">
121122
<li class="dropdown">
122-
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Tests<span class="caret"></span></a>
123+
<a href="#" class="dropdown-toggle" data-toggle="dropdown"
124+
role="button" aria-haspopup="true" aria-expanded="false">Tests
125+
<span class="caret"></span>
126+
</a>
123127
<ul class="dropdown-menu">
124128
<li>
125129
<a href="select_file.dialog">Open Existing File</a>
@@ -138,11 +142,11 @@
138142
</li>
139143

140144
<li>
141-
<a href="javascript:startPerlInfo();">Perl Basic Information</a>
145+
<a href="perl_info.script">Perl Basic Information</a>
142146
</li>
143147

144148
<li>
145-
<a href="javascript:startSqlite();">SQLite Test</a>
149+
<a href="sqlite.script">SQLite Test</a>
146150
</li>
147151

148152
<li>
@@ -157,17 +161,7 @@
157161

158162
<li><a href="https://www.google.com/">Google</a></li>
159163

160-
<li class="dropdown">
161-
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">About<span class="caret"></span></a>
162-
<ul class="dropdown-menu">
163-
<li>
164-
<a href="about-browser.function">About PEB</a>
165-
</li>
166-
167-
<li>
168-
<a href="about-qt.function">About Qt</a>
169-
</li>
170-
</li>
164+
<li><a href="about.function">About</a></li>
171165
</ul>
172166
</div>
173167
</div>
@@ -180,7 +174,10 @@ <h2>Perl Executing Browser</h2>
180174

181175
<div class="row">
182176
<div class="col-lg-12 introduction">
183-
Perl Executing Browser (PEB) is an HTML5 user interface for Perl 5 desktop applications. It is a C++ Qt 5 application running local Perl 5 scripts as child processes without server. Inspired by Electron and NW.js, PEB is another reuse of web technologies in desktop applications with Perl doing the heavy lifting instead of Node.js.
177+
Perl Executing Browser (PEB) is an HTML5 user interface for Perl 5 desktop applications.
178+
It is a C++ Qt 5 application running local Perl 5 scripts as child processes without server.
179+
Inspired by Electron and NW.js, PEB is another reuse of web technologies in
180+
desktop applications with Perl doing the heavy lifting instead of Node.js.
184181
</div>
185182
</div>
186183

resources/app/index.html

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
<nav class="navbar navbar-default navbar-fixed-top">
8585
<div class="container">
8686
<div class="navbar-header">
87-
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
87+
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
88+
data-target="#navbar" aria-expanded="false" aria-controls="navbar">
8889
<span class="sr-only">Toggle navigation</span>
8990
<span class="icon-bar"></span>
9091
<span class="icon-bar"></span>
@@ -95,7 +96,10 @@
9596
<div id="navbar" class="navbar-collapse collapse">
9697
<ul class="nav navbar-nav">
9798
<li class="dropdown">
98-
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Tests<span class="caret"></span></a>
99+
<a href="#" class="dropdown-toggle" data-toggle="dropdown"
100+
role="button" aria-haspopup="true" aria-expanded="false">Tests
101+
<span class="caret"></span>
102+
</a>
99103
<ul class="dropdown-menu">
100104
<li>
101105
<a href="select_file.dialog">Open Existing File</a>
@@ -114,11 +118,11 @@
114118
</li>
115119

116120
<li>
117-
<a href="javascript:startPerlInfo();">Perl Basic Information</a>
121+
<a href="perl_info.script">Perl Basic Information</a>
118122
</li>
119123

120124
<li>
121-
<a href="javascript:startSqlite();">SQLite Test</a>
125+
<a href="sqlite.script">SQLite Test</a>
122126
</li>
123127

124128
<li>
@@ -133,17 +137,7 @@
133137

134138
<li><a href="https://www.google.com/">Google</a></li>
135139

136-
<li class="dropdown">
137-
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">About<span class="caret"></span></a>
138-
<ul class="dropdown-menu">
139-
<li>
140-
<a href="about-browser.function">About PEB</a>
141-
</li>
142-
143-
<li>
144-
<a href="about-qt.function">About Qt</a>
145-
</li>
146-
</li>
140+
<li><a href="about.function">About</a></li>
147141
</ul>
148142
</div>
149143
</div>
@@ -156,7 +150,10 @@ <h2>Perl Executing Browser</h2>
156150

157151
<div class="row">
158152
<div class="col-lg-12 introduction">
159-
Perl Executing Browser (PEB) is an HTML5 user interface for Perl 5 desktop applications. It is a C++ Qt 5 application running local Perl 5 scripts as child processes without server. Inspired by Electron and NW.js, PEB is another reuse of web technologies in desktop applications with Perl doing the heavy lifting instead of Node.js.
153+
Perl Executing Browser (PEB) is an HTML5 user interface for Perl 5 desktop applications.
154+
It is a C++ Qt 5 application running local Perl 5 scripts as child processes without server.
155+
Inspired by Electron and NW.js, PEB is another reuse of web technologies in
156+
desktop applications with Perl doing the heavy lifting instead of Node.js.
160157
</div>
161158
</div>
162159

resources/app/peb-demo.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ select_file.type = 'single-file';
3737
select_file.receiverFunction = function (fileName) {
3838
open_file.inputData = fileName;
3939
clearTestData();
40-
peb.startScript('open_file.script');
40+
41+
var form = document.createElement('form');
42+
form.setAttribute('action', 'open_file.script');
43+
document.body.appendChild(form);
44+
form.submit();
4145
}
4246

4347
var new_file_name = {};
@@ -54,23 +58,23 @@ select_files.type = 'multiple-files';
5458
select_files.receiverFunction = function (fileNames) {
5559
open_files.inputData = fileNames;
5660
clearTestData();
57-
peb.startScript('open_files.script');
61+
62+
var form = document.createElement('form');
63+
form.setAttribute('action', 'open_files.script');
64+
document.body.appendChild(form);
65+
form.submit();
5866
}
5967

6068
var select_directory = {};
6169
select_directory.type = 'directory';
6270
select_directory.receiverFunction = function (directoryName) {
6371
open_directory.inputData = directoryName;
6472
clearTestData();
65-
peb.startScript('open_directory.script');
66-
}
67-
68-
function startPerlInfo() {
69-
peb.startScript('perl_info.script');
70-
}
7173

72-
function startSqlite() {
73-
peb.startScript('sqlite.script');
74+
var form = document.createElement('form');
75+
form.setAttribute('action', 'open_directory.script');
76+
document.body.appendChild(form);
77+
form.submit();
7478
}
7579

7680
function clearTestData() {

resources/app/perl-scripts/interactive-windows.pl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
};
3030

3131
# Temporary file:
32-
my $tempfile_handle = File::Temp->new(UNLINK => 0);
32+
my $tempfile_handle = File::Temp->new();
33+
$tempfile_handle->unlink_on_destroy(1);
3334
my $tempfile = $tempfile_handle->filename;
3435

3536
# Set the event loop:
@@ -46,6 +47,7 @@
4647
open $tempfile_handle, '<', $tempfile;
4748
$data = <$tempfile_handle>;
4849
close $tempfile_handle;
50+
unlink $tempfile;
4951
} or do {
5052
1;
5153
}
@@ -95,11 +97,10 @@ sub get_input {
9597
return $input;
9698
}
9799

98-
# This function is called when PEB is closed by user or unexpectedly crashes and
100+
# This function is called when PEB unexpectedly crashes and
99101
# script loses its STDOUT stream.
100102
# It must not be named 'shutdown' -
101103
# this is a reserved name for a Perl prototype function!
102104
sub shutdown_procedure {
103-
unlink $tempfile;
104105
exit(0);
105106
}

resources/data/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This directory may contain writable files used or produced by a PEB-based application.
1+
This directory may contain data files used or produced by a PEB-based application.

src/resources/html/about.html

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
<html>
2-
<h3>About Perl Executing Browser</h3>
3-
Application version APPLICATION_VERSION<br>
4-
Qt version QT_VERSION<br><br>
5-
This program is free software;<br>
6-
you can redistribute it and/or modify it under<br>
7-
the terms of the
8-
GNU Lesser General Public License,<br>
9-
as published by the Free Software Foundation;<br>
10-
either version 3 of the License,<br>
11-
or (at your option) any later version.<br><br>
12-
This program is distributed<br>
13-
in the hope that it will be useful,<br>
14-
but WITHOUT ANY WARRANTY;<br>
15-
without even the implied warranty of<br>
16-
MERCHANTABILITY or<br>
17-
FITNESS FOR A PARTICULAR PURPOSE.<br><br>
18-
Dimitar D. Mitov, 2013 - 2019<br>
19-
Valcho Nedelchev, 2014 - 2016<br><br>
20-
<a href='https://github.com/ddmitov/perl-executing-browser'>
21-
github.com/ddmitov/perl-executing-browser</a><br>
2+
<h3>About Perl Executing Browser</h3>
3+
Application version APPLICATION_VERSION<br>
4+
Qt version QT_VERSION
5+
<br><br>
6+
This program is free software;<br>
7+
you can redistribute it and/or modify it under<br>
8+
the terms of the
9+
GNU Lesser General Public License,<br>
10+
as published by the Free Software Foundation;<br>
11+
either version 3 of the License,<br>
12+
or (at your option) any later version.<br><br>
13+
This program is distributed<br>
14+
in the hope that it will be useful,<br>
15+
but WITHOUT ANY WARRANTY;<br>
16+
without even the implied warranty of<br>
17+
MERCHANTABILITY or<br>
18+
FITNESS FOR A PARTICULAR PURPOSE.<br><br>
19+
Dimitar D. Mitov, 2013 - 2019<br>
20+
Valcho Nedelchev, 2014 - 2016
21+
<br><br>
22+
<a href='https://github.com/ddmitov/perl-executing-browser'>
23+
github.com/ddmitov/perl-executing-browser
24+
</a>
25+
<br>
2226
</html>

src/resources/peb.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ peb.getScriptSettings = function(scriptSettings) {
2525
}
2626
}
2727

28-
peb.startScript = function(scriptSettings) {
29-
var form = document.createElement('form');
30-
form.setAttribute('action', scriptSettings);
31-
document.body.appendChild(form);
32-
form.submit();
33-
}
34-
3528
peb.checkUserInputBeforeClose = function() {
3629
var textEntered = false;
3730
var close = true;

0 commit comments

Comments
 (0)