preaction / Statocles

Static website CMS
http://preaction.me/statocles
Other
84 stars 33 forks source link

CPAN install breaks in Mac::FSEvents #607

Closed c-alpha closed 1 year ago

c-alpha commented 2 years ago

cpanm Statocles breaks when building Mac-FSEvents-0.14.

Peeking into the code of that module, it seems it supports macOS only up to, and including major version 10. I.e. macOS 11 (Big Sur) and 12 (Monetrey) are not supported.

Can it be replaced with something that is still maintained? Is it needed at all (looking at #189)?

c-alpha commented 2 years ago

I looked into /lib/Statocles/Command/daemon.pm, where Mac::FSEvents is used. Without any experience with Mojolicious on my part (cough), I think the relevant section in startup() could potentially be replaced with code along the lines of this little test script:

#!/usr/bin/env -S perl

use Mojo::IOLoop;
use File::ChangeNotify;

my $latency = 1.0;        # in seconds
my $ioloop = Mojo::IOLoop->singleton;
my $watches = [ '.' ];    # list more paths as needed

my $watcher =
  File::ChangeNotify->instantiate_watcher
  ( directories     => $watches,
    sleep_interval  => $latency,
    # follow_symlinks => 1,    # By default, symlinks are ignored. Set this to true to follow them.
  );

$ioloop->reactor->recurring ( $latency => sub {
                                my $rebuild = 0;
                                for my $event ( $watcher->new_events ) {
                                  print "Path '" . $event->path . "' changed...\n";
                                  $rebuild = 1;
                                }
                                if ($rebuild) {
                                  print "Rebuilding site\n";
                                }
                              } );

$ioloop->reactor->start;

File::ChangeNotify IMO has two advantages: it provides the feature cross-platform (i.e. no longer restricted to Mac), and it can watch several paths at once (i.e. code in startup() could perhaps be simplified).