run perl in the browser with webperl! goo.gl/qpvub9 ī · motivation hello, perl world!

21
Run Perl in the Browser with WebPerl! haukex ī goo.gl/QPvUb9

Upload: others

Post on 14-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 2: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation   Hello, Perl World!

Outline

2

Page 3: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation   Hello, Perl World!

Research for the Future of our Freshwaters

3

Page 5: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation   Hello, Perl World!

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 7: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation   Hello, Perl World!

↔Build Process Overview

webperl.jsemperl.js

emperl.wasmemperl.data

7

*.pm

Page 9: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation   Hello, Perl World!

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!

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!

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!

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!

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!

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!

Advantages & Disadvantages

● :-)

●●

node.js

●●

●fork qx

●○

○●

<iframe>

15

Page 16: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation   Hello, Perl World!

Status

●○○

qx runperl t/test.pl

qx

● ;-)

○○○ →

16

Page 17: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation   Hello, Perl World!

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!

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 20: Run Perl in the Browser with WebPerl! goo.gl/QPvUb9 ī · Motivation   Hello, Perl World!

Questions?

http://webperl.zero-g.net/

goo.gl/QPvUb9

Thank You!