From 1bab1732823d9e2fcd8126feed44a29e09109574 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Thu, 13 Sep 2018 10:20:52 +0200 Subject: [PATCH 01/29] Minor doc tweak --- using.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/using.md b/using.md index 7710a03..12f4918 100644 --- a/using.md +++ b/using.md @@ -368,7 +368,7 @@ This option was added in `v0.05-beta`. Enable this option at any time to get additional trace-level output to `console.debug()`. Defaults to `false`. -#### `Perl.addStateChangeListener` +#### `Perl.addStateChangeListener(function)` Pass this function a `function (from,to) {...}` to register a new handler for state changes of the Perl interpreter. From c3c0e842321970b09b51e88d8a6ed71214c75e2c Mon Sep 17 00:00:00 2001 From: Hauke D Date: Thu, 13 Sep 2018 10:54:25 +0200 Subject: [PATCH 02/29] Made import more flexible See fd678a6d9fc19437787de1f455e825d6720140d --- _misc/import_regex_tester.pl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/_misc/import_regex_tester.pl b/_misc/import_regex_tester.pl index 6b304e9..3b330a6 100755 --- a/_misc/import_regex_tester.pl +++ b/_misc/import_regex_tester.pl @@ -20,11 +20,11 @@ with the following differences: (see import_regex_tester.pl) ENDMSG -( $html =~ s{ <(?script\s+src="webperl\.js"\s*> }{}xms )==1 or die; -( $html =~ s{ }{<$+{x}>}xms )==1 or die; -( $html =~ s{ ^ \s* our \s+ \$RUN_CODE_IN_IFRAME\s*=\s*\K0(?=\s*;\s*) }{1}xms )==1 or die; -( $html =~ s{ https?://github.com/haukex/webperl/blob/\Kmaster/web/regex_tester.html }{gh-pages/regex.html}xms )==1 or die; -( $html =~ s{ \#\#\#\#\#\s*-->\n\K }{\n\n}xms )==1 or die; +( $html =~ s{ <(?script\s+src="(?:webperl\.js|__WEBPERLURL__)"\s*> }{}xmsg )==2 or die; +( $html =~ s{ }{<$+{x}>}xmsg )==2 or die; +( $html =~ s{ ^ \s* our \s+ \$RUN_CODE_IN_IFRAME\s*=\s*\K[01](?=\s*;\s*) }{1}xmsg )==1 or die; +( $html =~ s{ https?://github.com/haukex/webperl/blob/\Kmaster/web/regex_tester.html }{gh-pages/regex.html}xmsg )==1 or die; +( $html =~ s{ \#\#\#\#\#\s*-->\n\K }{\n\n}xmsg )==1 or die; open my $ofh, '>:encoding(UTF-8)', $outfn or die "$outfn: $!"; print $ofh $html; From dbbf9318f433d7aa00ae126f0f0c67dc5cff375e Mon Sep 17 00:00:00 2001 From: Hauke D Date: Sat, 22 Sep 2018 13:11:04 +0300 Subject: [PATCH 03/29] Updated documentation of "jscode" method --- using.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/using.md b/using.md index 12f4918..421ffeb 100644 --- a/using.md +++ b/using.md @@ -471,9 +471,11 @@ stored in a Perl scalar `$foo` pointing to a JavaScript object `foo`: regular Perl data structure (deep copy). Note that JavaScript functions are kept wrapped inside anonymous Perl `sub`s. - `jscode` returns a string of JavaScript code that represents a reference - to the JavaScript object. You should treat the string as an opaque value, - no guarantees are made about its format and whether it may change in future - releases. *Do not* call JavaScript's `delete` on this value. + to the JavaScript object. **Warning:** Treat this value as read-only in + JavaScript! *Do not* assign to this value, call JavaScript's `delete` on + this value, etc. (calling methods that may mutate the object is ok, though). + You should treat the string as an opaque value, no guarantees are made about + its format and whether it may change in future releases. This is an advanced function that should not normally be needed, unless you are building strings of JavaScript to run. In that case, you may need to wrap the value in parentheses for it to evaluate correctly in From 36beffa2fd79747a0fdb98783cd8b1d55eedb2a7 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Tue, 2 Oct 2018 14:29:53 +0300 Subject: [PATCH 04/29] Tiny typo fix --- using.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/using.md b/using.md index 421ffeb..bceff71 100644 --- a/using.md +++ b/using.md @@ -377,7 +377,7 @@ The states currently are: - `"Uninitialized"` - `Perl.init` has not been called yet. - `"Initializing"` - `Perl.init` is currently operating. -- `"Ready" - `Perl.init` is finished and `Perl.start` can be called. +- `"Ready"` - `Perl.init` is finished and `Perl.start` can be called. - `"Running"` - The Perl interpreter is running, `Perl.eval` and `Perl.end` may be called - `"Ended"` - The Perl interpreter has ended. You might receive several state change notifications for this state. From 774a56066a45e5151caf59253c41d169d601e050 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Sat, 6 Oct 2018 18:47:58 +0200 Subject: [PATCH 05/29] Updated notes --- notes.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/notes.md b/notes.md index d878a97..81a9893 100644 --- a/notes.md +++ b/notes.md @@ -36,6 +36,12 @@ TODOs - Add Perl.Util functions for making file uploads and downloads easier - Plus an example showing how to use it to run a "legacy" Perl script with inputs and output - Perhaps create a CPAN Bundle:: module or similar for `build.pl` deps? + - There is some potential for restructuring: + - `Perl.glue()` and `Perl.dispatch()` could go into `WebPerl.xs` (?) + - Parts of `webperl.js` could go into `common_preamble.js` or `WebPerl.xs`, + so that `emperl.js` is runnable on its own in a Web Worker (?) + (see notes in `perlrunner.html` / `e12f1aa25a000`) + - `nodeperl_dev_prerun.js` could probably be merged into that as well 3. See Also From 7c48cfdd282353b19895e0bb892b55acd12f13e1 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Wed, 10 Oct 2018 19:58:43 +0200 Subject: [PATCH 06/29] Copied "web/democode" from 'master' Only changes were to get webperl.js from CDN and rename "demo.html" to "index.html". --- democode/index.html | 166 ++++++++++++++ democode/perleditor.css | 83 +++++++ democode/perleditor.html | 470 +++++++++++++++++++++++++++++++++++++++ democode/perlrunner.html | 177 +++++++++++++++ 4 files changed, 896 insertions(+) create mode 100644 democode/index.html create mode 100644 democode/perleditor.css create mode 100644 democode/perleditor.html create mode 100644 democode/perlrunner.html diff --git a/democode/index.html b/democode/index.html new file mode 100644 index 0000000..bc3f95a --- /dev/null +++ b/democode/index.html @@ -0,0 +1,166 @@ + + + + +WebPerl Code Demo + + + + + + + + +

