NAME
Chandra::HotReload - File watching and hot reload for Chandra applications
SYNOPSIS
use Chandra::HotReload;
my $watcher = Chandra::HotReload->new(interval => 1.0);
$watcher->watch('lib/', sub {
my ($changed_files) = @_;
print "Changed: @$changed_files\n";
$app->set_content(build_ui());
$app->refresh;
});
# In event loop (or via App integration):
$watcher->poll;
# Or integrated with App:
$app->watch('lib/', sub {
my ($changed) = @_;
$app->set_content(rebuild());
$app->refresh;
});
$app->run; # automatically polls during event loop
DESCRIPTION
Chandra::HotReload provides file-system watching via stat() polling. Register paths (files or directories) to watch along with callbacks that are invoked whenever a change is detected.
When integrated with Chandra::App via $app->watch(), the event loop automatically switches to non-blocking mode and polls for file changes between iterations.
METHODS
new(%args)
Create a new watcher. Options:
watch($path, $coderef)
Register a path to watch. The callback receives an arrayref of changed file paths when a modification, addition, or deletion is detected.
poll()
Check all watched paths for changes. Returns the number of changed files (0 if nothing changed or the poll interval has not elapsed).
clear()
Remove all watches.
watched_paths()
Return a list of currently watched paths.
interval($seconds)
Get or set the poll interval.