Skip to content

Commit 1403a4d

Browse files
committed
console.debug for Perl errors
1 parent f8bd151 commit 1403a4d

File tree

6 files changed

+77
-67
lines changed

6 files changed

+77
-67
lines changed

doc/SETTINGS.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,15 @@ Each PEB interactive Perl script must have its own event loop waiting constantly
153153
A PEB interactive Perl script should have the following features:
154154

155155
* **No buffering**
156-
PEB interactive scripts should have ``$|=1;`` among their first lines to disable the built-in buffering of the Perl interpreter, which prevents any output before the script has ended.
156+
PEB interactive scripts should run with no output buffering preventing output before the script has ended.
157+
158+
Output buffering could be disabled using the following code:
159+
160+
```perl
161+
use English;
162+
163+
$OUTPUT_AUTOFLUSH = 1;
164+
```
157165

158166
* **Failsafe print**
159167
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.
Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,74 @@
2323
'Are you sure you want to close the application?';
2424

2525
// PEB settings objects for auto-started Perl interactive scripts:
26+
var messenger_one = {};
27+
messenger_one.scriptRelativePath = 'perl-scripts/messenger.pl';
28+
29+
messenger_one.message = {};
30+
messenger_one.inputData = function() {
31+
messenger_one.message.user_input =
32+
document.getElementById("interactive-one-input").value;
33+
$('#form-one').trigger('reset');
34+
return JSON.stringify(messenger_one.message);
35+
}
36+
37+
var messenger_two = {};
38+
messenger_two.scriptRelativePath = 'perl-scripts/messenger.pl';
39+
40+
messenger_two.message = {};
41+
messenger_two.inputData = function() {
42+
messenger_two.message.user_input =
43+
document.getElementById("interactive-two-input").value;
44+
$('#form-two').trigger('reset');
45+
return JSON.stringify(messenger_two.message);
46+
}
47+
2648
var interactive_one = {};
27-
interactive_one.scriptRelativePath = 'perl-scripts/interactive.pl';
49+
interactive_one.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
2850

2951
interactive_one.inputData = function() {
30-
var input = {}
52+
var input = {};
3153
input.mode = "unix-epoch";
32-
input.user_input = document.getElementById("interactive-one-input").value;
33-
$('#form-one').trigger('reset');
3454
return JSON.stringify(input);
3555
}
3656

3757
interactive_one.stdoutFunction = function (stdout) {
3858
var target = document.getElementById('instance-one-output');
3959
var output = JSON.parse(stdout);
4060
var html;
61+
messenger_one.message.tempfile = output.tempfile;
4162
if(("user_input" in output)) {
42-
html = output.time + '<br>' + output.user_input;
43-
} else {
44-
html = output.time;
63+
if (output.user_input != undefined) {
64+
html = output.time + '<br>' + output.user_input;
65+
} else {
66+
html = output.time;
67+
}
68+
target.innerHTML = html;
4569
};
46-
target.innerHTML = html;
4770
}
4871

4972
var interactive_two = {};
50-
interactive_two.scriptRelativePath = 'perl-scripts/interactive.pl';
73+
interactive_two.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
5174

5275
interactive_two.inputData = function() {
53-
var input = {}
76+
var input = {};
5477
input.mode = "local-time";
55-
input.user_input = document.getElementById("interactive-two-input").value;
56-
$('#form-one').trigger('reset');
5778
return JSON.stringify(input);
5879
}
5980

6081
interactive_two.stdoutFunction = function (stdout) {
6182
var target = document.getElementById('instance-two-output');
6283
var output = JSON.parse(stdout);
6384
var html;
85+
messenger_two.message.tempfile = output.tempfile;
6486
if(("user_input" in output)) {
65-
html = output.time + '<br>' + output.user_input;
66-
} else {
67-
html = output.time;
87+
if (output.user_input != undefined) {
88+
html = output.time + '<br>' + output.user_input;
89+
} else {
90+
html = output.time;
91+
}
92+
target.innerHTML = html;
6893
};
69-
target.innerHTML = html;
7094
}
7195
</script>
7296

@@ -164,7 +188,7 @@ <h3>Interactive Script Demo</h3>
164188

165189
<div class="row">
166190
<div class="col-xs-12 form-group">
167-
<form action="interactive_one.script" id="form-one">
191+
<form action="messenger_one.script" id="form-one">
168192
<div class="input-group">
169193
<input type="text" id="interactive-one-input" name="input" class="form-control"
170194
placeholder="Press Enter to send data to the first interactive script instance">
@@ -187,7 +211,7 @@ <h3>Interactive Script Demo</h3>
187211

188212
<div class="row">
189213
<div class="col-xs-12 form-group">
190-
<form action="interactive_two.script" id="form-two">
214+
<form action="messenger_two.script" id="form-two">
191215
<div class="input-group">
192216
<input type="text" id="interactive-two-input" name="input" class="form-control"
193217
placeholder="Press Enter to send data to the second interactive script instance">

resources/app/index.html

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,74 +23,50 @@
2323
'Are you sure you want to close the application?';
2424