+This page demonstrates the embeddable +🕸️🐪 WebPerl +Code Demo Editor, which can be embedded using <iframe> elements, including +sandboxing. +The documentation is contained in the source of this page, please use +the "View Source" function of your browser to view it, or have a look at +the project sources on GitHub. +

+ + + + + +

This is a simple example of running a oneliner:

+ + + + + + +

This example includes several files:

+ + + + + + + + diff --git a/democode/perleditor.css b/democode/perleditor.css new file mode 100644 index 0000000..62f566c --- /dev/null +++ b/democode/perleditor.css @@ -0,0 +1,83 @@ + +body { + margin: 0.4em; +} +.text { + font-family: Calibri, Ubuntu, "Droid Sans", Tahoma, Arial, Helvetica, sans-serif; + font-size: 0.9em; +} +pre,textarea,code,.code,.filename,.CodeMirror { + font-family: Consolas, "Ubuntu Mono", "Droid Sans Mono", "Lucida Console", "Courier New", Courier, monospace; +} +pre { + margin: 0; +} +a { + text-decoration: none; +} + +.CodeMirror { + border: 1px solid lightgrey; + height: auto; +} +.CodeMirror-scroll { + max-height: 12em; +} + +.codewithfn { + margin-top: 0.4em; +} +.fnfuncs { + cursor: default; +} +.filename { + display: inline-block; + border: 0; + padding: 1px; + min-width: 1em; + cursor: auto; +} +.filefuncs { + display: inline-block; + padding-top: 2px; + position: absolute; + right: 0.2em; +} +.fakelink { + color: darkblue; + cursor: pointer; +} +.badfilename { + background-color: rgba(255,200,200,255); + /* also has a placeholder text */ + min-width: 10em; +} + +#perlctrl { + margin-top: 0.3em; +} + +#misctools { + display: inline-block; + border: 1px solid grey; + padding: 1px 0.8em 1px 0.5em; + margin-top: 0.5em; +} +#runnerstate { + margin-top: 0.2em; + margin-bottom: 0.3em; +} +#runnererrors { + background-color: rgba(255,200,200,255); + margin-top: 0.3em; + margin-bottom: 0.3em; + padding: 0.1em 0.2em; +} + +#inputhere, #outputhere { + text-align: right; +} + +#footer { + margin-top: 0.5em; +} diff --git a/democode/perleditor.html b/democode/perleditor.html new file mode 100644 index 0000000..9f7de49 --- /dev/null +++ b/democode/perleditor.html @@ -0,0 +1,470 @@ + + + + +WebPerl Perl Editor + + + + + + + + + + + + + + + + + +
+ + +
+ +
+ Loading... +
+ + + + + + + + + +
+ +
+ Tools +   + +   + Add Input File +   + Add Output File +   + Copy Frame URL +
+
+ + + + + + diff --git a/democode/perlrunner.html b/democode/perlrunner.html new file mode 100644 index 0000000..b92d3f7 --- /dev/null +++ b/democode/perlrunner.html @@ -0,0 +1,177 @@ + + + + +WebPerl Perl Runner + + + + + + + + + + + + + From 897f9e7f254ad95e98623338e56ac721d7fe7e6e Mon Sep 17 00:00:00 2001 From: Hauke D Date: Wed, 10 Oct 2018 20:03:56 +0200 Subject: [PATCH 07/29] Change the cached URLs back to original URLs I forgot that I was using "htmlrescache" in my local repository. --- democode/perleditor.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/democode/perleditor.html b/democode/perleditor.html index 9f7de49..aed7ffa 100644 --- a/democode/perleditor.html +++ b/democode/perleditor.html @@ -25,13 +25,13 @@ You should have received a copy of the licenses along with this program. If not, see http://perldoc.perl.org/index-licence.html ##### --> - - + + - - - + + + @@ -95,7 +97,9 @@ tag, for example using the "Copy Frame URL" link shown in the editor. Note that implementing an automatic resize of the IFrame to fit its contents is nontrivial when sandboxing is enabled, which is why a -fixed height is used below. +fixed height is used below. However, see for example +http://davidjbradshaw.github.io/iframe-resizer/ - examples of how +to use this are included in the source files here. --> @@ -105,6 +109,8 @@ document.getElementById('perl1').src = inputs: [ { fn:"in.txt", text:"Foo\nBar\nQuz" } ], cmdline: "perl -CSD -pe 's/[aeiou]/_/g' in.txt", } )); +// Example of how to use the Optional "IFrame Resizer": +iFrameResize({checkOrigin:false}, document.getElementById('perl1'));

