Is it possible for Perl 6 to work online?

  • A+

This is probably a naïve and even not a valid question...

I've made a Perl 6 program (and hope to make a couple others) which analizes local data taking into account some user-defined parameters. Several of my colleagues/coworkers need the output of the program on a regular basis, so they send me the parameters, I run the program and send them back the output. Since the whole process isn't very convenient, I'm thinking about what can be done to make things easier for everyone. Here are the options, and neither of them seems ideal.

  • Install Perl 6 on my colleagues' computers and teach them how to use it. Most of them don't have any programming experience, the data and the program itself should be kept up to date on all the computers, the program should work identically on different systems etc., so this will presumably make things worse, not better.
  • Make an online 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 much easier for the users (and I've already made such thing for a simpler program), but I would prefer to use Perl 6...

So, my question: is it possible to somehow make Perl 6 work online? Can it work in browser? Or is there any other solution?


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 running on a server as the "back-end".

(The other way is to transpile to JS. The rest of this paragraph is only for readers interested in experimental solutions. In theory you could transpile Perl 6 to JS via an experimental nqp backend. This is analogous to a more up to date version of Perlito. There's a backend specifically targeting JS and another fledgling experiment targeting Graal which can in turn target JS. I'm pretty sure these solutions will be very slow and introduce many other problems, at least 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 runs 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 run 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 running 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 run 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 running on your desktop, which responds by running 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 running 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

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.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: