Skip to content

Commit 5767105

Browse files
committed
only JavaScript functions as STDOUT receivers
1 parent f274f4d commit 5767105

File tree

15 files changed

+134
-149
lines changed

15 files changed

+134
-149
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ A minimal example of a Perl script settings object:
149149
```javascript
150150
var perlScriptObject = {};
151151
perlScriptObject.path = '{app}/perl/test.pl';
152-
perlScriptObject.stdout = 'test';
152+
perlScriptObject.stdout = function (stdout) {
153+
var container = document.getElementById('tests');
154+
container.innerHTML = stdout;
155+
}
153156
```
154157

155158
* ``path``
@@ -158,7 +161,7 @@ perlScriptObject.stdout = 'test';
158161
*This object property is mandatory.*
159162

160163
* ``stdout``
161-
The ``stdout`` object property must be an id of a valid HTML DOM element or the name of a JavaScript function. Every piece of script output is immediately inserted into the DOM element or passed to the JavaScript function as its only argument.
164+
The ``stdout`` object property must be a JavaScript function. Every piece of script output is passed to this function as its only argument.
162165
*This object property is mandatory.*
163166

164167
* ``requestMethod``
@@ -192,7 +195,7 @@ perlScriptObject.stdout = 'test';
192195
The ``close_command`` object property designates the command used to gracefully shut down an interactive script when the containing PEB window is going to be closed. Upon receiving it, the interactive script must start its shutdown procedure.
193196

194197
* ``close_confirmation``
195-
Just before exiting an interactive script must print on STDOUT its ``close_confirmation`` to signal PEB that it completed its shutdown. All interactive scripts must exit in 5 seconds after ``close_command`` is given or any unresponsive scripts will be killed and PEB will exit.
198+
Just before exiting an interactive script must print on STDOUT its ``close_confirmation`` to signal PEB that it completed its shutdown. All interactive scripts must exit in 3 seconds after ``close_command`` is given or any unresponsive scripts will be killed and PEB will exit.
196199

197200
Perl scripts running for a long time should have ``$|=1;`` among their first lines to disable the built-in buffering of the Perl interpreter. Some builds of Perl may not give any output until the script is finished when buffering is enabled.
198201

@@ -239,7 +242,7 @@ The following code shows how to start an interactive Perl script right after a l
239242
The ``index.htm`` file of the demo package demonstrates how to start one script in two instances immediately after a page is loaded.
240243

241244
## Selecting Files and Folders
242-
Selecting files or folders with their full paths is performed by clicking a link to a pseudo filename composed from the name of the JavaScript object with the settings of the wanted dialog and a ``.dialog`` extension. Selected files or folders are seamlessly inserted in any local page using the ``target`` object property. ``target`` must be an id of a valid HTML DOM element or the name of a JavaScript function which receives all selected files or folders as its only argument.
245+
Selecting files or folders with their full paths is performed by clicking a link to a pseudo filename composed from the name of the JavaScript object with the settings of the wanted dialog and a ``.dialog`` extension. Selected files or folders are seamlessly inserted in any local page using the ``target`` object property. ``target`` must be a JavaScript function which receives all selected files or folders as its only argument.
243246

244247
```html
245248
<a href="select_file.dialog">Select existing file</a>
@@ -250,8 +253,10 @@ var select_file = {};
250253
// Type of the dialog, one of the following:
251254
// 'single-file', 'multiple-files', 'new-file-name' or 'directory'.
252255
select_file.type = 'single-file';
253-
// Unique DOM element or JavaScript function:
254-
select_file.target = 'tests';
256+
select_file.target = function (stdout) {
257+
var container = document.getElementById('tests');
258+
container.innerHTML = stdout;
259+
}
255260
```
256261

257262
* The actual opening of any existing file is performed by a Perl script and not by PEB.

resources/app/index.html

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
// Settings objects for the Perl scripts:
2727
var interactive_one = {};
2828
interactive_one.path = '{app}/perl/interactive.pl';
29-
interactive_one.stdout = 'instance-one-output';
29+
interactive_one.stdout = function (stdout) {
30+
var target = document.getElementById('instance-one-output');
31+
target.innerHTML = stdout;
32+
}
3033
interactive_one.requestMethod = 'POST';
3134
interactive_one.closeCommand = '_close_';
3235
interactive_one.closeConfirmation = '_closed_';
@@ -38,7 +41,10 @@
3841

3942
var interactive_two = {};
4043
interactive_two.path = '{app}/perl/interactive.pl';
41-
interactive_two.stdout = 'instance-two-output';
44+
interactive_two.stdout = function (stdout) {
45+
var target = document.getElementById('instance-two-output');
46+
target.innerHTML = stdout;
47+
}
4248
interactive_two.requestMethod = 'POST';
4349
interactive_two.closeCommand = '_close_';
4450
interactive_two.closeConfirmation = '_closed_';
@@ -51,33 +57,42 @@
5157
var get_test = {};
5258
get_test.path = '{app}/perl/get-post-test.pl';
5359
get_test.stdout = 'tests';
60+
get_test.stdout = function (stdout) {
61+
displayTestResult(stdout);
62+
}
5463
get_test.requestMethod = 'GET';
5564
get_test.inputData = 'name=Mickey&species=mouse';
5665

5766
var post_test = {};
5867
post_test.path = '{app}/perl/get-post-test.pl';
59-
post_test.stdout = 'tests';
68+
post_test.stdout = function (stdout) {
69+
displayTestResult(stdout);
70+
}
6071
post_test.requestMethod = 'POST';
6172
post_test.inputData = 'name=Geoffrey&species=giraffe';
6273

