1Config::Watch(3)      User Contributed Perl Documentation     Config::Watch(3)
2
3
4

NAME

6       Log::Log4perl::Config::Watch - Detect file changes
7

SYNOPSIS

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

DESCRIPTION

24       This module helps detecting changes in files. Although it comes with
25       the "Log::Log4perl" distribution, it can be used independently.
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
34           seconds 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 a
41       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 call.
51
52       If you already have the current time available, you can pass it on to
53       change_detected() as an optional parameter, like in
54
55           change_detected($time)
56
57       which then won't trigger a call to time(), but use the value provided.
58
59   SIGNAL MODE
60       Instead of polling time and file changes, new() can be instructed to
61       set up a signal handler. If you call the constructor like
62
63           my $watcher = Log::Log4perl::Config::Watch->new(
64                                 file    => "/data/my.conf",
65                                 signal  => 'HUP'
66                         );
67
68       then a signal handler will be installed, setting the object's variable
69       "$self->{signal_caught}" to a true value when the signal arrives.
70       Comes with all the problems that signal handlers go along with.
71
72   TRIGGER CHECKS
73       To trigger a physical file check on the next call to change_detected()
74       regardless if "check_interval" has expired or not, call
75
76           $watcher->force_next_check();
77
78       on the watcher object.
79
80   DETECT MOVED FILES
81       The watcher can also be used to detect files that have moved. It will
82       not only detect if a watched file has disappeared, but also if it has
83       been replaced by a new file in the meantime.
84
85           my $watcher = Log::Log4perl::Config::Watch->new(
86               file           => "/data/my.conf",
87               check_interval => 30,
88           );
89
90           while(1) {
91               if($watcher->file_has_moved()) {
92                   print "File has moved!\n";
93               }
94               sleep(1);
95           }
96
97       The parameters "check_interval" and "signal" limit the number of
98       physical file system checks, similarily as with change_detected().
99

LICENSE

101       Copyright 2002-2013 by Mike Schilli <m@perlmeister.com> and Kevin Goess
102       <cpan@goess.org>.
103
104       This library is free software; you can redistribute it and/or modify it
105       under the same terms as Perl itself.
106

AUTHOR

108       Please contribute patches to the project on Github:
109
110           http://github.com/mschilli/log4perl
111
112       Send bug reports or requests for enhancements to the authors via our
113
114       MAILING LIST (questions, bug reports, suggestions/patches):
115       log4perl-devel@lists.sourceforge.net
116
117       Authors (please contact them via the list above, not directly): Mike
118       Schilli <m@perlmeister.com>, Kevin Goess <cpan@goess.org>
119
120       Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens
121       Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse
122       Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis
123       Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier  David
124       Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
125       Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars
126       Thegler, David Viner, Mac Yang.
127
128
129
130perl v5.38.0                      2023-07-20                  Config::Watch(3)
Impressum