.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "IO::Async::File 3pm" .TH IO::Async::File 3pm 2024-02-04 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME "IO::Async::File" \- watch a file for changes .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use IO::Async::File; \& \& use IO::Async::Loop; \& my $loop = IO::Async::Loop\->new; \& \& my $file = IO::Async::File\->new( \& filename => "config.ini", \& on_mtime_changed => sub { \& my ( $self ) = @_; \& print STDERR "Config file has changed\en"; \& reload_config( $self\->handle ); \& } \& ); \& \& $loop\->add( $file ); \& \& $loop\->run; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This subclass of IO::Async::Notifier watches an open filehandle or named filesystem entity for changes in its \f(CWstat()\fR fields. It invokes various events when the values of these fields change. It is most often used to watch a file for size changes; for this task see also IO::Async::FileStream. .PP While called "File", it is not required that the watched filehandle be a regular file. It is possible to watch anything that \f(CWstat(2)\fR may be called on, such as directories or other filesystem entities. .SH EVENTS .IX Header "EVENTS" The following events are invoked, either using subclass methods or CODE references in parameters. .ie n .SS "on_dev_changed $new_dev, $old_dev" .el .SS "on_dev_changed \f(CW$new_dev\fP, \f(CW$old_dev\fP" .IX Subsection "on_dev_changed $new_dev, $old_dev" .ie n .SS "on_ino_changed $new_ino, $old_ino" .el .SS "on_ino_changed \f(CW$new_ino\fP, \f(CW$old_ino\fP" .IX Subsection "on_ino_changed $new_ino, $old_ino" .SS ... .IX Subsection "..." .ie n .SS "on_ctime_changed $new_ctime, $old_ctime" .el .SS "on_ctime_changed \f(CW$new_ctime\fP, \f(CW$old_ctime\fP" .IX Subsection "on_ctime_changed $new_ctime, $old_ctime" Invoked when each of the individual \f(CWstat()\fR fields have changed. All the \&\f(CWstat()\fR fields are supported apart from \f(CW\*(C`blocks\*(C'\fR and \f(CW\*(C`blksize\*(C'\fR. Each is passed the new and old values of the field. .ie n .SS "on_devino_changed $new_stat, $old_stat" .el .SS "on_devino_changed \f(CW$new_stat\fP, \f(CW$old_stat\fP" .IX Subsection "on_devino_changed $new_stat, $old_stat" Invoked when either of the \f(CW\*(C`dev\*(C'\fR or \f(CW\*(C`ino\*(C'\fR fields have changed. It is passed two File::stat instances containing the complete old and new \f(CWstat()\fR fields. This can be used to observe when a named file is renamed; it will not be observed to happen on opened filehandles. .ie n .SS "on_stat_changed $new_stat, $old_stat" .el .SS "on_stat_changed \f(CW$new_stat\fP, \f(CW$old_stat\fP" .IX Subsection "on_stat_changed $new_stat, $old_stat" Invoked when any of the \f(CWstat()\fR fields have changed. It is passed two File::stat instances containing the old and new \f(CWstat()\fR fields. .SH PARAMETERS .IX Header "PARAMETERS" The following named parameters may be passed to \f(CW\*(C`new\*(C'\fR or \f(CW\*(C`configure\*(C'\fR. .SS "handle => IO" .IX Subsection "handle => IO" The opened filehandle to watch for \f(CWstat()\fR changes if \f(CW\*(C`filename\*(C'\fR is not supplied. .SS "filename => STRING" .IX Subsection "filename => STRING" Optional. If supplied, watches the named file rather than the filehandle given in \f(CW\*(C`handle\*(C'\fR. The file will be opened for reading and then watched for renames. If the file is renamed, the new filename is opened and tracked similarly after closing the previous file. .SS "interval => NUM" .IX Subsection "interval => NUM" Optional. The interval in seconds to poll the filehandle using \f(CWstat(2)\fR looking for size changes. A default of 2 seconds will be applied if not defined. .SH METHODS .IX Header "METHODS" .SS handle .IX Subsection "handle" .Vb 1 \& $handle = $file\->handle; .Ve .PP Returns the filehandle currently associated with the instance; either the one passed to the \f(CW\*(C`handle\*(C'\fR parameter, or opened from the \f(CW\*(C`filename\*(C'\fR parameter. .SH AUTHOR .IX Header "AUTHOR" Paul Evans