IO::Async::File(3pm)
π IO::Async::File π
okay bestie, this is the manual page for IO::Async::File(3pm) from the User Contributed Perl Documentation β and no, it's not boring, it's lowkey iconic. let's get into it π«Ά
β¨ NAME β¨
IO::Async::File β watch a file for changes π (that's literally the whole job, and it slays)
πΈ SYNOPSIS πΈ
here's the vibe, copy-paste it and go:
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\n";
reload_config( $self->handle );
}
);
$loop->add( $file );
$loop->run;
π¦ DESCRIPTION π¦
so this is a subclass of IO::Async::Notifier, right? and what it does is watch an open filehandle β or a named filesystem entity β for changes in its stat() fields. when those fields change value, it fires off various events. the most common use case is watching a file for size changes; if that's your goal, also go look at IO::Async::FileStream.
and the way it's called "File" but does NOT require the watched filehandle to be a regular file? yeah. you can watch literally anything stat(2) can be called on β directories, other filesystem entities, whatever. main character energy, it does not gatekeep π
since version 0.805, a named file does not necessarily need to exist. if it's not there, all its stat() fields are treated as undefined; events get invoked when it becomes present or gets removed, plus whenever anything else changes. so it's tracking the whole arc, not just the glow-up π
π₯ EVENTS π₯
these events get invoked, either using subclass methods or CODE references in parameters. yes, both. flexible queen.
π« on_dev_changed $new_dev, $old_dev
π« on_ino_changed $new_ino, $old_ino
π« ...
π« on_ctime_changed $new_ctime, $old_ctime
Invoked when each of the individual stat() fields have changed. all the stat() fields are supported apart from blocks and blksize β those two are the ones that didn't make the cut, sorry to them. each event is passed the new and old values of the field. either field may be undef if the file did not exist or currently does not exist (it's giving absent, but emotionally).
π« on_devino_changed $new_stat, $old_stat
Invoked when either of the dev or ino fields have changed. it gets passed two File::stat instances containing the complete old and new stat() fields. bestie, this is the one you use to observe when a named file gets renamed β but heads up, that will not be observed to happen on opened filehandles. it's giving "only for the named files, periodt" π
π« on_stat_changed $new_stat, $old_stat
Invoked when any of the stat() fields have changed. it gets passed two File::stat instances containing the old and new stat() fields. either value may be undef if the file did not exist or currently does not exist. this is the catch-all, the main event, the one that watches everything π
π PARAMETERS π
these named parameters can be passed to new or configure. mix and match, do your thing β¨
handle=> IO β the opened filehandle to watch forstat()changes, iffilenameis not supplied.filename=> STRING β Optional. if you supply it, it watches the named file rather than the filehandle given inhandle. the file gets 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. glow-up with a handle swap, we love to see it π¦interval=> NUM β Optional. the interval in seconds to poll the filehandle usingstat(2)looking for size changes. if you don't define it, a default of2seconds gets applied. no cap, just twice-a-second-ish energy β±οΈ
π METHODS π
β handle
$handle = $file->handle;
Returns the filehandle currently associated with the instance; either the one passed to the handle parameter, or opened from the filename parameter. either way, it's your handle, owned and iconic.
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
that's the whole page bestie, you've officially read the entire manual π no cap. this was perl v5.40.1, dated 2026-02-21, IO::Async::File(3pm) β and yes, the footer is the sign-off, so: mwah, bye, go watch some files ππ
π«Ά
π¦ where this page comes from
- ubuntu stonking: libio-async-perl 0.805-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms