File-ChangeNotify-0.24/0000755000175000017500000000000012245662027014540 5ustar autarchautarchFile-ChangeNotify-0.24/dist.ini0000644000175000017500000000230712245662027016206 0ustar autarchautarchname = File-ChangeNotify author = Dave Rolsky license = Artistic_2_0 copyright_holder = Dave Rolsky version = 0.24 [NextRelease] format = %-6v %{yyyy-MM-dd}d [@Filter] bundle = @Basic remove = MakeMaker remove = ModuleBuild [=inc::MyModuleBuild] [InstallGuide] [MetaJSON] [MetaResources] bugtracker.web = http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-ChangeNotify bugtracker.mailto = bug-file-changenotify@rt.cpan.org repository.url = git://git.urth.org/File-ChangeNotify.git repository.web = http://git.urth.org/File-ChangeNotify.git repository.type = git [SurgicalPodWeaver] [PkgVersion] [EOLTests] ; fails because of the Module::Build ConfigData module ;[NoTabsTests] [PodSyntaxTests] [Test::CPAN::Changes] ; fails because of the KQueue module ;[Test::Compile] ; fails because it can't find IO::KQueue or login.conf(5) ;[Test::Pod::LinkCheck] [Test::Pod::No404s] [Test::PodSpelling] stopwords = distro stopwords = userspace stopwords = FreeBSD stopwords = Linux's stopwords = OpenBSD [Test::Synopsis] [CheckChangeLog] [AutoPrereqs] skip = IO::KQueue skip = Linux::Inotify2 skip = Test::Spelling [Prereqs / ConfigureRequires] Module::Build = 0 [CheckPrereqsIndexed] [@Git] File-ChangeNotify-0.24/README0000644000175000017500000000041212245662027015415 0ustar autarchautarch This archive contains the distribution File-ChangeNotify, version 0.24: Watch for changes to files, cross-platform style This software is Copyright (c) 2013 by Dave Rolsky. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) File-ChangeNotify-0.24/Build.PL0000644000175000017500000000355412245662027016043 0ustar autarchautarch use strict; use warnings; use Module::Build 0.3601; my %module_build_args = ( "auto_features" => { "Inotify" => { "description" => "Inotify support", "requires" => { "Linux::Inotify2" => "1.2" } }, "KQueue" => { "description" => "KQueue support", "requires" => { "IO::KQueue" => 0 } } }, "build_requires" => { "Module::Build" => "0.3601" }, "configure_requires" => { "Module::Build" => "0.3601" }, "dist_abstract" => "Watch for changes to files, cross-platform style", "dist_author" => [ "Dave Rolsky " ], "dist_name" => "File-ChangeNotify", "dist_version" => "0.24", "license" => "artistic_2", "module_name" => "File::ChangeNotify", "recommends" => {}, "recursive_test_files" => 1, "requires" => { "Carp" => 0, "Class::Load" => 0, "File::Find" => 0, "File::Spec" => 0, "List::MoreUtils" => 0, "Module::Pluggable::Object" => 0, "Moose" => 0, "Moose::Util::TypeConstraints" => 0, "MooseX::Params::Validate" => 0, "MooseX::SemiAffordanceAccessor" => 0, "Time::HiRes" => 0, "namespace::autoclean" => 0, "strict" => 0, "warnings" => 0 }, "script_files" => [], "test_requires" => { "Data::Dumper" => 0, "Exporter" => 0, "File::Path" => 0, "File::Temp" => 0, "FindBin" => 0, "Test::Exception" => 0, "Test::More" => 0, "base" => 0, "lib" => 0 } ); unless ( eval { Module::Build->VERSION(0.4004) } ) { my $tr = delete $module_build_args{test_requires}; my $br = $module_build_args{build_requires}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } my $build = Module::Build->new(%module_build_args); $build->create_build_script; File-ChangeNotify-0.24/t/0000755000175000017500000000000012245662027015003 5ustar autarchautarchFile-ChangeNotify-0.24/t/release-try-load.t0000644000175000017500000000111312245662027020335 0ustar autarchautarch BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; use File::ChangeNotify; ok( File::ChangeNotify::_try_load('File::ChangeNotify::Watcher::Default'), 'can load Default watcher' ); ok( File::ChangeNotify::_try_load('File::ChangeNotify::Watcher::Inotify'), 'can load Inotify watcher' ); ok( !File::ChangeNotify::_try_load('File::ChangeNotify::Watcher::KQueue'), 'cannot load KQueue watcher' ); done_testing(); File-ChangeNotify-0.24/t/release-pod-no404s.t0000644000175000017500000000076512245662027020425 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; foreach my $env_skip ( qw( SKIP_POD_NO404S AUTOMATED_TESTING ) ){ plan skip_all => "\$ENV{$env_skip} is set, skipping" if $ENV{$env_skip}; } eval "use Test::Pod::No404s"; if ( $@ ) { plan skip_all => 'Test::Pod::No404s required for testing POD'; } else { all_pod_files_ok(); } File-ChangeNotify-0.24/t/all.t0000644000175000017500000000017712245662027015745 0ustar autarchautarchuse strict; use warnings; use lib 't/lib'; use File::ChangeNotify::TestHelper; File::ChangeNotify::TestHelper::run_tests(); File-ChangeNotify-0.24/t/release-pod-syntax.t0000644000175000017500000000045012245662027020713 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); File-ChangeNotify-0.24/t/release-cpan-changes.t0000644000175000017500000000052112245662027021133 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More 0.96 tests => 2; use_ok('Test::CPAN::Changes'); subtest 'changes_ok' => sub { changes_file_ok('Changes'); }; done_testing(); File-ChangeNotify-0.24/t/lib/0000755000175000017500000000000012245662027015551 5ustar autarchautarchFile-ChangeNotify-0.24/t/lib/File/0000755000175000017500000000000012245662027016430 5ustar autarchautarchFile-ChangeNotify-0.24/t/lib/File/ChangeNotify/0000755000175000017500000000000012245662027021006 5ustar autarchautarchFile-ChangeNotify-0.24/t/lib/File/ChangeNotify/TestHelper.pm0000644000175000017500000002476412245662027023440 0ustar autarchautarchpackage File::ChangeNotify::TestHelper; use strict; use warnings; use File::ChangeNotify; use File::Temp qw( tempdir ); use File::Path qw( mkpath rmtree ); use Test::Exception; use Test::More; use base 'Exporter'; our @EXPORT = qw( run_tests ); our $_DESC; sub run_tests { my @classes = 'File::ChangeNotify::Watcher::Default'; push @classes, File::ChangeNotify->usable_classes(); for my $class (@classes) { ( my $short = $class ) =~ s/^File::ChangeNotify::Watcher:://; local $_DESC = "[with $short - blocking]"; _shared_tests( $class, \&_blocking ); local $_DESC = "[with $short - nonblocking]"; _shared_tests( $class, \&_nonblocking ); _exclude_tests($class, \&_nonblocking); _symlink_tests($class); } done_testing(); } sub _blocking { my $watcher = shift; return $watcher->wait_for_events(); } sub _nonblocking { my $watcher = shift; return $watcher->new_events(); } sub _shared_tests { _basic_tests(@_); _multi_event_tests(@_); _filter_tests(@_); _dir_add_remove_tests(@_); } sub _basic_tests { my $class = shift; my $events_sub = shift; my $dir = tempdir( CLEANUP => 1 ); my $watcher = $class->new( directories => $dir, follow_symlinks => 0, sleep_interval => 0, ); my $path = "$dir/whatever"; create_file($path); _check_events( 1, [ $events_sub->($watcher) ], [ { path => $path, type => 'create', }, ], "added one file ($path)", ); modify_file($path); _check_events( 1, [ $events_sub->($watcher) ], [ { path => $path, type => 'modify', }, ], "modified one file ($path)", ); delete_file($path); _check_events( 1, [ $events_sub->($watcher) ], [ { path => $path, type => 'delete', }, ], "deleted one file ($path)", ); } sub _multi_event_tests { my $class = shift; my $events_sub = shift; my $dir = tempdir( CLEANUP => 1 ); my $watcher = $class->new( directories => $dir, follow_symlinks => 0, sleep_interval => 0, ); my $path1 = "$dir/whatever"; create_file($path1); modify_file($path1); delete_file($path1); my $path2 = "$dir/another"; create_file($path2); modify_file($path2); if ( $watcher->sees_all_events() ) { _check_events( 5, [ $events_sub->($watcher) ], [ { path => $path1, type => 'create', }, { path => $path1, type => 'modify', }, { path => $path1, type => 'delete', }, { path => $path2, type => 'create', }, { path => $path2, type => 'modify', }, ], "added/modified/deleted $path1 and added/modified $path2", ); } else { _check_events( 1, [ $events_sub->($watcher) ], [ { path => $path2, type => 'create', }, ], "added/modified/deleted $path1 and added/modified $path2", ); } } sub _filter_tests { my $class = shift; my $events_sub = shift; my $dir = tempdir( CLEANUP => 1 ); my $watcher = $class->new( directories => $dir, follow_symlinks => 0, filter => qr/^foo/, sleep_interval => 0, ); my $path1 = "$dir/not-included"; create_file($path1); modify_file($path1); delete_file($path1); my $path2 = "$dir/foo.txt"; create_file($path2); _check_events( 1, [ $events_sub->($watcher) ], [ { path => $path2, type => 'create', }, ], 'file not matching filter is ignored but foo.txt is noted', ); } sub _dir_add_remove_tests { my $class = shift; my $events_sub = shift; my $dir = tempdir( CLEANUP => 1 ); my $watcher = $class->new( directories => $dir, follow_symlinks => 0, sleep_interval => 0, ); my $subdir1 = "$dir/subdir1"; my $subdir2 = "$dir/subdir2"; mkpath( $subdir1, 0, 0755 ); rmtree($subdir1); mkpath( $subdir2, 0, 0755 ); my $path = "$subdir2/whatever"; create_file($path); if ( $watcher->sees_all_events() ) { _check_events( 4, [ $events_sub->($watcher) ], [ { path => $subdir1, type => 'create', }, { path => $subdir1, type => 'delete', }, { path => $subdir2, type => 'create', }, { path => $path, type => 'create', }, ], "created/delete $subdir1 and created one file ($path) in a new subdir ($subdir2)", ); } else { _check_events( 2, [ $events_sub->($watcher) ], [ { path => $subdir2, type => 'create', }, { path => $path, type => 'create', }, ], "created/delete $subdir1 and created one file ($path) in a new subdir ($subdir2)", ); } rmtree($subdir2); _check_events( 2, # The Default & Inotify watchers have different orders for these events [ sort { $a->path() cmp $b->path() } $events_sub->($watcher) ], [ { path => $subdir2, type => 'delete', }, { path => $path, type => 'delete', }, ], "deleted $subdir2", ); } sub _exclude_tests { my $class = shift; my $events_sub = shift; my $dir = tempdir( CLEANUP => 1 ); my $watcher = $class->new( directories => $dir, follow_symlinks => 0, sleep_interval => 0, exclude => [ qr/\bignored-dir\b/, qr/\.ignore$/, ], ); my $included = "$dir/include"; create_file($included); _check_events( 1, [ $events_sub->($watcher) ], [ { path => $included, type => 'create', }, ], "added/modified/deleted $included", ); mkpath( "$dir/ignored-dir", 0, 0755 ); my $excluded_dir = "$dir/ignored-dir/foo"; create_file($excluded_dir); _check_events( 0, [ $events_sub->($watcher) ], [], "created $excluded_dir - should be ignored", ); my $excluded_file = "$dir/foo.ignore"; create_file($excluded_file); _check_events( 0, [ $events_sub->($watcher) ], [], "created $excluded_file - should be ignored", ); } sub _symlink_tests { my $class = shift; my $dir1 = tempdir( CLEANUP => 1 ); my $dir2 = tempdir( CLEANUP => 1 ); my $symlink = "$dir1/other"; SKIP: { skip 'This platform does not support symlinks.', 3 unless eval { symlink $dir2 => $symlink }; my $watcher = $class->new( directories => $dir1, follow_symlinks => 0, sleep_interval => 0, ); my $path = "$dir2/file"; create_file($path); delete_file($path); _check_events( 0, [ $watcher->new_events() ], [], 'no events for symlinked dir when not following symlinks', ); $watcher = $class->new( directories => $dir1, follow_symlinks => 1, sleep_interval => 0, ); create_file($path); my $expected_path = "$symlink/file"; _check_events( 1, [ $watcher->new_events() ], [ { path => $expected_path, type => 'create', }, ], 'one event for symlinked dir when following symlinks', ); my $dir3 = tempdir( CLEANUP => 1 ); symlink "$dir3/.", "$dir3/self"; symlink "$dir3/input-circular1", "$dir3/input-circular2"; symlink "$dir3/input-circular2", "$dir3/input-circular1"; lives_ok { File::ChangeNotify->instantiate_watcher( directories => $dir3, follow_symlinks => 1, ); } 'made watcher for directory with circular symlinks'; } } sub _check_events { my $count = shift; my $got_events = shift; my $expect_events = shift; my $desc = shift; local $Test::Builder::Level = $Test::Builder::Level + 1; my $noun = $count == 1 ? 'event' : 'events'; is( scalar @{$got_events}, $count, "got $count $noun $_DESC" ) or do { use Data::Dumper; diag Dumper $got_events }; return unless $count; _is_events( $got_events, $expect_events, $desc, ); } sub _is_events { my $got = shift; my $expected = shift; my $desc = shift; local $Test::Builder::Level = $Test::Builder::Level + 1; is_deeply( [ map { { path => $_->path(), type => $_->type() } } @{$got} ], $expected, "$desc $_DESC" ); } sub create_file { my $path = shift; diag("Creating $path"); open my $fh, '>', $path or die "Cannot write to $path: $!"; close $fh or die "Cannot write to $path: $!"; } sub modify_file { my $path = shift; diag("Modifying $path"); die "No such file $path!\n" unless -f $path; open my $fh, '>>', $path or die "Cannot write to $path: $!"; print {$fh} "1\n" or die "Cannot write to $path: $!"; close $fh or die "Cannot write to $path: $!"; } sub delete_file { my $path = shift; diag("Deleting $path"); die "No such file $path!\n" unless -f $path; unlink $path or die "Cannot unlink $path: $!"; } 1; File-ChangeNotify-0.24/t/excluded-dirs.t0000644000175000017500000000174412245662027017732 0ustar autarchautarchuse strict; use warnings; use FindBin; use File::ChangeNotify::Watcher; use File::Spec; use Test::More; my $root = File::Spec->catfile( $FindBin::Bin, '..' ); sub f { File::Spec->catfile( $root, @_ ) } my $watcher = File::ChangeNotify::Watcher->new( directories => f(), exclude => [ f('foo'), f('bar'), f( 'excluded', 'dir' ), qr{(?:\\|/)r[^\\/]+$}, qr{(?:\\|/)\.[^\\/]*$}, ] ); ok( !$watcher->_path_is_excluded( f('quux') ), 'included dir' ); ok( $watcher->_path_is_excluded( f('foo') ), 'excluded dir' ); ok( !$watcher->_path_is_excluded( f( 'foo', 'bar' ) ), 'subdirs not excluded with string exclusion' ); ok( $watcher->_path_is_excluded( f( 'left', 'right' ) ), 'excluded by regex' ); ok( $watcher->_path_is_excluded( f('.hidden') ), 'excluding hidden dirs with regex' ); ok( !$watcher->_path_is_excluded( f( '.hidden', 'file' ) ), 'hidden dir regex does not exclude subdirs' ); done_testing(); File-ChangeNotify-0.24/t/release-eol.t0000644000175000017500000000047612245662027017374 0ustar autarchautarch BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; eval 'use Test::EOL'; plan skip_all => 'Test::EOL required' if $@; all_perl_files_ok({ trailing_whitespace => 1 }); File-ChangeNotify-0.24/t/author-pod-spell.t0000644000175000017500000000102412245662027020364 0ustar autarchautarch BEGIN { unless ($ENV{AUTHOR_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for testing by the author'); } } use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.004003 eval "use Test::Spelling 0.12; use Pod::Wordlist::hanekomu; 1" or die $@; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ distro userspace FreeBSD Linux's OpenBSD Dave Rolsky autarch lib File ChangeNotify Event Watcher Inotify KQueue Default File-ChangeNotify-0.24/t/instantiate-twice.t0000644000175000017500000000107512245662027020627 0ustar autarchautarchuse strict; use warnings; use Test::More; eval 'use Test::Without::Module qw( Linux::Inotify2 )'; plan skip_all => 'This test requires Test::Without::Module' if $@; use File::ChangeNotify; my $watcher1 = File::ChangeNotify->instantiate_watcher( directories => 't' ); my $watcher2 = File::ChangeNotify->instantiate_watcher( directories => 't' ); ok( $watcher1->isa('File::ChangeNotify::Watcher'), 'first isa File::ChangeNotify::Watcher' ); ok( $watcher2->isa('File::ChangeNotify::Watcher'), 'second isa File::ChangeNotify::Watcher' ); done_testing(); File-ChangeNotify-0.24/t/release-synopsis.t0000644000175000017500000000046312245662027020500 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Synopsis"; plan skip_all => "Test::Synopsis required for testing synopses" if $@; all_synopsis_ok('lib'); File-ChangeNotify-0.24/META.yml0000644000175000017500000000177112245662027016017 0ustar autarchautarch--- abstract: 'Watch for changes to files, cross-platform style' author: - 'Dave Rolsky ' build_requires: Data::Dumper: 0 Exporter: 0 File::Path: 0 File::Temp: 0 FindBin: 0 Module::Build: 0.3601 Test::Exception: 0 Test::More: 0 base: 0 lib: 0 configure_requires: Module::Build: 0.3601 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300039, CPAN::Meta::Converter version 2.131560' license: artistic_2 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: File-ChangeNotify requires: Carp: 0 Class::Load: 0 File::Find: 0 File::Spec: 0 List::MoreUtils: 0 Module::Pluggable::Object: 0 Moose: 0 Moose::Util::TypeConstraints: 0 MooseX::Params::Validate: 0 MooseX::SemiAffordanceAccessor: 0 Time::HiRes: 0 namespace::autoclean: 0 strict: 0 warnings: 0 resources: bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-ChangeNotify repository: git://git.urth.org/File-ChangeNotify.git version: 0.24 File-ChangeNotify-0.24/LICENSE0000644000175000017500000002152012245662027015545 0ustar autarchautarchThis software is Copyright (c) 2013 by Dave Rolsky. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) The Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. File-ChangeNotify-0.24/inc/0000755000175000017500000000000012245662027015311 5ustar autarchautarchFile-ChangeNotify-0.24/inc/MyModuleBuild.pm0000644000175000017500000000112212245662027020356 0ustar autarchautarchpackage inc::MyModuleBuild; use strict; use warnings; use Moose; extends 'Dist::Zilla::Plugin::ModuleBuild'; around module_build_args => sub { my $orig = shift; my $self = shift; my $args = $self->$orig(@_); $args->{auto_features} = { Inotify => { description => 'Inotify support', requires => { 'Linux::Inotify2' => '1.2' }, }, KQueue => { description => 'KQueue support', requires => { 'IO::KQueue' => '0' }, } }; return $args; }; __PACKAGE__->meta()->make_immutable(); 1; File-ChangeNotify-0.24/lib/0000755000175000017500000000000012245662027015306 5ustar autarchautarchFile-ChangeNotify-0.24/lib/File/0000755000175000017500000000000012245662027016165 5ustar autarchautarchFile-ChangeNotify-0.24/lib/File/ChangeNotify/0000755000175000017500000000000012245662027020543 5ustar autarchautarchFile-ChangeNotify-0.24/lib/File/ChangeNotify/Event.pm0000644000175000017500000000327012245662027022164 0ustar autarchautarchpackage File::ChangeNotify::Event; { $File::ChangeNotify::Event::VERSION = '0.24'; } use strict; use warnings; use namespace::autoclean; use Moose; use Moose::Util::TypeConstraints; has path => ( is => 'ro', isa => 'Str', required => 1, ); has type => ( is => 'ro', isa => enum( [qw( create modify delete unknown )] ), required => 1, ); __PACKAGE__->meta()->make_immutable(); 1; # ABSTRACT: Class for file change events __END__ =pod =head1 NAME File::ChangeNotify::Event - Class for file change events =head1 VERSION version 0.24 =head1 SYNOPSIS my $watcher = File::ChangeNotify->instantiate_watcher( directories => [ '/my/path', '/my/other' ], filter => qr/\.(?:pm|conf|yml)$/, exclude => [ 't', 'root', qr(/(?!\.)[^/]+$) ], ); for my $event ( $watcher->new_events() ) { print $event->path(), ' - ', $event->type(), "\n"; } =head1 DESCRIPTION This class provides information about a change to a specific file or directory. =head1 METHODS =head2 File::ChangeNotify::Event->new(...) This method creates a new event. It accepts the following arguments: =over 4 =item * path => $path The full path to the file or directory that changed. =item * type => $type The type of event. This must be one of "create", "modify", "delete", or "unknown". =back =head2 $event->path() Returns the path of the changed file or directory. =head2 $event->type() Returns the type of event. =head1 AUTHOR Dave Rolsky =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by Dave Rolsky. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) =cut File-ChangeNotify-0.24/lib/File/ChangeNotify/Watcher/0000755000175000017500000000000012245662027022140 5ustar autarchautarchFile-ChangeNotify-0.24/lib/File/ChangeNotify/Watcher/Default.pm0000644000175000017500000001015112245662027024060 0ustar autarchautarchpackage File::ChangeNotify::Watcher::Default; { $File::ChangeNotify::Watcher::Default::VERSION = '0.24'; } use strict; use warnings; use namespace::autoclean; use File::Find qw( finddepth ); use File::Spec; use Time::HiRes qw( sleep ); # Trying to import this just blows up on Win32, and checking # Time::HiRes::d_hires_stat() _also_ blows up on Win32. BEGIN { eval { Time::HiRes->import('stat') }; } use Moose; use MooseX::SemiAffordanceAccessor; extends 'File::ChangeNotify::Watcher'; has _map => ( is => 'rw', isa => 'HashRef', default => sub { {} }, ); sub sees_all_events {0} sub BUILD { my $self = shift; $self->_set_map( $self->_build_map() ); } sub _build_map { my $self = shift; my %map; File::Find::find( { wanted => sub { my $path = $File::Find::name; if ( $self->_path_is_excluded($path) ) { $File::Find::prune = 1; return; } my $entry = $self->_entry_for_map($path) or return; $map{$path} = $entry; }, follow_fast => ( $self->follow_symlinks() ? 1 : 0 ), no_chdir => 1, follow_skip => 2, }, @{ $self->directories() }, ); return \%map; } sub _entry_for_map { my $self = shift; my $path = shift; my $is_dir = -d $path ? 1 : 0; return if -l $path && !$is_dir; unless ($is_dir) { my $filter = $self->filter(); return unless ( File::Spec->splitpath($path) )[2] =~ /$filter/; } return { is_dir => $is_dir, mtime => _mtime(*_), size => ( $is_dir ? 0 : -s _ ), }; } # It seems that Time::HiRes's stat does not act exactly like the # built-in, so if I do ( stat _ )[9] it will not work (grr). sub _mtime { my @stat = stat; return $stat[9]; } sub wait_for_events { my $self = shift; while (1) { my @events = $self->_interesting_events(); return @events if @events; sleep $self->sleep_interval(); } } sub _interesting_events { my $self = shift; my @interesting; my $old_map = $self->_map(); my $new_map = $self->_build_map(); for my $path ( sort keys %{$old_map} ) { if ( !exists $new_map->{$path} ) { if ( $old_map->{$path}{is_dir} ) { $self->_remove_directory($path); } push @interesting, $self->event_class()->new( path => $path, type => 'delete', ); } elsif ( !$old_map->{$path}{is_dir} && ( $old_map->{$path}{mtime} != $new_map->{$path}{mtime} || $old_map->{$path}{size} != $new_map->{$path}{size} ) ) { push @interesting, $self->event_class()->new( path => $path, type => 'modify', ); } } for my $path ( sort grep { !exists $old_map->{$_} } keys %{$new_map} ) { if ( -d $path ) { push @interesting, $self->event_class()->new( path => $path, type => 'create', ), ; } else { push @interesting, $self->event_class()->new( path => $path, type => 'create', ); } } $self->_set_map($new_map); return @interesting; } __PACKAGE__->meta()->make_immutable(); 1; # ABSTRACT: Fallback default watcher subclass __END__ =pod =head1 NAME File::ChangeNotify::Watcher::Default - Fallback default watcher subclass =head1 VERSION version 0.24 =head1 DESCRIPTION This class implements watching by comparing two snapshots of the filesystem tree. It if inefficient and dumb, and so it is the subclass of last resort. Its C<< $watcher->wait_for_events() >> method sleeps between comparisons of the filesystem snapshot it takes. =head1 AUTHOR Dave Rolsky =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by Dave Rolsky. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) =cut File-ChangeNotify-0.24/lib/File/ChangeNotify/Watcher/KQueue.pm0000644000175000017500000001471112245662027023701 0ustar autarchautarchpackage File::ChangeNotify::Watcher::KQueue; { $File::ChangeNotify::Watcher::KQueue::VERSION = '0.24'; } use strict; use warnings; use namespace::autoclean; use Moose; use File::Find (); use IO::KQueue; extends 'File::ChangeNotify::Watcher'; has absorb_delay => ( is => 'ro', isa => 'Int', default => 100, ); has _kqueue => ( is => 'ro', isa => 'IO::KQueue', default => sub { IO::KQueue->new }, init_arg => undef, ); # We need to keep hold of filehandles for all the directories *and* files in the # tree. KQueue events will be automatically deleted when the filehandles go out # of scope. has _files => ( is => 'ro', isa => 'HashRef', default => sub { {} }, init_arg => undef, ); sub sees_all_events {0} sub BUILD { my ($self) = @_; $self->_watch_dir($_) for @{ $self->directories }; } sub wait_for_events { my ($self) = @_; while (1) { my @events = $self->_get_events; return @events if @events; } } sub new_events { my ($self) = @_; my @events = $self->_get_events(0); } sub _get_events { my ( $self, $timeout ) = @_; my @kevents = $self->_kqueue->kevent( defined $timeout ? $timeout : () ); # Events come in groups, wait for a short period to absorb any extra ones # that might happen immediately after the ones we've detected. push @kevents, $self->_kqueue->kevent( $self->absorb_delay ) if $self->absorb_delay; my @events; foreach my $kevent (@kevents) { my $path = $kevent->[KQ_UDATA]; next if $self->_path_is_excluded($path); my $flags = $kevent->[KQ_FFLAGS]; # Delete - this works reasonably well with KQueue if ( $flags & NOTE_DELETE ) { delete $self->_files->{$path}; push @events, $self->_event( $path, 'delete' ); } # Rename - represented as deletes and creates elsif ( $flags & NOTE_RENAME ) { # Renamed dirs # Use the stored filehandle (it survives renaming) to identify a dir # and remove any filehandles we're storing to its contents my $fh = $self->_files->{$path}; if ( -d $fh ) { foreach my $stored_path ( keys %{ $self->_files } ) { next unless index( $stored_path, $path ) == 0; delete $self->_files->{$stored_path}; push @events, $self->_event( $stored_path, 'delete' ); } } # Renamed files else { delete $self->_files->{$path}; push @events, $self->_event( $path, 'delete' ); } } # Modify/Create - writes to files indicate modification, but we get # writes to dirs too, which indicates a file (or dir) was created or # removed from the dir. Deletes are picked up by delete events, but to # find created files we have to scan the dir again. elsif ( $flags & NOTE_WRITE ) { if ( -f $path ) { push @events, $self->_event( $path, 'modify' ); } elsif ( -d $path ) { push @events, map { $self->_event( $_, 'create' ) } $self->_watch_dir($path); } } } return @events; } sub _event { my ( $self, $path, $type ) = @_; return $self->event_class->new( path => $path, type => $type ); } sub _watch_dir { my ( $self, $dir ) = @_; my @new_files; # use find(), finddepth() doesn't support pruning $self->_find( $dir, sub { my $path = $File::Find::name; # Don't monitor anything below excluded dirs return $File::Find::prune = 1 if $self->_path_is_excluded($path); # Skip file names that don't match the filter return unless $self->_is_included_file($path); # Skip if we're watching it already return if $self->_files->{$path}; $self->_watch_file($path); push @new_files, $path; } ); return @new_files; } sub _is_included_file { my ( $self, $path ) = @_; return 1 if -d $path; my $filter = $self->filter; my $filename = ( File::Spec->splitpath($path) )[2]; return 1 if $filename =~ m{$filter}; } sub _find { my ( $self, $dir, $wanted ) = @_; File::Find::find( { wanted => $wanted, no_chdir => 1, follow_fast => ( $self->follow_symlinks ? 1 : 0 ),, follow_skip => 2, }, $dir, ); } sub _watch_file { my ( $self, $file ) = @_; # Don't panic if we can't open a file open my $fh, '<', $file or warn "Can't open '$file': $!"; return unless $fh && defined fileno $fh; # Store this filehandle (this will automatically nuke any existing events # assigned to the file) $self->_files->{$file} = $fh; # Watch it for changes $self->_kqueue->EV_SET( fileno($fh), EVFILT_VNODE, EV_ADD | EV_CLEAR, NOTE_DELETE | NOTE_WRITE | NOTE_RENAME | NOTE_REVOKE, 0, $file, ); } __PACKAGE__->meta->make_immutable; 1; __END__ =head1 NAME File::ChangeNotify::Watcher::KQueue - KQueue-based watcher subclass =head1 DESCRIPTION This class implements watching using L, which must be installed for it to work. This is a BSD alternative to Linux's Inotify and similar event-based systems. =head1 CAVEATS Although this watcher is more efficient and accurate than the C class, in order to monitor files and directories, it must open filehandles to each of them. Because many BSD systems have relatively low defaults for the maximum number of files each process can open, you may find you run out of file descriptors. On FreeBSD, you can check (and alter) your system's settings with C if necessary. The important keys are: C and C. You can see how many files your system current has open with C. On OpenBSD, the C keys are C and C. Per-process limits are set in F. See L for details. =head1 SUPPORT I (Dave Rolsky) cannot test this class, as I have no BSD systems. Reasonable patches will be applied as-is, and when possible I will consult with Dan Thomas or other BSD users before releasing. =head1 AUTHOR Dan Thomas, Edan@cpan.orgE =cut File-ChangeNotify-0.24/lib/File/ChangeNotify/Watcher/Inotify.pm0000644000175000017500000001254112245662027024122 0ustar autarchautarchpackage File::ChangeNotify::Watcher::Inotify; { $File::ChangeNotify::Watcher::Inotify::VERSION = '0.24'; } use strict; use warnings; use namespace::autoclean; use File::Find (); use Linux::Inotify2 1.2; use Moose; extends 'File::ChangeNotify::Watcher'; has is_blocking => ( is => 'ro', isa => 'Bool', default => 1, ); has _inotify => ( is => 'ro', isa => 'Linux::Inotify2', default => sub { Linux::Inotify2->new() or die "Cannot construct a Linux::Inotify2 object: $!"; }, init_arg => undef, ); has _mask => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build_mask', ); sub sees_all_events {1} sub BUILD { my $self = shift; $self->_inotify()->blocking( $self->is_blocking() ); # If this is done via a lazy_build then the call to # ->_watch_directory ends up causing endless recursion when it # calls ->_inotify itself. $self->_watch_directory($_) for @{ $self->directories() }; return $self; } sub wait_for_events { my $self = shift; $self->_inotify()->blocking(1); while (1) { my @events = $self->_interesting_events(); return @events if @events; } } override new_events => sub { my $self = shift; $self->_inotify()->blocking(0); super(); }; sub _interesting_events { my $self = shift; my $filter = $self->filter(); my @interesting; # This may be a blocking read, in which case it will not return until # something happens. For Catalyst, the restarter will end up calling # ->watch again after handling the changes. for my $event ( $self->_inotify()->read() ) { # An excluded path will show up here if ... # # Something created a new directory and that directory needs to be # excluded or when the exclusion excludes a file, not a dir. next if $self->_path_is_excluded( $event->fullname() ); if ( $event->IN_CREATE() && $event->IN_ISDIR() ) { $self->_watch_directory( $event->fullname() ); push @interesting, $event; push @interesting, $self->_fake_events_for_new_dir( $event->fullname() ); } elsif ( $event->IN_DELETE_SELF() ) { $self->_remove_directory( $event->fullname() ); } # We just want to check the _file_ name elsif ( $event->name() =~ /$filter/ ) { push @interesting, $event; } } return map { $_->can('path') ? $_ : $self->_convert_event($_) } @interesting; } sub _build_mask { my $self = shift; my $mask = IN_MODIFY | IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MOVE_SELF; $mask |= IN_DONT_FOLLOW unless $self->follow_symlinks(); return $mask; } sub _watch_directory { my $self = shift; my $dir = shift; # A directory could be created & then deleted before we get a # chance to act on it. return unless -d $dir; File::Find::find( { wanted => sub { my $path = $File::Find::name; if ( $self->_path_is_excluded($path) ) { $File::Find::prune = 1; return; } $self->_add_watch_if_dir($path); }, follow_fast => ( $self->follow_symlinks() ? 1 : 0 ), no_chdir => 1, follow_skip => 2, }, $dir ); } sub _add_watch_if_dir { my $self = shift; my $path = shift; return if -l $path && !$self->follow_symlinks(); return unless -d $path; return if $self->_path_is_excluded($path); $self->_inotify()->watch( $path, $self->_mask() ); } sub _fake_events_for_new_dir { my $self = shift; my $dir = shift; return unless -d $dir; my @events; File::Find::find( { wanted => sub { my $path = $File::Find::name; return if $path eq $dir; if ( $self->_path_is_excluded($path) ) { $File::Find::prune = 1; return; } push @events, $self->event_class()->new( path => $path, type => 'create', ); }, follow_fast => ( $self->follow_symlinks() ? 1 : 0 ), no_chdir => 1 }, $dir ); return @events; } sub _convert_event { my $self = shift; my $event = shift; return $self->event_class()->new( path => $event->fullname(), type => ( $event->IN_CREATE() ? 'create' : $event->IN_MODIFY() ? 'modify' : $event->IN_DELETE() ? 'delete' : 'unknown' ), ); } __PACKAGE__->meta()->make_immutable(); 1; # ABSTRACT: Inotify-based watcher subclass __END__ =pod =head1 NAME File::ChangeNotify::Watcher::Inotify - Inotify-based watcher subclass =head1 VERSION version 0.24 =head1 DESCRIPTION This class implements watching by using the L module. This only works on Linux 2.6.13 or newer. This watcher is much more efficient and accurate than the C class. =head1 AUTHOR Dave Rolsky =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by Dave Rolsky. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) =cut File-ChangeNotify-0.24/lib/File/ChangeNotify/Watcher.pm0000644000175000017500000001404712245662027022504 0ustar autarchautarchpackage File::ChangeNotify::Watcher; { $File::ChangeNotify::Watcher::VERSION = '0.24'; } use strict; use warnings; use namespace::autoclean; use Class::Load qw( load_class ); use File::ChangeNotify::Event; use List::MoreUtils qw(all); use Moose; use Moose::Util::TypeConstraints; use MooseX::Params::Validate qw( pos_validated_list ); has filter => ( is => 'ro', isa => 'RegexpRef', default => sub {qr/.*/}, ); #<<< my $dir = subtype as 'Str', where { -d $_ }, message { "$_ is not a valid directory" }; my $array_of_dirs = subtype as 'ArrayRef[Str]', where { map {-d} @{$_}; }, message {"@{$_} is not a list of valid directories"}; coerce $array_of_dirs, from $dir, via { [$_] }; #>>> has directories => ( is => 'ro', writer => '_set_directories', isa => $array_of_dirs, required => 1, coerce => 1, ); has follow_symlinks => ( is => 'ro', isa => 'Bool', default => 0, ); has event_class => ( is => 'ro', isa => 'ClassName', default => 'File::ChangeNotify::Event', ); has sleep_interval => ( is => 'ro', isa => 'Num', default => 2, ); my $files_or_regexps = subtype as 'ArrayRef[Str|RegexpRef]'; has exclude => ( is => 'ro', isa => $files_or_regexps, default => sub { [] }, ); sub BUILD { my $self = shift; load_class( $self->event_class() ); } sub new_events { my $self = shift; return $self->_interesting_events(); } sub _add_directory { my $self = shift; my $dir = shift; return if grep { $_ eq $dir } $self->directories(); push @{ $self->directories() }, $dir; } sub _path_is_excluded { my $self = shift; my $path = shift; foreach my $excluded ( @{ $self->exclude } ) { if ( ref $excluded && ref $excluded eq 'Regexp' ) { return 1 if $path =~ /$excluded/; } else { return 1 if $path eq $excluded; } } return; } sub _remove_directory { my $self = shift; my $dir = shift; $self->_set_directories( [ grep { $_ ne $dir } @{ $self->directories() } ] ); } __PACKAGE__->meta()->make_immutable(); 1; # ABSTRACT: Base class for all watchers __END__ =pod =head1 NAME File::ChangeNotify::Watcher - Base class for all watchers =head1 VERSION version 0.24 =head1 SYNOPSIS my $watcher = File::ChangeNotify->instantiate_watcher ( directories => [ '/my/path', '/my/other' ], filter => qr/\.(?:pm|conf|yml)$/, exclude => ['t', 'root', qr(/(?!\.)[^/]+$)], ); if ( my @events = $watcher->new_events() ) { ... } # blocking while ( my @events = $watcher->wait_for_events() ) { ... } =head1 DESCRIPTION A C class monitors a directory for changes made to any file. You can provide a regular expression to filter out files you are not interested in. It handles the addition of new subdirectories by adding them to the watch list. Note that the actual granularity of what each watcher subclass reports may vary across subclasses. Implementations that hook into some sort of kernel event interface (Inotify, for example) have much better knowledge of exactly what changes are happening than one implemented purely in userspace code (like the Default subclass). By default, events are returned in the form L objects, but this can be overridden by providing an "event_class" attribute to the constructor. The watcher can operate in a blocking/callback style, or you can simply ask it for a list of new events as needed. =head1 METHODS =head2 File::ChangeNotify::Watcher::Subclass->new(...) This method creates a new watcher. It accepts the following arguments: =over 4 =item * directories => $path =item * directories => \@paths This argument is required. It can be either one or many paths which should be watched for changes. =item * filter => qr/.../ This is an optional regular expression that will be used to check if a file is of interest. This filter is only applied to files. By default, all files are included. =item * exclude => [...] An optional list of paths to exclude. This list can contain either plain strings or regular expressions. If you provide a string it should contain the complete path to be excluded. The paths can be either directories or specific files. If the exclusion matches a directory, all of its files and subdirectories are ignored. =item * follow_symlinks => $bool By default, symlinks are ignored. Set this to true to follow them. If this symlinks are being followed, symlinks to files and directories will be followed. Directories will be watched, and changes for directories and files reported. =item * sleep_interval => $number For watchers which call C to implement the C<< $watcher->wait_for_events() >> method, this argument controls how long it sleeps for. The value is a number in seconds. The default is 2 seconds. =item * event_class => $class This can be used to change the class used to report events. By default, this is L. =back =head2 $watcher->wait_for_events() This method causes the watcher to block until it sees interesting events, and then return them as a list. Some watcher subclasses may implement blocking as a sleep loop, while others may actually block. =head2 $watcher->new_events() This method returns a list of any interesting events seen since the last time the watcher checked. =head2 $watcher->sees_all_events() If this is true, the watcher will report on all events. Some watchers, like the Default subclass, are not smart enough to track things like a file being created and then immediately deleted, and can only detect changes between snapshots of the file system. Other watchers, like the Inotify subclass, see all events that happen and report on them. =head1 AUTHOR Dave Rolsky =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by Dave Rolsky. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) =cut File-ChangeNotify-0.24/lib/File/ChangeNotify.pm0000644000175000017500000000761512245662027021112 0ustar autarchautarchpackage File::ChangeNotify; { $File::ChangeNotify::VERSION = '0.24'; } use strict; use warnings; use Carp qw( confess ); use Class::Load qw( load_class ); # We load this up front to make sure that the prereq modules are installed. use File::ChangeNotify::Watcher::Default; use Module::Pluggable::Object; sub instantiate_watcher { my $class = shift; for my $class ( $class->usable_classes() ) { if ( _try_load($class) ) { return $class->new(@_); } } return File::ChangeNotify::Watcher::Default->new(@_); } { my @usable_classes = (); sub usable_classes { my $class = shift; return @usable_classes if @usable_classes; return @usable_classes = grep { _try_load($_) } $class->_all_classes(); } } { my %tried; sub _try_load { my $class = shift; return $tried{$class} if exists $tried{$class}; eval { load_class($class) }; my $e = $@; die $e if $e && $e !~ /Can\'t locate|did not return a true value/; return $tried{$class} = $e ? 0 : 1; } } my $finder = Module::Pluggable::Object->new( search_path => 'File::ChangeNotify::Watcher' ); sub _all_classes { return sort grep { $_ ne 'File::ChangeNotify::Watcher::Default' } $finder->plugins(); } 1; # ABSTRACT: Watch for changes to files, cross-platform style __END__ =pod =head1 NAME File::ChangeNotify - Watch for changes to files, cross-platform style =head1 VERSION version 0.24 =head1 SYNOPSIS use File::ChangeNotify; my $watcher = File::ChangeNotify->instantiate_watcher ( directories => [ '/my/path', '/my/other' ], filter => qr/\.(?:pm|conf|yml)$/, ); if ( my @events = $watcher->new_events() ) { ... } # blocking while ( my @events = $watcher->wait_for_events() ) { ... } =head1 DESCRIPTION This module provides an API for creating a L subclass that will work on your platform. Most of the documentation for this distro is in L. =head1 METHODS This class provides the following methods: =head2 File::ChangeNotify->instantiate_watcher(...) This method looks at each available subclass of L and instantiates the first one it can load, using the arguments you provided. It always tries to use the L class last, on the assumption that any other class that is available is a better option. =head2 File::ChangeNotify->usable_classes() Returns a list of all the loadable L subclasses. =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 DONATIONS If you'd like to thank me for the work I've done on this module, please consider making a "donation" to me via PayPal. I spend a lot of free time creating free software, and would appreciate any support you'd care to offer. Please note that B in order for me to continue working on this particular software. I will continue to do so, inasmuch as I have in the past, for as long as it interests me. Similarly, a donation made in this way will probably not make me work on this software much more, unless I get so many donations that I can consider working on free software full time, which seems unlikely at best. To donate, log into PayPal and send money to autarch@urth.org or use the button on this page: L =head1 AUTHOR Dave Rolsky =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by Dave Rolsky. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) =cut File-ChangeNotify-0.24/META.json0000644000175000017500000000414212245662027016162 0ustar autarchautarch{ "abstract" : "Watch for changes to files, cross-platform style", "author" : [ "Dave Rolsky " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300039, CPAN::Meta::Converter version 2.131560", "license" : [ "artistic_2" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "File-ChangeNotify", "prereqs" : { "build" : { "requires" : { "Module::Build" : "0.3601" } }, "configure" : { "requires" : { "Module::Build" : "0.3601" } }, "develop" : { "requires" : { "Test::CPAN::Changes" : "0.19", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Carp" : "0", "Class::Load" : "0", "File::Find" : "0", "File::Spec" : "0", "List::MoreUtils" : "0", "Module::Pluggable::Object" : "0", "Moose" : "0", "Moose::Util::TypeConstraints" : "0", "MooseX::Params::Validate" : "0", "MooseX::SemiAffordanceAccessor" : "0", "Time::HiRes" : "0", "namespace::autoclean" : "0", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Data::Dumper" : "0", "Exporter" : "0", "File::Path" : "0", "File::Temp" : "0", "FindBin" : "0", "Test::Exception" : "0", "Test::More" : "0", "base" : "0", "lib" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-file-changenotify@rt.cpan.org", "web" : "http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-ChangeNotify" }, "repository" : { "type" : "git", "url" : "git://git.urth.org/File-ChangeNotify.git", "web" : "http://git.urth.org/File-ChangeNotify.git" } }, "version" : "0.24" } File-ChangeNotify-0.24/Changes0000644000175000017500000001070112245662027016032 0ustar autarchautarch0.24 2013-11-28 - Removed used of deprecated Class::MOP::load_class(). 0.23 2013-01-26 - The new_events() watcher method blocked when using IO::Kqueue as the watcher backend. Reported and patched by Jun Kuriyama. 0.22 2012-04-13 - Remove unnecessary Perl 5.10 requirement. 0.21 2012-02-03 - The implementation of the exclude feature did not work properly in several cases. First, for the Inotify and KQueue watchers, when a new directory was created that should have been excluded, it was not. Second, it didn't work for files at all for these watchers. Reported by Jon Swartz. RT #73089. 0.20 2011-04-19 - The KQueue watcher checks that a file has a file descriptor to avoid watching closed files. Patch by Adreas Voegele. 0.19 2010-10-17 - The all.t test didn't run any tests at all if neither the Inotify nor KQueue watchers could be loaded. This was treated as a failure by test harnesses. Now we always test the Default class. 0.18 2010-10-15 - Always make a Default watcher object if we cannot load an OS-specific class. - Add Test::Exception as a test prereq. 0.17 2010-10-04 - Loading File::ChangeNotify always loads the Default watcher class. This will give a useful error message if this module's prereqs are not loaded. 0.16 2010-07-12 - Changes to avoid a warning about a useless coercion from future versions of Moose. 0.15 2010-07-09 - Add a missing prereq, namespace::autoclean. 0.14 2010-07-08 - Running the tests left behind a lot of temp directories that should have been cleaned up, but weren't. Reported by Peter Edwards. RT #59125. - License is now Artistic 2.0 0.13 2010-03-28 - Circular symlinks would cause instantiating a watcher to die with an error from File::Find. These are now ignored. Reported by Jon Schutz. RT #55883. - Fixed misspelling of IO::KQueue in auto features. Reported by Jens Rehsack. RT #54905. 0.12 2010-01-28 - Added auto_features to the Build.PL, which will give hints on what modules to install for KQueue and Inotify support. - Require Linux::Inotify 1.2+, since 1.1 apparently doesn't work with this module. Reported by Michael Grondin. RT #54069. 0.11 2009-12-07 - A test attempted to use Test::Without::Module but this wasn't in the prereq list. I've made the test check for the module and skip its tests if the module isn't present. Reported by Leon Brocard. RT #52539. 0.10 2009-12-06 - Attempting to instantiate more than one watcher failed if you were on a system where one of the watcher subclasses could not be loaded (which is basically every system because no system has both inotify and kqueue). Patch by Mark Grimes. RT #52477. 0.09 2009-11-09 - This release fixes the excluded-dirs.t under Windows. There are no other changes in this release, so there's no need to upgrade if you have 0.08 installed. Patch by Taro Nishino. RT #51161. 0.08 2009-11-05 - Added a new exclude feature that allows you to excludes files or directories outright. Implemented by Dan Thomas. RT #51062. - Added a KQueue-based watcher written by Dan Thomas. I have no idea if this works, as I don't have BSD, but we'll assume he ran the tests on his system ;) RT #51062. 0.07 2009-06-29 - Fixed a typo in File::ChangeNotify::Watcher that causes a warning with newer versions of Moose. Reported by David Raab. Fixes RT #47431. 0.06 2009-06-03 - Created a Makefile.PL from the Build.PL. 0.05 2009-05-17 - Update the Moose::Params::Validate prereq so it requires the version we really need (0.08+). - Removed Cwd and FindBin from our prereq list. 0.04 2009-05-14 - The Default watcher would blow up when a directory it was watching was later removed. Reported by Tomas Doran. - The Inotify watcher would generate two events when a directory it was watching was removed, one delete and one unknown, rather than just a delete event. 0.03 2009-05-11 - Removed the default value for directories in the Watcher class, because setting this value is really an app-specific task. 0.02 2009-05-10 - Not having Linux::Inotify2 caused attempting to make a watcher blow up, when it should just use the Default watcher. Reported by Florian Ragwitz. - Fixes a a bug in the Default watcher that causes it die when trying to sleep in the wait_for_events method. - Fixed warnings from the Default watcher in the face of symlinks that point to nonexistent files. 0.01 2009-05-07 - First version, released on an unsuspecting world. File-ChangeNotify-0.24/MANIFEST0000644000175000017500000000104112245662027015665 0ustar autarchautarchBuild.PL Changes INSTALL LICENSE MANIFEST META.json META.yml README dist.ini inc/MyModuleBuild.pm lib/File/ChangeNotify.pm lib/File/ChangeNotify/Event.pm lib/File/ChangeNotify/Watcher.pm lib/File/ChangeNotify/Watcher/Default.pm lib/File/ChangeNotify/Watcher/Inotify.pm lib/File/ChangeNotify/Watcher/KQueue.pm t/all.t t/author-pod-spell.t t/excluded-dirs.t t/instantiate-twice.t t/lib/File/ChangeNotify/TestHelper.pm t/release-cpan-changes.t t/release-eol.t t/release-pod-no404s.t t/release-pod-syntax.t t/release-synopsis.t t/release-try-load.t File-ChangeNotify-0.24/INSTALL0000644000175000017500000000174612245662027015601 0ustar autarchautarch This is the Perl distribution File-ChangeNotify. Installing File-ChangeNotify is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm File::ChangeNotify If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S File::ChangeNotify ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan File::ChangeNotify ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Build.PL % ./Build && ./Build test Then install it: % ./Build install If you are installing into a system-wide directory, you may need to run: % sudo ./Build install ## Documentation File-ChangeNotify documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc File::ChangeNotify