NAME

Chandra::App - High-level application wrapper for Chandra

SYNOPSIS

use Chandra::App;

my $app = Chandra::App->new(
    title  => 'My App',
    width  => 800,
    height => 600,
);

$app->bind('greet', sub {
    my ($name) = @_;
    return "Hello, $name!";
});

$app->set_content('<h1>Hello World</h1><button onclick="window.chandra.invoke(\'greet\',[\'World\']).then(r=>document.title=r)">Greet</button>');

$app->run;

DESCRIPTION

Chandra::App provides a clean, high-level OO interface on top of the XS-backed Chandra module. It manages the webview lifecycle and provides convenience methods for setting content, updating the DOM, and running JavaScript.

METHODS

new(%args)

Create a new application. Accepts all the same options as Chandra->new: title, url, width, height, resizable, debug.

run()

Initialize the webview, inject any set_content HTML, and enter the event loop. Blocks until the window is closed.

bind($name, $coderef)

Register a Perl subroutine callable from JavaScript via window.chandra.invoke($name, [args]).

set_content($html_or_element)

Set the page content. Accepts a plain HTML string or any object that responds to render() (e.g., a future Chandra::Element).

update($selector, $html_or_element)

Replace the innerHTML of the element matching $selector.

eval($js)

Execute JavaScript in the webview.

dispatch_eval($js)

Deferred JavaScript evaluation, safe to call from within Perl callbacks.

set_title($title)

Change the window title.

alert($message)

Show a JavaScript alert dialog.

terminate()

Signal the event loop to stop.

webview()

Access the underlying Chandra XS object.

init() / loop($blocking) / exit()

Low-level lifecycle methods for manual event loop control.