1Config::Watch(3) User Contributed Perl Documentation Config::Watch(3)
2
3
4
6 Log::Log4perl::Config::Watch - Detect file changes
7
9 use Log::Log4perl::Config::Watch;
10
11 my $watcher = Log::Log4perl::Config::Watch->new(
12 file => "/data/my.conf",
13 check_interval => 30,
14 );
15
16 while(1) {
17 if($watcher->change_detected()) {
18 print "Change detected!\n";
19 }
20 sleep(1);
21 }
22
24 This module helps detecting changes in files. Although it comes with
25 the "Log::Log4perl" distribution, it can be used independly.
26
27 The constructor defines the file to be watched and the check interval
28 in seconds. Subsequent calls to "change_detected()" will
29
30 · return a false value immediately without doing physical file checks
31 if "check_interval" hasn't elapsed.
32
33 · perform a physical test on the specified file if the number of sec‐
34 onds specified in "check_interval" have elapsed since the last
35 physical check. If the file's modification date has changed since
36 the last physical check, it will return a true value, otherwise a
37 false value is returned.
38
39 Bottom line: "check_interval" allows you to call the function
40 "change_detected()" as often as you like, without paying the performing
41 a significant performance penalty because file system operations are
42 being performed (however, you pay the price of not knowing about file
43 changes until "check_interval" seconds have elapsed).
44
45 The module clearly distinguishes system time from file system time. If
46 your (e.g. NFS mounted) file system is off by a constant amount of time
47 compared to the executing computer's clock, it'll just work fine.
48
49 To disable the resource-saving delay feature, just set "check_interval"
50 to 0 and "change_detected()" will run a physical file test on every
51 call.
52
53 If you already have the current time available, you can pass it on to
54 "change_detected()" as an optional parameter, like in
55
56 change_detected($time)
57
58 which then won't trigger a call to "time()", but use the value pro‐
59 vided.
60
61 SIGNAL MODE
62
63 Instead of polling time and file changes, "new()" can be instructed to
64 set up a signal handler. If you call the constructor like
65
66 my $watcher = Log::Log4perl::Config::Watch->new(
67 file => "/data/my.conf",
68 signal => 'HUP'
69 );
70
71 then a signal handler will be installed, setting the object's variable
72 "$self->{signal_caught}" to a true value when the signal arrives. Comes
73 with all the problems that signal handlers go along with.
74
77 Mike Schilli, <log4perl@perlmeister.com>
78
80 Copyright 2003 by Mike Schilli <m@perlmeister.com> and Kevin Goess
81 <cpan@goess.org>.
82
83 This library is free software; you can redistribute it and/or modify it
84 under the same terms as Perl itself.
85
86
87
88perl v5.8.8 2002-07-10 Config::Watch(3)