Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (64 sloc) 1.97 KB
<!doctype html>
<html lang="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WebPerl &lt;script&gt; Demos</title>
<script src="webperl.js"></script>
<!-- Please see the documentation at -->
<!-- Example 1: A really basic script -->
<script type="text/perl">
print "Hello, Perl World!\n";
<!-- Example 2: Accessing JavaScript -->
<script type="text/perl">
use warnings;
use strict;
use WebPerl qw/js/;
->addEventListener("click", sub {
print "You clicked 'Testing!'\n";
} );
<!-- Example 3: Using jQuery -->
<!--cacheable--><script src="" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script type="text/perl">
use warnings;
use strict;
use WebPerl qw/js/;
my $jq = js('jQuery');
my $btn = $jq->('<button>', { text=>"Click me!" } );
$btn->click(sub {
print "You clicked the jQuery button!\n";
} );
$btn->appendTo( $jq->('#buttons') );
# And a demo of AJAX using jQuery:
use Cpanel::JSON::XS qw/encode_json/;
use Data::Dumper;
my $data_out = { hello => "Hello, World!\n" };
$jq->ajax( '/ajaxtest', {
method => 'POST', # we're sending JSON in the POST body
data => encode_json($data_out),
} )->done( sub {
my $data_in = shift;
print "AJAX Success! Data: ", Dumper($data_in->toperl);
} )->fail( sub {
my ($jqXHR, $textStatus, $errorThrown) = @_;
print "AJAX Failed! ($errorThrown)\n";
} );
<!-- Optional STDOUT/STDERR text area (if you don't use this, output goes to Javascript console) -->
window.addEventListener("load", function () {
.appendChild( Perl.makeOutputTextarea() );
<p>This is a demo of <a href="" target="_blank">WebPerl</a>!</p>
<div id="output"></div>
<div id="buttons">
<button id="my_button">Testing!</button>
You can’t perform that action at this time.