App-SlideServer
view release on metacpan or search on metacpan
lib/App/SlideServer.pm view on Meta::CPAN
package App::SlideServer;
use v5.36;
use Mojo::Base 'Mojolicious';
use Mojo::WebSocket 'WS_PING';
use Mojo::File 'path';
use Mojo::DOM;
use Scalar::Util 'looks_like_number';
use File::stat;
use Text::Markdown::Hoedown;
use Carp;
our $VERSION = '0.002'; #VERSION
#ABSTRACT: Mojo web server that serves slides and websocket
# Files supplied by the user to override the distribution
has serve_dir => sub { path(shift->home) };
# Choose the first of
sub slides_source_file($self, $value=undef) {
$self->{slides_source_file}= $value if defined $value;
$self->{slides_source_file} // do {
my ($src)= grep -f $_,
$self->serve_dir->child('slides.html'),
$self->serve_dir->child('slides.md'),
$self->serve_dir->child('public','slides.html'),
$self->serve_dir->child('public','slides.md');
$src;
};
}
has 'slides_source_monitor';
# Files that ship with the distribution
has share_dir => sub {
if (-f path(__FILE__)->sibling('..','..','share','public','slides.js')) {
return path(__FILE__)->sibling('..','..','share')->realpath;
} else {
require File::ShareDir;
return path(File::ShareDir::dist_dir('App-SlideServer'));
}
};
# A secret known only to whoever starts the server
# Clients must send this to gain presenter permission.
has presenter_key => sub($self) {
my $key= sprintf "%06d", rand 1000000;
$self->log->info("Auto-generated presenter key: $key");
return $key;
};
# Hashref of { ID => $context } for every connected websocket
has viewers => sub { +{} };
# Hashref of data to be pushed to all clients
has published_state => sub { +{} };
has ['cache_token', 'page_dom', 'slides_dom'];
sub build_slides($self, %opts) {
( run in 1.465 second using v1.01-cache-2.11-cpan-39bf76dae61 )