6374
var perl_info = {};
6475
perl_info.path = '{app}/perl/perl-info.pl';
65-
perl_info.stdout = 'tests';
76+
perl_info.stdout = function (stdout) {
77+
displayTestResult(stdout);
78+
}
6679

6780
var extensionless = {};
6881
extensionless.path = '{app}/perl/extensionless';
69-
extensionless.stdout = 'tests';
82+
extensionless.stdout = function (stdout) {
83+
displayTestResult(stdout);
84+
}
7085

7186
var sqlite = {};
7287
sqlite.path = '{app}/perl/sqlite.pl';
73-
sqlite.stdout = 'tests';
88+
sqlite.stdout = function (stdout) {
89+
displayTestResult(stdout);
90+
}
7491

7592
// Filesystem dilog boxes configuration objects:
7693
var select_file = {};
7794
select_file.type = 'single-file';
78-
select_file.target = 'insertFileName';
79-
80-
function insertFileName(fileName) {
95+
select_file.target = function (fileName) {
8196
clearTargetElement();
8297
var pre = document.createElement("pre");
8398
pre.innerHTML = 'Selected existing file: ' + fileName;
@@ -86,9 +101,7 @@
86101

87102
var new_file_name = {};
88103
new_file_name.type = 'new-file-name';
89-
new_file_name.target = 'insertNewFileName';
90-
91-
function insertNewFileName(fileName) {
104+
new_file_name.target = function (fileName) {
92105
clearTargetElement();
93106
var pre = document.createElement("pre");
94107
pre.innerHTML = 'Selected new file name: ' + fileName;
@@ -97,9 +110,7 @@
97110

98111
var select_files = {};
99112
select_files.type = 'multiple-files';
100-
select_files.target = 'insertFileNames';
101-
102-
function insertFileNames(fileNames) {
113+
select_files.target = function (fileNames) {
103114
clearTargetElement();
104115
var pre = document.createElement("pre");
105116
fileNames = fileNames.replace(/;/g, "<br>");
@@ -109,9 +120,7 @@
109120

110121
var select_directory = {};
111122
select_directory.type = 'directory';
112-
select_directory.target = 'insertDirectoryName';
113-
114-
function insertDirectoryName(directoryName) {
123+
select_directory.target = function (directoryName) {
115124
clearTargetElement();
116125
var pre = document.createElement("pre");
117126
pre.innerHTML = 'Selected directory: ' + directoryName;
@@ -124,6 +133,13 @@
124133
container.removeChild(container.firstChild);
125134
}
126135
}
136+
137+
function displayTestResult(stdout) {
138+
clearTargetElement();
139+
var pre = document.createElement("pre");
140+
pre.innerHTML = stdout;
141+
document.getElementById('tests').appendChild(pre);
142+
}
127143
</script>
128144

129145
<script src="jquery/jquery-1.12.4.min.js"></script>

resources/app/perl/extensionless

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
use strict;
44
use warnings;
55

6-
print "<pre>Hello from a Perl script without a filename extension!</pre>";
6+
print "Hello from a Perl script without a filename extension!";

resources/app/perl/get-post-test.pl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
}
1717
}
1818

19-
print "<pre>";
2019
print "REQUEST_METHOD: $ENV{'REQUEST_METHOD'}<br>";
2120

2221
# Split information into name/value pairs:
@@ -27,5 +26,3 @@
2726
$value =~ s/%(..)/pack("C", hex($1))/eg;
2827
print "$name = $value<br>";
2928
}
30-
31-
print "</pre>";

resources/app/perl/open-directory.pl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818

1919
traverse ($directory_name);
2020

21-
print "<pre>Listing all files in the $directory_name directory:<br>";
21+
print "Listing all files in the $directory_name directory:<br>";
2222
foreach my $file (@files) {
2323
print "$file<br>";
2424
}
25-
print "</pre>";
2625

2726
sub traverse {
2827
my ($entry) = @_;

resources/app/perl/open-file.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
my $number_of_lines = scalar(@file_contents);
1414

15-
print "<pre>Opening single file: $filename Lines: $number_of_lines</pre>";
15+
print "Opening single file: $filename Lines: $number_of_lines";

resources/app/perl/open-files.pl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
my $number_of_lines;
1111

12-
print "<pre>";
1312
print "Opening multiple files:<br>";
1413

1514
foreach my $file (@files) {
@@ -20,5 +19,3 @@
2019
my $number_of_lines = scalar(@file_contents);
2120
print "File: $file Lines: $number_of_lines<br>";
2221
}
23-
24-
print "</pre>";

resources/app/perl/perl-info.pl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66

77
my $cwd = cwd();
88

9-
print "<pre>";
10-
119
print "Perl $^V<br>";
1210
print "Working Directory: $cwd<br><br>";
1311

1412
print "\@INC Array:<br>";
1513
print join "<br>", @INC;
16-
17-
print "</pre>";

resources/app/perl/sqlite.pl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,11 @@
3434

3535
$all_records = $db->selectall_arrayref ("SELECT * FROM USER");
3636

37-
print "<pre>";
3837
print "SQLite Test:<br>";
3938

4039
foreach my $row (@$all_records) {
4140
my ($id, $name, $surname) = @$row;
4241
print "$id $name $surname<br>";
4342
}
4443

45-
print "</pre>";
46-
4744
$db->disconnect;

src/resources/html/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h3>About Perl Executing Browser</h3>
1010
either version 3 of the License,<br>
1111
or (at your option) any later version.<br><br>
1212
This program is distributed<br>
13-
in the hopethat it will be useful,<br>
13+
in the hope that it will be useful,<br>
1414
but WITHOUT ANY WARRANTY;<br>
1515
without even the implied warranty of<br>
1616
MERCHANTABILITY or<br>

0 commit comments

Comments
 (0)