NAME

Chandra::Bridge - JavaScript bridge code for Perl communication

SYNOPSIS

use Chandra::Bridge;

# Get the JS code to inject
my $js = Chandra::Bridge->js_code;

# Get the JS code escaped for eval
my $escaped = Chandra::Bridge->js_code_escaped;

DESCRIPTION

This module contains the JavaScript bridge code that enables communication between JavaScript and Perl via window.chandra.

You normally do not use this module directly; Chandra::App injects the bridge automatically.

JavaScript API

After injection, the following is available in JavaScript:

// Call a Perl function (returns Promise)
const result = await window.chandra.invoke('method_name', [arg1, arg2]);

// Shorthand
const result = await window.chandra.call('method_name', arg1, arg2);

METHODS

js_code

my $js = Chandra::Bridge->js_code;

Class method. Returns the raw JavaScript source for the bridge.

js_code_escaped

my $js = Chandra::Bridge->js_code_escaped;

Class method. Returns the bridge code wrapped for injection via eval_js (newlines and quotes escaped).

SEE ALSO

Chandra::App, Chandra::Bind