This example includes several files:

@@ -160,6 +166,7 @@ document.getElementById('perl2').src = ], outputs: [ "vowels.txt" ], } )); +iFrameResize({checkOrigin:false}, document.getElementById('perl2')); diff --git a/democode/perleditor.html b/democode/perleditor.html index 364468b..6ef528a 100644 --- a/democode/perleditor.html +++ b/democode/perleditor.html @@ -29,6 +29,8 @@ If not, see http://perldoc.perl.org/index-licence.html + + @@ -148,6 +150,7 @@ window.addEventListener('message', function (event) { $('#runnererrors').show(); $('#runnererrors>pre').append(data.perlRunnerError+"\n"); } + else if (data.substring(0,13)=="[iFrameSizer]") {} // ignore quietly else console.warn("Perl Editor ignoring unknown message:",data); }); From 40cb4cee9e6d91d0717d060e0b3606ff7693a4ab Mon Sep 17 00:00:00 2001 From: Hauke D Date: Thu, 11 Oct 2018 16:28:43 +0200 Subject: [PATCH 14/29] Added reference to documentation --- democode/perleditor.html | 2 ++ democode/perlrunner.html | 2 ++ 2 files changed, 4 insertions(+) diff --git a/democode/perleditor.html b/democode/perleditor.html index 6ef528a..5303c11 100644 --- a/democode/perleditor.html +++ b/democode/perleditor.html @@ -25,6 +25,8 @@ You should have received a copy of the licenses along with this program. If not, see http://perldoc.perl.org/index-licence.html ##### --> + + diff --git a/democode/perlrunner.html b/democode/perlrunner.html index b92d3f7..00532be 100644 --- a/democode/perlrunner.html +++ b/democode/perlrunner.html @@ -25,6 +25,8 @@ You should have received a copy of the licenses along with this program. If not, see http://perldoc.perl.org/index-licence.html ##### --> + +   http://webperl.zero-g.net/ From 989dc45cb0ece50aa36810d10b6d70df12ede480 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Fri, 12 Oct 2018 15:05:13 +0200 Subject: [PATCH 16/29] Added "Copy JSON" function from 287e449c5ef088a7fdd86d67bca9a25c589f6962 --- democode/perleditor.html | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/democode/perleditor.html b/democode/perleditor.html index 5fa27e1..b2e0761 100644 --- a/democode/perleditor.html +++ b/democode/perleditor.html @@ -309,6 +309,15 @@ function getFileData () { return filedata; } +function copyit (what) { + var pageurl = $('#pageurl'); + pageurl.val(what); + pageurl.show(); + pageurl[0].select(); + document.execCommand("copy"); + pageurl.hide(); +} + $(function () { var hashdata = window.location.hash.substr(1); @@ -407,18 +416,18 @@ $(function () { perlRunner.postMessage({ runPerl: rp_data }, '*'); }); - // "copy frame url" function + // "copy url / json" function $('#copyurl').click(function () { - var pageurl = $('#pageurl'); var data = getFileData(); data.cmdline = $('#argv').val(); var loc = new URL(window.location); loc.hash = encodeURIComponent(JSON.stringify(data)); - pageurl.val(loc); - pageurl.show(); - pageurl[0].select(); - document.execCommand("copy"); - pageurl.hide(); + copyit(loc); + }); + $('#copyjson').click(function () { + var data = getFileData(); + data.cmdline = $('#argv').val(); + copyit(JSON.stringify(data, null, "\t")); }); // start looking for the Perl runner @@ -469,7 +478,8 @@ $(function () {   Add Output File   - Copy Frame URL + Copy URL + / JSON From 9937eee58f0ffc562bb96443ae28e5664d740e2f Mon Sep 17 00:00:00 2001 From: Hauke D Date: Thu, 18 Oct 2018 14:31:19 +0200 Subject: [PATCH 17/29] Added a note to the build docs --- building.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/building.md b/building.md index dc7c8e5..82b0d2c 100644 --- a/building.md +++ b/building.md @@ -157,6 +157,9 @@ so for example `Cpanel/JSON/XS` instead of `Cpanel::JSON::XS` Note that the build script does **not** automatically fetch modules' dependencies, for now you will need to resolve them and add them to `EMPERL_EXTENSIONS` yourself. (This may be improved upon in the future.) +You can try out the script +[`experiments/depend.pl`](https://github.com/haukex/webperl/blob/master/experiments/depend.pl), +which uses the MetaCPAN API to resolve dependencies. *** From 978143858246e12df1f29b8a363993990b617c31 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Fri, 19 Oct 2018 14:56:01 +0200 Subject: [PATCH 18/29] Added some links to building.md --- building.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/building.md b/building.md index 82b0d2c..a40c3f8 100644 --- a/building.md +++ b/building.md @@ -48,6 +48,15 @@ The source code is in two repositories: You only need to check out the first of the two, the `emperl5` repository is checked out by the build script. +Some of the central source files of WebPerl are: + +- [`webperl/build/build.pl`](https://github.com/haukex/webperl/blob/master/build/build.pl) +- [`emperl5/hints/emscripten.sh`](https://github.com/haukex/emperl5/blob/emperl_v5.28.0/hints/emscripten.sh) +- [`emperl5/perlmain_noexit_patch`](https://github.com/haukex/emperl5/blob/emperl_v5.28.0/perlmain_noexit_patch) +- [`emperl5/ext/WebPerl/WebPerl.xs`](https://github.com/haukex/emperl5/blob/emperl_v5.28.0/ext/WebPerl/WebPerl.xs) +- [`emperl5/ext/WebPerl/WebPerl.pm`](https://github.com/haukex/emperl5/blob/emperl_v5.28.0/ext/WebPerl/WebPerl.pm) +- [`webperl/web/webperl.js`](https://github.com/haukex/webperl/blob/master/web/webperl.js) + Running the Build ----------------- From 887ba059c246885d60aa64acf0c3f53917e79377 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Fri, 19 Oct 2018 15:26:10 +0200 Subject: [PATCH 19/29] Added a link to notes --- notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/notes.md b/notes.md index 55c6f8e..44d4f5f 100644 --- a/notes.md +++ b/notes.md @@ -55,6 +55,7 @@ TODOs so that `emperl.js` is runnable on its own in a Web Worker (?) (see notes in `perlrunner.html` / `e12f1aa25a000`) - `nodeperl_dev_prerun.js` could probably be merged into that as well + - Regarding the funky syntax highlighting on GitHub: 3. See Also From 4bf870b776db0c9671eef71de15cb9dac74dcb91 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Fri, 19 Oct 2018 17:27:36 +0200 Subject: [PATCH 20/29] Added a sentence on the virtual FS --- using.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/using.md b/using.md index bceff71..1cb3f23 100644 --- a/using.md +++ b/using.md @@ -219,6 +219,8 @@ after having passed them to JavaScript, as that will probably cause mysterious b Emscripten provides a virtual file system that also provides a few "fake" files such as `/home/web_user`, `/dev`, and others, so that it resembles a normal *NIX file system. +This filesystem resides entirely in memory in the browser. + Perl's libraries (`*.pm`) are installed into this virtual file system at `/opt/perl`. Note that because the `perl` binary is compiled to WebAssembly and XS libraries are statically linked into it, you won't find any `perl` binary or shared library files in the From 2e57c3c7878201e51f0312f9230228505cad24b7 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Fri, 19 Oct 2018 19:12:03 +0200 Subject: [PATCH 21/29] Added "argv", "autorun" and "merge STDOUT+ERR" A squash of commits: - 1381ced6fe862d6b6bc2f532c3720de08a86092a Allow passing in argv array instead of cmdline - 3d90c22fe7951a68e38fa1de59a4d9f3bf63d7a1 Added "autorun" option - d856a1b81760e4466ac029f9aaf123b2cdd5d0a7 Made "merge STDOUT+ERR" option conf'able in editor --- democode/index.html | 38 +++++++++++++++-- democode/perleditor.html | 88 ++++++++++++++++++++++++++++++++-------- 2 files changed, 105 insertions(+), 21 deletions(-) diff --git a/democode/index.html b/democode/index.html index 3f77aee..f8f5133 100644 --- a/democode/index.html +++ b/democode/index.html @@ -118,7 +118,28 @@ iFrameResize({checkOrigin:false}, document.getElementById('perl1')); diff --git a/democode/perleditor.html b/democode/perleditor.html index b2e0761..438848e 100644 --- a/democode/perleditor.html +++ b/democode/perleditor.html @@ -39,11 +39,12 @@ If not, see http://perldoc.perl.org/index-licence.html