File Coverage

blib/lib/Mojo/File/ChangeNotify/WatcherProcess.pm
Criterion Covered Total %
statement 14 23 60.8
branch 0 2 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 19 32 59.3


line stmt bran cond sub pod time code
1             package Mojo::File::ChangeNotify::WatcherProcess 0.02;
2 8     8   160 use 5.020;
  8         66  
3 8     8   56 use experimental 'signatures';
  8         30  
  8         60  
4 8     8   1192 use feature 'postderef';
  8         20  
  8         367  
5 8     8   42 use Exporter 'import';
  8         14  
  8         419  
6 8     8   4757 use File::ChangeNotify;
  8         2565667  
  8         2904  
7             our @EXPORT_OK = 'watch';
8              
9             # We keep this in a separate module file as to minimize any variables
10             # shared over into this context
11              
12             =head1 NAME
13              
14             Mojo::File::ChangeNotify::WatcherProcess - helper module for the subprocess
15              
16             =head1 SYNOPSIS
17              
18             my $w = Mojo::File::ChangeNotify->instantiate_watcher(
19             directories => ['.'],
20             on_change => sub($s,$ev) {
21             for my $e ($ev->@*) {
22             print "$e->{type} $e->{path}\n";
23             }
24             }
25             );
26             # note that the watcher might need about 1s to start up
27              
28             =cut
29              
30 0     0 0   sub watch( $subprocess, $args ) {
  0            
  0            
  0            
31 0           my $watcher = File::ChangeNotify->instantiate_watcher( $args->%* );
32 0           while( my @events = $watcher->wait_for_events ) {
33 0           for my $list (@events) {
34 0           $subprocess->progress( [ map {;
35 0 0         defined $_->path
36             ? +{ path => $_->path, type => $_->type }
37             : ()
38             } $list ]);
39             }
40             }
41             }
42              
43             1;