AnyEvent-Filesys-Watcher

 view release on metacpan or  search on metacpan

lib/AnyEvent/Filesys/Watcher/FSEvents.pm  view on Meta::CPAN

package AnyEvent::Filesys::Watcher::FSEvents;

use strict;

our $VERSION = 'v0.1.1'; # VERSION

use AnyEvent;
use Mac::FSEvents;
use Scalar::Util qw(weaken);
use Config;

use base qw(AnyEvent::Filesys::Watcher);

# Needed for counting unset bits.
our $THREES = 0x3333_3333;
our $FIVES = 0x5555_5555;
for (my $shift = $Config{ivsize}; $shift -= 4; $shift > 4) {
	$THREES = ($THREES << 8) | 0x3333_3333;
	$FIVES = ($FIVES << 8) | 0x5555_5555;

lib/AnyEvent/Filesys/Watcher/FSEvents.pm  view on Meta::CPAN


	# Create an AnyEvent->io watcher for each fs_monitor
	my $alter_ego = $self;
	$self->{__mac_fh} = $fs_monitor->watch;

	my $watcher = AE::io $self->{__mac_fh}, 0, sub {
		if (my @raw_events = $fs_monitor->read_events) {
			$alter_ego->_processEvents(@raw_events);
		}
	};
	weaken $alter_ego;

	$self->_watcher($watcher);

	return $self;
}

if ($has_file_events) {
	sub _parseEvents {
		my ($self, $filter, @raw_events) = @_;

lib/AnyEvent/Filesys/Watcher/Fallback.pm  view on Meta::CPAN

package AnyEvent::Filesys::Watcher::Fallback;

use strict;

our $VERSION = 'v0.1.1'; # VERSION

use Locale::TextDomain ('AnyEvent-Filesys-Watcher');

use AnyEvent;
use Scalar::Util qw(weaken);

use base qw(AnyEvent::Filesys::Watcher);

sub new {
	my ($class, %args) = @_;

	my $self = $class->SUPER::_new(%args);

	my $alter_ego = $self;
	my $impl = AnyEvent->timer(
		after => $self->interval,
		interval => $self->interval,
		cb => sub {
			$alter_ego->_processEvents();
		}
	);
	weaken $alter_ego;

	if (!$impl) {
		die __x("Error creating timer: {error}\n", error => $@);
	}

	$self->_watcher($impl);

	return $self;
}

lib/AnyEvent/Filesys/Watcher/Inotify2.pm  view on Meta::CPAN

use strict;

our $VERSION = 'v0.1.1'; # VERSION

use Locale::TextDomain ('AnyEvent-Filesys-Watcher');

use AnyEvent;
use Linux::Inotify2;
use Carp;
use Path::Iterator::Rule;
use Scalar::Util qw(weaken);

use base qw(AnyEvent::Filesys::Watcher);

sub new {
	my ($class, %args) = @_;

	my $self = $class->SUPER::_new(%args);

	my $inotify = Linux::Inotify2->new
		or croak "Unable to create new Linux::INotify2 object: $!";

lib/AnyEvent/Filesys/Watcher/Inotify2.pm  view on Meta::CPAN


	my $alter_ego = $self;
	for my $dir (@dirs) {
		$inotify->watch(
			$dir,
			IN_MODIFY | IN_CREATE | IN_DELETE | IN_DELETE_SELF |
				IN_MOVE | IN_MOVE_SELF | IN_ATTRIB,
			sub { my $e = shift; $alter_ego->_processEvents($e); }
		);
	}
	weaken $alter_ego;

	$self->_filesystemMonitor($inotify);

	$self->_watcher([AnyEvent->io(
		fh => $inotify->fileno,
		poll => 'r',
		cb => sub {
			$inotify->poll;
		}
	)]);

lib/AnyEvent/Filesys/Watcher/KQueue.pm  view on Meta::CPAN


use strict;

our $VERSION = 'v0.1.1'; # VERSION

use Locale::TextDomain ('AnyEvent-Filesys-Watcher');

use AnyEvent;
use IO::KQueue;
use Errno qw(:POSIX);
use Scalar::Util qw(weaken);

use base qw(AnyEvent::Filesys::Watcher);

# Arbitrary default limit on open filehandles before we issue a warning.
our $WARN_FILEHANDLE_LIMIT = 128;

# And now try to be more accurate.
eval {
	require BSD::Resource;

lib/AnyEvent/Filesys/Watcher/KQueue.pm  view on Meta::CPAN

	}

	# Now use AE to watch the KQueue.
	my $w;
	my $alter_ego = $self;
	$w = AE::io $$kqueue, 0, sub {
		if (my @events = $kqueue->kevent) {
			$alter_ego->_processEvents(@events);
		}
	};
	weaken $alter_ego;
	$watcher->{w} = $w;

	$self->_checkFilehandleCount;

	return $self;
}

# Need to add newly created items (directories and files) or remove deleted
# items.  This isn't going to be perfect. If the path is not canonical then we
# won't deleted it.  This is done after filtering. So entire dirs can be

lib/AnyEvent/Filesys/Watcher/ReadDirectoryChanges.pm  view on Meta::CPAN

package AnyEvent::Filesys::Watcher::ReadDirectoryChanges;

use strict;

our $VERSION = 'v0.1.1'; # VERSION

use Locale::TextDomain ('AnyEvent-Filesys-Watcher');

use AnyEvent;
use Filesys::Notify::Win32::ReadDirectoryChanges;
use Scalar::Util qw(weaken);
use File::Spec;
use Cwd;
use AnyEvent::Filesys::Watcher::Event;
use AnyEvent::Filesys::Watcher::ReadDirectoryChanges::Queue;

use base qw(AnyEvent::Filesys::Watcher);

sub new {
	my ($class, %args) = @_;

lib/AnyEvent/Filesys/Watcher/ReadDirectoryChanges.pm  view on Meta::CPAN

	my $io = AE::io $queue->handle, 0, sub {
		my $pending = $watcher->queue->pending;
		if ($pending) {
			my @raw_events = $watcher->queue->dequeue($pending);

			$alter_ego->_processEvents(
				@raw_events
			);
		}
	};
	weaken $alter_ego;

	$self->_watcher($io);

	return $self;
}

sub _parseEvents {
	my ($self, $filter, @all_events) = @_;

	my %events;



( run in 0.344 second using v1.01-cache-2.11-cpan-65fba6d93b7 )