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

LICENSE

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

AUTHOR

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