2525
// PEB settings objects for auto-started Perl interactive scripts:
26-
var messenger_one = {};
27-
messenger_one.scriptRelativePath = 'perl-scripts/messenger.pl';
28-
29-
messenger_one.message = {};
30-
messenger_one.inputData = function() {
31-
messenger_one.message.user_input =
32-
document.getElementById("interactive-one-input").value;
33-
$('#form-one').trigger('reset');
34-
return JSON.stringify(messenger_one.message);
35-
}
36-
37-
var messenger_two = {};
38-
messenger_two.scriptRelativePath = 'perl-scripts/messenger.pl';
39-
40-
messenger_two.message = {};
41-
messenger_two.inputData = function() {
42-
messenger_two.message.user_input =
43-
document.getElementById("interactive-two-input").value;
44-
$('#form-two').trigger('reset');
45-
return JSON.stringify(messenger_two.message);
46-
}
47-
4826
var interactive_one = {};
49-
interactive_one.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
27+
interactive_one.scriptRelativePath = 'perl-scripts/interactive.pl';
5028

5129
interactive_one.inputData = function() {
52-
var input = {};
30+
var input = {}
5331
input.mode = "unix-epoch";
32+
input.user_input = document.getElementById("interactive-one-input").value;
33+
$('#form-one').trigger('reset');
5434
return JSON.stringify(input);
5535
}
5636

5737
interactive_one.stdoutFunction = function (stdout) {
5838
var target = document.getElementById('instance-one-output');
5939
var output = JSON.parse(stdout);
6040
var html;
61-
messenger_one.message.tempfile = output.tempfile;
6241
if(("user_input" in output)) {
63-
if (output.user_input != undefined) {
64-
html = output.time + '<br>' + output.user_input;
65-
} else {
66-
html = output.time;
67-
}
68-
target.innerHTML = html;
42+
html = output.time + '<br>' + output.user_input;
43+
} else {
44+
html = output.time;
6945
};
46+
target.innerHTML = html;
7047
}
7148

7249
var interactive_two = {};
73-
interactive_two.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
50+
interactive_two.scriptRelativePath = 'perl-scripts/interactive.pl';
7451

7552
interactive_two.inputData = function() {
76-
var input = {};
53+
var input = {}
7754
input.mode = "local-time";
55+
input.user_input = document.getElementById("interactive-two-input").value;
56+
$('#form-one').trigger('reset');
7857
return JSON.stringify(input);
7958
}
8059

8160
interactive_two.stdoutFunction = function (stdout) {
8261
var target = document.getElementById('instance-two-output');
8362
var output = JSON.parse(stdout);
8463
var html;
85-
messenger_two.message.tempfile = output.tempfile;
8664
if(("user_input" in output)) {
87-
if (output.user_input != undefined) {
88-
html = output.time + '<br>' + output.user_input;
89-
} else {
90-
html = output.time;
91-
}
92-
target.innerHTML = html;
65+
html = output.time + '<br>' + output.user_input;
66+
} else {
67+
html = output.time;
9368
};
69+
target.innerHTML = html;
9470
}
9571
</script>
9672

@@ -188,7 +164,7 @@ <h3>Interactive Script Demo</h3>
188164

189165
<div class="row">
190166
<div class="col-xs-12 form-group">
191-
<form action="messenger_one.script" id="form-one">
167+
<form action="interactive_one.script" id="form-one">
192168
<div class="input-group">
193169
<input type="text" id="interactive-one-input" name="input" class="form-control"
194170
placeholder="Press Enter to send data to the first interactive script instance">
@@ -211,7 +187,7 @@ <h3>Interactive Script Demo</h3>
211187

212188
<div class="row">
213189
<div class="col-xs-12 form-group">
214-
<form action="messenger_two.script" id="form-two">
190+
<form action="interactive_two.script" id="form-two">
215191
<div class="input-group">
216192
<input type="text" id="interactive-two-input" name="input" class="form-control"
217193
placeholder="Press Enter to send data to the second interactive script instance">

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
use warnings;
55
use POSIX qw(strftime);
66
use Encode qw(decode);
7+
use English;
78

89
use AnyEvent;
9-
use File::Temp qw(tempfile tempdir);
10+
use File::Temp;
1011
use JSON::PP;
1112

12-
# Disable built-in buffering:
13-
$| = 1;
13+
# Disable output buffering:
14+
$OUTPUT_AUTOFLUSH = 1;
1415

1516
# Global defaults:
1617
my $mode = "unix-epoch";

resources/app/perl-scripts/interactive.pl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
use warnings;
55
use POSIX qw(strftime);
66
use Encode qw(decode);
7+
use English;
78

89
use AnyEvent;
910
use JSON::PP;
1011

11-
# Disable built-in buffering:
12-
$| = 1;
12+
# Disable output buffering:
13+
$OUTPUT_AUTOFLUSH = 1;
1314

1415
# Defaults:
1516
my $mode = "unix-epoch";

src/webkit-page.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public slots:
320320
errors.replace("\r", "");
321321

322322
QString perlScriptErrorsMessage =
323-
"console.log('" + errors + "'); null";
323+
"console.debug('" + errors + "'); null";
324324

325325
mainFrame()->evaluateJavaScript(perlScriptErrorsMessage);
326326
}

0 commit comments

Comments
 (0)