1File::ChangeNotify::WatUcsheerr(C3o)ntributed Perl DocumFeinltea:t:iCohnangeNotify::Watcher(3)
2
3
4
6 File::ChangeNotify::Watcher - Base class for all watchers
7
9 version 0.16
10
12 my $watcher =
13 File::ChangeNotify->instantiate_watcher
14 ( directories => [ '/my/path', '/my/other' ],
15 filter => qr/\.(?:pm|conf|yml)$/,
16 exclude => ['t', 'root', qr(/(?!\.)[^/]+$)],
17 );
18
19 if ( my @events = $watcher->new_events() ) { ... }
20
21 # blocking
22 while ( my @events = $watcher->wait_for_events() ) { ... }
23
25 A "File::ChangeNotify::Watcher" class monitors a directory for changes
26 made to any file. You can provide a regular expression to filter out
27 files you are not interested in. It handles the addition of new
28 subdirectories by adding them to the watch list.
29
30 Note that the actual granularity of what each watcher subclass reports
31 may vary across subclasses. Implementations that hook into some sort of
32 kernel event interface (Inotify, for example) have much better
33 knowledge of exactly what changes are happening than one implemented
34 purely in userspace code (like the Default subclass).
35
36 By default, events are returned in the form File::ChangeNotify::Event
37 objects, but this can be overridden by providing an "event_class"
38 attribute to the constructor.
39
40 The watcher can operate in a blocking/callback style, or you can simply
41 ask it for a list of new events as needed.
42
44 File::ChangeNotify::Watcher::Subclass->new(...)
45 This method creates a new watcher. It accepts the following arguments:
46
47 · directories => $path
48
49 · directories => \@paths
50
51 This argument is required. It can be either one or many paths which
52 should be watched for changes.
53
54 · filter => qr/.../
55
56 This is an optional regular expression that will be used to check
57 if a file is of interest. This filter is only applied to files.
58
59 By default, all files are included.
60
61 · exclude => [...]
62
63 An optional list of paths to exclude. This list can contain either
64 plain strings or regular expressions. If you provide a string it
65 should contain the complete path to be excluded.
66
67 The paths can be either directories or specific files. If the
68 exclusion matches a directory, all of its files and subdirectories
69 are ignored.
70
71 · follow_symlinks => $bool
72
73 By default, symlinks are ignored. Set this to true to follow them.
74
75 If this symlinks are being followed, symlinks to files and
76 directories will be followed. Directories will be watched, and
77 changes for directories and files reported.
78
79 · sleep_interval => $number
80
81 For watchers which call "sleep" to implement the
82 "$watcher->wait_for_events()" method, this argument controls how
83 long it sleeps for. The value is a number in seconds.
84
85 The default is 2 seconds.
86
87 · event_class => $class
88
89 This can be used to change the class used to report events. By
90 default, this is File::ChangeNotify::Event.
91
92 $watcher->wait_for_events()
93 This method causes the watcher to block until it sees interesting
94 events, and then return them as a list.
95
96 Some watcher subclasses may implement blocking as a sleep loop, while
97 others may actually block.
98
99 $watcher->new_events()
100 This method returns a list of any interesting events seen since the
101 last time the watcher checked.
102
103 $watcher->sees_all_events()
104 If this is true, the watcher will report on all events.
105
106 Some watchers, like the Default subclass, are not smart enough to track
107 things like a file being created and then immediately deleted, and can
108 only detect changes between snapshots of the file system.
109
110 Other watchers, like the Inotify subclass, see all events that happen
111 and report on them.
112
114 Dave Rolsky <autarch@urth.org>
115
117 This software is Copyright (c) 2010 by Dave Rolsky.
118
119 This is free software, licensed under:
120
121 The Artistic License 2.0
122
123
124
125perl v5.12.1 2010-07-12 File::ChangeNotify::Watcher(3)