"use strict"; /** ***** WebPerl - http://webperl.zero-g.net ***** * * Copyright (c) 2018 Hauke Daempfling (haukex@zero-g.net) * at the Leibniz Institute of Freshwater Ecology and Inland Fisheries (IGB), * Berlin, Germany, http://www.igb-berlin.de * * This program is free software; you can redistribute it and/or modify * it under the same terms as Perl 5 itself: either the GNU General Public * License as published by the Free Software Foundation (either version 1, * or, at your option, any later version), or the "Artistic License" which * comes with Perl 5. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the licenses for details. * * You should have received a copy of the licenses along with this program. * If not, see http://perldoc.perl.org/index-licence.html **/ /* -- Please see the documentation at http://webperl.zero-g.net/using.html -- */ var Module; var Perl = { trace: false, // user may enable this endAfterMain: false, // user may enable this (before Perl.init) // internal variables: initStepsLeft: 2, // Must match number of Perl.initStepFinished() calls! state: "Uninitialized", readyCallback: null, stdout_buf: "", stderr_buf: "", // for our default Perl.output implementation }; /* TODO: Embedded script should be able to influence the running of Perl, * the cleanest would probably be to set properties on the Perl object, * such as Perl.autorun = false or Perl.argv = [...]. */ window.addEventListener("load", function () { // Note: to get the content of script tags with jQuery: $('script[type="text/perl"]').html() var scripts = []; var script_src; document.querySelectorAll("script[type='text/perl']") .forEach(function (el) { if (el.src) { if (script_src || scripts.length) console.error('Only a single Perl script may be loaded via "script src=", ignoring others'); else script_src = el.src; } else { if (script_src) console.error('Only a single Perl script may be loaded via "script src=", ignoring others'); else scripts.push(el.innerHTML); } }); if (script_src) { console.debug("Perl: Found a script with src, fetching and running...", script_src); var xhr = new XMLHttpRequest(); xhr.addEventListener("load", function () { //TODO Later: Might be nice to name the script in the virtual FS after the URL instead of a generic name Perl._saveAndRun( this.responseText ); }); xhr.open("GET", script_src); xhr.send(); } else if (scripts.length) { console.debug("Perl: Found",scripts.length,"embedded script(s), autorunning..."); var code = scripts.join(";\n"); // get the first five lines of code var n = 5 + 1; // the contents of the