run perl in the browser with webperl! goo.gl/qpvub9 ī · motivation hello, perl world!
TRANSCRIPT
![Page 1: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/1.jpg)
Run Perl in the Browser with WebPerl!
haukex
ī
goo.gl/QPvUb9
![Page 2: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/2.jpg)
Outline
●
●
●
●
●
●
2
![Page 4: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/4.jpg)
Many Thanks To:
●●
○○○ ł○
■■■
4
![Page 5: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/5.jpg)
Motivation<html>
<head>
<title>Hello, Perl World!</title>
<script type="text/perl">
print "Hello, Perl World!\n";
</script>
</head>
<body>
</body>
</html>
<script src="webperl.js"></script>
5
![Page 6: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/6.jpg)
Technical Background
●○
● asm.js
○
●○○ asm.js
●○ clang asm.js
○
6
![Page 7: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/7.jpg)
↔Build Process Overview
webperl.jsemperl.js
emperl.wasmemperl.data
7
*.pm
![Page 8: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/8.jpg)
● webperl.js
○ <script type="text/perl"> join
Perl
○ emperl.js emperl.wasm emperl.data
○ STDOUT ERR Perl.output
● WebPerl.pm
○ js($javascript_code) WebPerl::JSObject
○ WebPerl.xs webperl.js
Glue Code
8
![Page 9: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/9.jpg)
API: js()
js("javascript_code")
⇒
undefined undef
!0 !1
function
WebPerl::JSObject
js( [1,2,3] ) js( {foo=>"bar"} )
WebPerl::JSObject
9
![Page 10: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/10.jpg)
API: WebPerl::JSObject
⇒
$jso->{"bar"} obj["bar"]
$jso->[42] obj[42]
$jso->("arg", ...) obj("arg", ...)
$jso->bar("arg", ...) obj.bar("arg", ...)
$jso->methodcall( "can", "arg", ...)
obj.can("arg", ...)
$jso->toperl()
function
WebPerl::JSObject DESTROY
10
![Page 11: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/11.jpg)
API: JS ↔ Perl
my $jsobject = js( {hello=>"world"} );
js("function (a,b,c,d,e) {}")->( "foo", [1,2,3], {bar=>42},
sub {}, $jsobject );
Cpanel::JSON::XS
● function sub
● sub
● DESTROY sub
WebPerl::unregister($coderef)
11
WebPerl::JSObject
![Page 12: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/12.jpg)
Example <script>
document.getElementById('my_button')
.addEventListener('click', function () {
window.alert("You clicked the button!");
} );
</script>
<script src="webperl.js"></script>
<script type="text/perl">
js('document')->getElementById('my_button')
->addEventListener('click', sub {
js('window')->alert("You clicked the button!");
} );
</script>
12
![Page 13: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/13.jpg)
The Perl Interpreter’s Environment
● system qx open fork
kill wait waitpid SIGALRM
●○ <STDIN>
○ :-)
●○○ /mnt/idb
○
13
![Page 14: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/14.jpg)
Perl Interpreter Lifecycle#!/usr/bin/perlEND { ... }while (<>) { chomp; ... print;}exit(0);__END__
use Tk;$mw = MainWindow->new;$mw->Button( -text => "Close", -command => sub { $mw->destroy(); } )->pack();MainLoop;__END__
use WebPerl;END { ... }...->addEventListener( 'click', sub { ... } );exit(0);__END__
END
main()
main()
●●
WebPerl::end_perl()
14
![Page 15: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/15.jpg)
Advantages & Disadvantages
● :-)
●●
node.js
●●
●fork qx
●
●○
○●
<iframe>
15
➢
![Page 17: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/17.jpg)
Perl 6 Support
● ł○○
●○ ł○ js
●○ <script type="text/perl6">
○ Raku
●my $window = EVAL(:lang<JavaScript>, 'return window');
$window.alert("Hello, World!");
17
![Page 18: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/18.jpg)
Example: Getting Started
https://webperl.zero-g.net/#quick-start
https://webperl.zero-g.net/perl6.html#quick-start
💲 git clone https://github.com/haukex/webperl.git && cd webperl
💲 wget https://github.com/haukex/webperl/releases/\
download/v0.09-beta/webperl_prebuilt_v0.09-beta.zip
💲 unzip -j webperl_prebuilt_v0.09-beta.zip '*/emperl.*' -d web
💲 cpanm --installdeps .
💲 plackup web/webperl.psgi &
💲 x-www-browser http://localhost:5000/webperl_demo.html
18
![Page 19: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/19.jpg)
More Examples
●○○
●○
●○
●○
perl11.org
19
![Page 20: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation Hello, Perl World!](https://reader035.vdocument.in/reader035/viewer/2022081613/5fb4e070e7551939284972be/html5/thumbnails/20.jpg)
Questions?
http://webperl.zero-g.net/
goo.gl/QPvUb9
Thank You!