Actually Portable Perl
computoid.com
computoid.com
Differences:
* Actually Portable Perl runs on more operating systems, StaticPerl runs on Linux i386 (requiring i686 or newer processor), Linux amd64 and FreeBSD with Linux emulation.
* Actually Portable Perl has more of the standard Perl modules and C extensions bundled. StaticPerl contains only a few modules, simplified, with documentation and non-Linux support removed. StaticPerl is unlikely to work with existing Perl scripts with many use calls, but it is useful to write new Perl scripts from scratch, and these scripts will work with both StaticPerl and regular Perl.
* Actually Portable Perl executable programs are larger (5 MB minimum, StaticPerl is ~1 MB) because they are compiled for amd64 rather than i386, and they contain more Perl and C code.
* The first time an Actually Portable Perl executable program is run, it modifies a few bytes at the beginning of the program file (except on Windows). Thus these programs don't work on read-only filesystems unless they have been run on a read-write filesystem first. StaticPerl doesn't have this limitation.
There is a kernel patch to add APE (Actually Portable Executable) support to Linux removing the need for the the apeloader or assimilating. I'm not sure what the status is on that.
I'm thinking of serving content on 127.0.0.2. There is no need for a high performance server like nginx, but serving files and having some CGI capability would be a plus.
I'd be interested in suggestions for the HTTP server part and maybe an example for how do serve an index.pl file that reads payload files packaged in the APPerl binary (ex: .js, .jpg)
Then, I would create a custom build of APPerl using Perl::Dist::APPerl 's apperlm and modifying the apperl-project.json to pack in the script, CPAN modules, cgi files, and the static resources into a APPerl binary. When bundled into APPerl, the script can read the files embedded in APPerl from the /zip path.
Perl::Dist::APPerl (with tutorial on building apps): https://metacpan.org/pod/Perl::Dist::APPerl
MHFS's APPerl packaging config: https://github.com/G4Vi/MHFS/blob/master/apperl/apperl-proje...
Same. I know about HTTP::Daemon, HTTP::Tiny and HTTP::Server::Simple
If you have tried one of the 3 and can confirm it works with APPerl, it might save time?
If not, first with HTTP::Daemon (since it shows how to bind to a given IP in https://gist.github.com/mikkun/6388508, unlike HTTP::Tiny) I will try to release something similar to redbean but based on perl and DBD::SQLite
> When bundled into APPerl, the script can read the files embedded in APPerl from the /zip path.
That much I knew, but I was afraid there might be extra things needed
> MHFS's APPerl packaging config: https://github.com/G4Vi/MHFS/blob/master/apperl/apperl-proje...
Thank you! Then I might go with MHFS at first (tweaking its index.pl), if only because it's been tested by you with APPerl :)
I haven't tested any. Pure Perl servers should be the easiest to get working. The Cosmopolitan Libc doesn't support fcntl F_SETFL O_NONBLOCK on Windows yet, and so non-blocking / event loop servers may be a no-go for now.
> I will try to release something similar to redbean but based on perl and DBD::SQLite
I'd like to see this.
> Then I might go with MHFS at first
I wouldn't consider MHFS's HTTP server "production ready" and suffers from the above mentioned O_NONBLOCK issue, but I'm curious how it would go.
If you haven't already, feel free to join the Redbean/Cosmopolitan Libc discord to discuss. (There's a link on the APPerl webpage).
I used your perl.com as an input. Fake positive? Or have you been infected?
Also, even if I cpan install the modules and have:
"perl_repo_files" : {"cpan" : [
"HTML-Template",
"URI",
"Class-Inspector",
"HTTP-Daemon",
"HTTP-Status",
"IPC-Open2"
}
I get:C:\test> .\test.com Can't locate HTTP/Daemon.pm in @INC (you may need to install the HTTP::Daemon module) (@INC contains: . /zip/lib/perl5/site_perl/5.36.0/x86_64-cosmo /zip/lib/perl5/site_perl/5.36.0 /zip/lib/perl5/5.36.0/x86_64-cosmo /zip/lib/perl5/5.36.0) at /zip/bin/test line 9. BEGIN failed--compilation aborted at /zip/bin/test line 9.
Do I need to use https://github.com/G4Vi/MHFS/blob/master/apperl/download_pac... or something else to put the dependencies pm files in the zip?
apperlm does not download perl module dependencies right now, but download_package.pl can be used to download dependencies. apperlm mostly just acts as a glorified front-end to Info-ZIP when doing a build of a "nobuild" config (building off of existing apperl)
download_package.pl example https://github.com/G4Vi/MHFS/blob/6db6ad24886ca0ea335a050228...
Edit: You can see what files were packed into it by renaming with .zip extension and opening with Windows Explorer.
Edit 2: "perl_repo_files" just specifies where to copy files to inside of the perl source tree. It is only used if you are building APPerl from source (it is unused if you are building a "nobuild" config). IPC-Open2 should already be bundled in the full perl.com as it's included in the perl5 repo: https://github.com/G4Vi/perl5/tree/cosmo-apperl/ext/IPC-Open...
I'll see if I can have something akin to redbean ready this weekend.
https://www.oreilly.com/library/view/learning-perl-6/9781491...
Wrong. Perlers still cheer for it.
But for some reasons it hasn't wide spread adoption yet. We hope to use it some day in production.
When I was first learning to program and picked up Perl 5 (I was interested in Web programming, so... that was the thing to learn at the time) and then later read some books (yes, kids, we used to read books) on Java and C++, I wondered how the hell anyone could make sense of them. And hacking up early Javascript snippets (you know, for image rollovers, the only thing anyone used it for for the first few years) was so painful. It's just words! There's nothing to indicate what anything is! The examples in the books were so hard to read.
The answer, of course, was "they use syntax highlighting", but I'd not made that discovery yet.
Lol, you find bash readable? With all its weird ad-hoc constructs? I don’t pretend Perl looks pretty but at least its constructs seem to be consciously designed and do not look bolted on.
At my work place we still maintain a huge web application written in Perl 5. Most of the time if we are in trouble it‘s due to bad architectural designs that are not specific to Perl as a language or ecosystem. Only rarely I stumble over issues like implicit returns, or context sensitive sub routines. Also I hate Perl 5 allowing circular includes. The worst offenders among in-house modules are Perl modules written in a Java-esque style which mostly would have benefitted well from using native Perl features instead of trying to mimick Java programs.
When I arrived I tried to move as much of the front end logic to JS but the backend remained in Perl as most business logic still lives there (and not in the DB). These days we try to implement new features in separate JS or TypeScript services and SPAs that, however, communicate with our REST API that is implemented in Perl/Mojolicious. This way we can hire cheaper JS devs (that never learned Perl) and people can still enjoy React and modern frameworks if they so wish. The most talented ones I try to sucker into little refactoring projects in Perl. Most JS developers that tried got fluent in Perl 5 only after a couple of weeks.
In the future we will try to move more business logic of the "Kernel" into the DB system since Postgres grew much more powerful compared to the time back when the application was invented. I believe this will be our only hope to actually shrink our Perl 5 code base eventually.
What about develop time? how long does it take to deploy a feature?
Ah, how times change.
Perl was the original practical back-end development language for the web. There's a bit of opinion in that, but not a lot; there's not a lot of other contenders, unless you count writing raw C CGI programs which was never that popular.
Perl performance isn't great, but then I don't consider TS/JS performance all that good either. Perl is a cut below JS nowadays because of the JIT that JS has but it's not impractically slow. If it wasn't impractically slow in literally the late 1990s, when it was powering nearly every dynamic site that existed, it sure isn't today.
Go look up some real-world-(ish) performance benchmarks for various web frameworks if you want a real surprise. You might find it'd be hard to sell any scripting language other than PHP(!!!) for a project, if performance actually matters and for some reason you can't use a compiled language. Don't assume the new thing is better, or faster, even if that's its reputation. It may not be entirely earned.
> Lol, you find bash readable?
Note, they didn't say it was readable, just more readable.
Compared to that, bash is really anemic.
Python took Perl's money a bit when it came to scripting, Ruby – clearly influenced a lot by Perl – made big grounds in web apps, once they outgrew CGIs, and of course then we collectively got Javascript Stockholm syndrome.
But seriously, they're all good dogs. We all revel in the Narcicissm of Small Differences, but in the end it wouldn't really matter if we used Perl instead of Python or any other algol-ish imperative OO language with some functional bits.
It's linked from the page, but thought I'd point out if you're curious what went into making APPerl, check out the blogpost (self-plug): https://computoid.com/posts/Perl-is-Actually-Portable.html
Unix and Windows in the same binary?? Sacrilege! Haven't we still laws against witchcraft?
But the fact is: it gets shit done. It’s pretty good at dealing with strings and byte sequences, and even more importantly, it’s always fucking installed,
The “best” software helps you nothing if you’re machine isn’t running it.
Ugh. Close to half the bugs I’ve chased in Perl in the last 10 years are encode/decode string bugs (or more specifically, the lack of doing encode/decode where necessary). After just one ‘downgrade_utf8()’ use, you get sick of Perl pretty fast.
Basically try using it outside of the anglosphere in the world of Unicode and support falls apart. Sure is excellent if you need to do something like extract a bunch of 1980s database files encoded in LATIN-1 though!
Or, y'know, a bunch of 2010s database files encoded in latin1. Fun fact: Did you know that MySQL 5.7 is still a supported version in 2022?
Even then, I’d rather choose Python.
Perl has had strong unicode support since Perl v5.12 (~2010).
references: 1. http://xahlee.info/perl/perl_unicode.html 2. https://stackoverflow.com/a/6163129/12458
> If you think pythons package management is not disastrous enough, maybe.
Huh? I've used PAR::Packer with great success since 2005.
> If you do not (need to) consider Windows, maybe.
Microsoft used to ship Perl scripts to work with COM and WMI with their NT4 and Windows 2000 resource kits. Perl works *extremely* well with Windows.
I mean, there are lots of reasons to choose Python over Perl, but IMHO, these are not those reasons.
I use Perl as a better-bash. If I was writing a modern website, a large application, or any ML related work...I'd choose Python. But for complex system administration, I'm picking Perl. YMMV
A com file is different from a typical dos/Windows exe, which requires a specific file header. Each exe begins with the two bytes MZ followed by specific information on page sizes etc. and there is no way around.
The challenge a program like APP has is that it should be recognized by all operating systems, so to Linux it should look like an ELF executable, on Windows like a windows executable, etc.
Now if you take this APP perl.com file and load it with Linux, Linux will read the ELF header and be happy. If you load it into Windows, it will see the .com ending and thus just put the code into memory, jump to address 0100h and start executing. The program then can ignore the elf header. And if you open it with some (unzip) Programm such a Programm will look at the end of the file, where it will find a zip file header info and will think it's an zip archive. (Zip files have the header at the end mostly for historic reasons, as all information was only available once compression was done, but as you span multiple disks you can't reach the front anymore)
In the end it is a trick to make it look like different kind of file, depending on who looks at it.
An interesting effort and article from around 2001: https://www.foo.be/docs/tpj/issues/vol5_3/tpj0503-0003.html
And an old Perlmonks discussion on a 850kb Perl: https://www.perlmonks.org/?node_id=222465
There is a newer github project as well -- it did work for a simple project with core modules for me: https://github.com/bentxt/microperl-standalone
$ bash ./perl.com --version
This is perl 5, version 36, subversion 0 (v5.36.0) built for x86_64-cosmo
(with 3 registered patches, see perl -V for more detail)Shame there isn't a portable windowing toolkit you could use with this. I'm pretty sure it's not possible to get the Qt or GTK bindings to work across all platforms from a single install, even if you are using the toolkit's widgets instead of trying to use the platform native widgets.
After stumbling upon Gautham's APE Python port (https://ahgamut.github.io/2021/07/13/ape-python/) [...]However, the libc has grown a lot over the last year (Cosmo has a pthreads API now!) -- the updated libc enabled a quick experimental port of Python 3.11.0rc1 back in August (https://github.com/ahgamut/cpython/tree/cosmo_py311), so I would expect that a newer version of PHP can be ported similarly. Let's see....
(note it's an experimental port, I just put it together).
Does this support musl?