Acme-Sort-Sleep
view release on metacpan or search on metacpan
local/lib/perl5/IO/Async/File.pm view on Meta::CPAN
# You may distribute under the terms of either the GNU General Public License
# or the Artistic License (the same terms as Perl itself)
#
# (C) Paul Evans, 2012-2015 -- leonerd@leonerd.org.uk
package IO::Async::File;
use strict;
use warnings;
our $VERSION = '0.70';
use base qw( IO::Async::Timer::Periodic );
use Carp;
use File::stat;
# No point watching blksize or blocks
my @STATS = qw( dev ino mode nlink uid gid rdev size atime mtime ctime );
=head1 NAME
C<IO::Async::File> - watch a file for changes
=head1 SYNOPSIS
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;
=head1 DESCRIPTION
This subclass of L<IO::Async::Notifier> watches an open filehandle or named
filesystem entity for changes in its C<stat()> 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 L<IO::Async::FileStream>.
While called "File", it is not required that the watched filehandle be a
regular file. It is possible to watch anything that C<stat(2)> may be called
on, such as directories or other filesystem entities.
=cut
=head1 EVENTS
The following events are invoked, either using subclass methods or CODE
references in parameters.
=head2 on_dev_changed $new_dev, $old_dev
=head2 on_ino_changed $new_ino, $old_ino
=head2 ...
=head2 on_ctime_changed $new_ctime, $old_ctime
Invoked when each of the individual C<stat()> fields have changed. All the
C<stat()> fields are supported apart from C<blocks> and C<blksize>. Each is
passed the new and old values of the field.
=head2 on_devino_changed $new_stat, $old_stat
Invoked when either of the C<dev> or C<ino> fields have changed. It is passed
two L<File::stat> instances containing the complete old and new C<stat()>
fields. This can be used to observe when a named file is renamed; it will not
( run in 0.606 second using v1.01-cache-2.11-cpan-5735350b133 )