Alien-Xrepo
view release on metacpan or search on metacpan
eg/webui.pl view on Meta::CPAN
#log .ev { color: var(--accent); }
#log .err { color: #ff6b6b; }
footer { margin-top: 14px; color: var(--muted); font-size: .8rem; }
a { color: var(--accent); }
</style>
</head>
<body>
<main>
<h1>WebUI <span>·</span> Modern Perl</h1>
<p class="sub">Synchronous callbacks, async Promises, and Perl with page events via Alien::Xrepo and Affix</p>
<div class="grid">
<section class="card">
<h2>Counter · synchronous</h2>
<div class="row">
<button onclick="count_inc()">+1</button>
<button onclick="count_dec()">-1</button>
<button class="primary" onclick="count_reset()">reset</button>
<div id="count">0</div>
</div>
<p style="color:var(--muted);font-size:.85rem;margin:0">Each click calls C bound with <code>webui_bind()</code>; Perl writes the result back with <code>webui_run()</code>.</p>
</section>
<section class="card">
<h2>Async · Promises</h2>
<div class="row">
<input id="n" type="number" value="21">
<button onclick="callDouble()">double it</button>
</div>
<div class="result" id="double-out"></div>
<div class="row">
<input id="t" type="text" value="hello, webui">
<button onclick="callShout()">shout it</button>
</div>
<div class="result" id="shout-out"></div>
<p style="color:var(--muted);font-size:.85rem;margin:0">Resolved by C via <code>webui_interface_bind()</code> + <code>webui_interface_set_response()</code>.</p>
</section>
</div>
<section class="card" style="margin-top:16px">
<h2>Event log</h2>
<ul id="log"></ul>
<footer>Open an <a id="ext" href="https://example.com">external link</a> to trigger a navigation event - Perl sends you right back.</footer>
</section>
</main>
<script>
const logEl = document.getElementById('log');
function log(message, kind = '') {
const li = document.createElement('li');
if (kind) li.className = kind;
const t = new Date().toLocaleTimeString([], { hour12: false });
li.textContent = `${t} ${message}`;
logEl.appendChild(li);
logEl.scrollTop = logEl.scrollHeight;
}
function updateCount(n) { document.getElementById('count').textContent = n; }
function callDouble() {
const n = Number(document.getElementById('n').value);
if (Number.isNaN(n)) return log('double: invalid number', 'err');
double_async(n)
.then(r => { document.getElementById('double-out').textContent = `${n} Ã 2 = ${r}`; })
.catch(e => log(`double_async() rejected: ${e}`, 'err'));
}
function callShout() {
const t = document.getElementById('t').value;
shout_async(t)
.then(r => { document.getElementById('shout-out').textContent = `"${t}" â "${r}"`; })
.catch(e => log(`shout_async() rejected: ${e}`, 'err'));
}
log('page ready - waiting for the C side to talk back', 'ev');
</script>
</body>
</html>
HTML
$app->set_size( 920, 800 );
$app->show($html);
$app->wait;
$app->clean;
__END__
Copyright (C) Sanko Robinson.
This library is free software; you can redistribute it and/or modify it under the terms found in
the Artistic License 2. Other copyrights, terms, and conditions may apply to data transmitted
through this module.
( run in 1.597 second using v1.01-cache-2.11-cpan-60884a8df76 )