Open
Description
Hi!
First of all, thank you for doing this project! I'm using it to write a memoized dom module and test it (https://github.com/FCO/webperl/blob/master/web/todo6.html).
I'd like to not include the module inside the html. Id love to use
just work, but it would be ok if I need to <script type=text/perl6 src=MemoizedDom.pm6></script>
too.
Is it possible?
thank you
Metadata
Metadata
Assignees
Labels
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Make a way to use modules[/-][+]Create a way to use modules[/+]haukex commentedon Nov 30, 2018
That looks pretty cool, and thanks for the report!
In theory, it should be possible to load modules dynamically, one way to do this would be via JavaScript's XHR or the newer Fetch API. There are two things that make this nontrivial:
For a single module file, it'd be pretty straightforward. But as a general mechanism, one module might load another, and another, and so on. That hook would need to be made in Perl rather than WebPerl.
Loading of modules normally needs to happen synchronously.
For the case of Perl 5, I discussed this with @LanX over on PerlMonks: fetching data over the web and dynamically importing non-bundled modules via http, where he uses synchronous XHRs to fetch modules via an
@INC
hook (although synchronous XHR's aren't recommended anymore, see e.g. MDN's take on it).For Perl 6, I'm not fully up to speed on it yet, so I don't know at the moment what the equivalent mechanism to Perl 5's
@INC
hook is. I do suspect that because Perl 6 has better built-in async support, it might be easier to load modules asynchronously. (Note that I "stole" the Perl 6 build from @pmurias's 6pad, and I'm not much of an expert on it myself.)For now, if you're just loading one specific module with no dependencies, I would suggest you implement it yourself using one of the JS APIs. As a general feature, it's on my radar, but has not been a high priority yet, because of the potential performance impact of fetching a bunch of modules dynamically. If there are modules that a WebPerl project always needs, another solution is bundling them with the main package so that they are fetched together with WebPerl. For Perl 5, this can be done by building one's own virtual file system, and for Perl 6, Paweł wrote me recently that he might add some documentation on how the bundling works - for now, see perl6-parcel-example.
I unfortunately can't work on WebPerl full-time, but I do hope we can get around to adding some useful features like this one :-)