Perl 6 可以联机工作吗?

Is it possible for Perl 6 to work online?

这可能是一个天真的问题,甚至不是一个有效的问题...

我已经制作了一个 Perl 6 程序(并希望制作其他几个),它在考虑一些用户定义的参数的情况下分析本地数据。我的几个 colleagues/coworkers 需要定期输出程序,所以他们将参数发送给我,我 运行 程序并将输出发送回他们。
由于整个过程不是很方便,所以我在考虑可以做些什么来让大家更轻松。以下是选项,但似乎都不理想。

那么,我的问题是:是否可以通过某种方式使 Perl 6 在线工作?它可以在浏览器中运行吗?或者还有其他解决办法吗?

既然你已经实现了一个你似乎很满意的程序,并且它已经用 Perl 6 编写,可能值得提供 Perlito a try (for reference, it is listed on the perl6.org compilers page)。

目标是使用 Perlito 将您的 Perl 6 源代码一次性翻译成 JavaScript,当然可以在浏览器中 运行。程序的后续维护将按以下顺序进行: (1) 更新 Perl 6 源代码; (2) 运行 Perlito 获取JavaScript源码; (3) 用新渲染的源代码替换旧的JavaScript源代码。

整个建议都是实验性的,我自己还没有做过,所以请三思而后行。

最后还有一个more detailed README(提到JavaScript-to-Perl-6)。

Install Perl 6 on my colleagues' computers ... this will presumably make things worse, not better.

Given your stated details for the ... I agree.

Make [a] variant of the program (using JS etc.), so that my colleagues can input the parameters and get the result in a browser window.

This is a natural choice imo.

(Note that I elided "online" in my quoting of your words. If your colleagues are able to see your computer via an internal network, then you can still do a JS/web solution but do one that's not public -- not online. Basically do the same solution but use slightly different server plumbing.)

An alternative would be to accept a structured email. More on that in the appropriate spot.

I would prefer to use Perl 6...

The most common way to use code from a language other than JS in a web solution is to still use html etc., quite often including JS, in the "front-end" of the solution and then include calls of code 运行ning on a server as the "back-end".

(The other way is to transpile to JS. In theory you could transpile Perl 6 to JS via an experimental nqp backend. I think this is an exciting development but I suspect it will be slow and limited in the near term.)

(One final point for this section. If instead you end up translating the Perl 6 to a JS solution because you don't want to learn or deal with having a server in the mix, then you'll have used Perl 6 as a prototyping language. This can be a legitimate way to use a language but the rest of this answer assumes you'll introduce a server.)

Introducing and managing a server

A server is a computer or software that reliably stays available and 运行s software on demand due to requests from "clients" (typically other computers).

That sounds simple, and in some ways it is, but in other ways it isn't. What if someone turns off the power? Or fails to pay the internet bill? Or the software leaks memory causing the system to periodically fail? Or a hacker attacks and gets in?

Unless those using the service can already see the server computer over a local network, and often even then, a modern approach to introducing a server into a solution is to purchase an online server package (typically one based on virtualization). (Think in terms of a few dollars a month and up.) Assuming a decent service provider, this effectively guarantees it'll be a well 运行 server that generally stays on, working, connected, and serving unless it's hacked or otherwise broken, and that you'll be informed in a timely fashion if the latter happens. The "zero cost" alternative is to make your desktop be a server too. That means you're responsible for keeping your desktop up and 运行ning and connected.

A modern approach to managing a server is to use Docker or similar on top of the server. This effectively guarantees you can near instantly fix a problem with a well 运行 server if it's hacked or otherwise broken. It also makes it easy to have a local server that you can develop and test on that's guaranteed to be identical to the deployed production server. Best of all perhaps, installing Docker on your desktop or using it on a purchased server and then dropping in an already prepared docker file means you can can go from never having used a server to having a working server in the time it takes you to click a few buttons.

There is a range of offerings out there that use both OS virtualization and docker or docker like technologies to create pay-for-use combinations where you only pay for the time the server is in use rather than for it being available 24/7. There are many ins-and-outs. Some don't support Perl 6. As far as I know Amazon AWS and Google Cloud both support pay-for-use and allow use of any programming language.

Building the web application

The final few sections of this answer cover how to use Perl 6 once you have a server in place, starting with the least sophisticated. Jump to the last section, on Cro, if you want to go straight to the solution I recommend if you go the web route.

Email client responder

Especially if you don't want to spend the money on a separate server, to simplify things a little, you could have your colleagues send a structured email to an email address that arrives at an email client you have 运行ning on your desktop, which responds by 运行ning the Perl 6 program on your desktop and then emails them back when the results are in. If you're interested in this solution, please post another SO asking about it.

The remaining sections assume a web solution instead.

CGI and hand-rolled code

Calling code 运行ning on a server from a web page is trivial.

You just write a suitable link to click on that points to a dynamic program rather than a static html page.

If you want to collect parameters, then you just write a form and a suitable submit button and do it that way.

Given an existing web page with a form already written you could learn how to pass parameters, call Perl 6 code, and display the results, in minutes, if you read an appropriate article such as How to generate webpages using CGI scripts.

Modules and Bailador

Imo it's not worth doing things at such a low level as hand-rolled CGI. There are dangers to doing so and there are modules that make things easier and less dangerous to create and maintain.

These will appear under "web" at modules.perl6.org.

Bailador is an obvious pick for a basic solution that does a decent job with "routes" (mapping URLs to code) and templates.

Cro and an SPA

If you are interested in using the most fundamentally natural approach to building modern web sites, I recommend using Cro. Cro makes it trivial to build simple web solutions using the SPA approach. But it's designed to use the features built in to Perl 6 to scale nicely to the most sophisticated web sites imaginable involving any mixture of asynchronous, concurrent, parallel, or distributed processing and any middleware you care to introduce.

A Cro SPA is possibly overkill for such a very trivial application as you suggest in your OP but it's still very simple and there are countless upsides to choosing it and no significant downsides imo for your application. (Even its official status as a beta product is fine for your scenario imo. It's already a very solid product, devs respond quickly to any issues raised, and it's of strategic importance to both those devs and indeed Perl 6 that it stays clean, fast, production worthy, and well maintained.)

The quickest way to get an entire setup going so you can start playing with Cro is probably to install Docker if you don't already have it on your server (or desktop if you're using that as your server) and then install the croservices/cro-http Docker container.

And the quickest way to learn how to use Cro for delivering a single web page is to follow the Building a Single Page Application with Cro tutorial.

一个不错的解决方案是您可以 运行 一个 Jupyter Notebook 服务器供他们使用 https://github.com/bduggan/p6-jupyter-kernel

或者另一个人将您的代码托管在 glot.io 上,这样他们就可以 运行 在浏览器中 https://glot.io/new/perl6

这些将是我的快速解决方案。如果程序非常简单并且在命令行上有 运行s,那么 JVM 版本的 Rajudo 可能会使用 --target=jar 将它打包到其他机器上的所有东西到 运行 Java 已安装。