diff options
author | dakkar <dakkar@thenautilus.net> | 2018-11-09 14:41:29 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2018-11-09 14:41:29 +0000 |
commit | db72db7fd0c10131dfc3c4a49e3e2c77aae96b25 (patch) | |
tree | 6a9e16db8a00a8133aed7928e8e1f296fff6b2bd /lib/MaildirIndexer/ScanDir.pm6 | |
parent | let's use Perl 6! (diff) | |
download | MaildirIndexer-db72db7fd0c10131dfc3c4a49e3e2c77aae96b25.tar.gz MaildirIndexer-db72db7fd0c10131dfc3c4a49e3e2c77aae96b25.tar.bz2 MaildirIndexer-db72db7fd0c10131dfc3c4a49e3e2c77aae96b25.zip |
move stuff into modules
Diffstat (limited to 'lib/MaildirIndexer/ScanDir.pm6')
-rw-r--r-- | lib/MaildirIndexer/ScanDir.pm6 | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/MaildirIndexer/ScanDir.pm6 b/lib/MaildirIndexer/ScanDir.pm6 new file mode 100644 index 0000000..d3e5070 --- /dev/null +++ b/lib/MaildirIndexer/ScanDir.pm6 @@ -0,0 +1,34 @@ +use v6.d.PREVIEW; +unit module MaildirIndexer::ScanDir; + +sub scan-dir(IO() $path --> Supply) is export { + supply { + my %watched-dirs; + + sub add-dir(IO::Path $dir, :$initial) { + %watched-dirs{$dir} = True; + + CATCH { when X::IO::Dir { }; default { .perl.say } } + + whenever $dir.watch { + my $path-io = .path.IO; + emit $path-io; + when $path-io.e && $path-io.d { + add-dir($path-io) unless %watched-dirs{$path-io}; + } + when !$path-io.e { + %watched-dirs{$path-io}:delete + } + } + + for $dir.dir { + emit $_; + when .e && .d { + add-dir($_); + } + } + } + + add-dir($path); + } +} |