File-Modified-0.10/000755 000765 000024 00000000000 12613524434 014267 5ustar00neilbstaff000000 000000 File-Modified-0.10/Changes000644 000765 000024 00000003160 12613524434 015562 0ustar00neilbstaff000000 000000 Revision history for Perl module File::Modified 0.10 2015-10-26 NEILB - Switched to Dist::Zilla - Updated github repo URL after changing my github username 0.09 2014-05-13 NEILB - Added a bunch of similar modules to the SEE ALSO section in the pod. - Corrected self-reference in doc to use the right name. 0.08 2014-03-31 NEILB - got rid of warning about defined(@array) being deprecated. Bug and fix from BWAGNER RT#81444 - Removed two .cvsignore files RT#26843 - Removed META.yml so it can be auto-generated by MakeMaker - Min perl version 5.6.0 - Marked license as 'perl' in metadata, to match the doc - Added github repo to metadata and pod - Added PREREQ_PM, CONFIGURE_REQUIRES and TEST_REQUIRES to Makefile.PL 0.07 2004-12-05 - Changed a hidden submodule so it doesn't clash with File::Signature anymore. - Directory cleanup (Modified.pm was distributed twice) 0.06 2002-08-12 - Yet another test-only update : Check that the different digests are actually there before using them. Apparently, MD2 isn't in the Digest:: modules anymore. Added directory watching to the Todo list. 0.05 2002-08-11 - Adjusted number of planned tests in the distribution test file 0.04 2002-08-11 - Fixed stupid bug in Signature::MD5 by adding a call to binmode() 0.02 2002-05-09 - Added checksum signature - Added more tests (now up to 40) - Changed MD5 fallback from mtime to checksum - Added general use of the Digest:: module tree instead of MD5 only 0.01 2002-04-22 - original version; created by h2xs 1.21 with options -X File::Modified File-Modified-0.10/dist.ini000644 000765 000024 00000000442 12613524434 015733 0ustar00neilbstaff000000 000000 name = File-Modified author = Max Maischein license = Perl_5 copyright_holder = Max Maischein copyright_year = 2002 version = 0.10 [@Filter] -bundle = @Basic -remove = Readme [PkgVersion] [AutoPrereqs] [MetaJSON] [GithubMeta] [Git::Tag] tag_message= [Git::Push] File-Modified-0.10/example/000755 000765 000024 00000000000 12613524434 015722 5ustar00neilbstaff000000 000000 File-Modified-0.10/lib/000755 000765 000024 00000000000 12613524434 015035 5ustar00neilbstaff000000 000000 File-Modified-0.10/LICENSE000644 000765 000024 00000043660 12613524434 015305 0ustar00neilbstaff000000 000000 This software is copyright (c) 2002 by Max Maischein. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2002 by Max Maischein. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2002 by Max Maischein. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End File-Modified-0.10/Makefile.PL000644 000765 000024 00000002221 12613524434 016236 0ustar00neilbstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.037. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "checks intelligently if files have changed", "AUTHOR" => "Max Maischein ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "File-Modified", "EXE_FILES" => [], "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.006", "NAME" => "File::Modified", "PREREQ_PM" => { "base" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Test::More" => "0.88" }, "VERSION" => "0.10", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "ExtUtils::MakeMaker" => 0, "Test::More" => "0.88", "base" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); File-Modified-0.10/MANIFEST000644 000765 000024 00000000352 12613524434 015420 0ustar00neilbstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.037. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini example/1.pl example/Export.cfg example/Import.cfg lib/File/Modified.pm t/test.t File-Modified-0.10/META.json000644 000765 000024 00000002200 12613524434 015702 0ustar00neilbstaff000000 000000 { "abstract" : "checks intelligently if files have changed", "author" : [ "Max Maischein " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.037, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "File-Modified", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "base" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "0.88" } } }, "release_status" : "stable", "resources" : { "homepage" : "https://github.com/neilbowers/File-Modified", "repository" : { "type" : "git", "url" : "https://github.com/neilbowers/File-Modified.git", "web" : "https://github.com/neilbowers/File-Modified" } }, "version" : "0.10" } File-Modified-0.10/META.yml000644 000765 000024 00000001163 12613524434 015541 0ustar00neilbstaff000000 000000 --- abstract: 'checks intelligently if files have changed' author: - 'Max Maischein ' build_requires: Test::More: '0.88' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.037, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: File-Modified requires: base: '0' perl: '5.006' strict: '0' warnings: '0' resources: homepage: https://github.com/neilbowers/File-Modified repository: https://github.com/neilbowers/File-Modified.git version: '0.10' File-Modified-0.10/README000644 000765 000024 00000001437 12613524434 015154 0ustar00neilbstaff000000 000000 File::Modified version 0.02 ========================= This module provides an easy way for long running processes (like daemons) to determine whether a file was changed since the last time it was checked. Also, some persistence now allows you to use it as a more general caching mechanism. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES Digest is optional but nice to have. If a script uses MD5 features, a fallback to checksums is available. Test::More is needed to run the test script. COPYRIGHT AND LICENCE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002 Max Maischein, corion@cpan.orgFile-Modified-0.10/t/000755 000765 000024 00000000000 12613524434 014532 5ustar00neilbstaff000000 000000 File-Modified-0.10/t/test.t000755 000765 000024 00000011340 12613524434 015700 0ustar00neilbstaff000000 000000 #!/usr/bin/perl -w # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' use strict; use warnings; ######################### use Test::More 0.88; our ($have_file_temp, $have_digest, @methods, @digest_methods); BEGIN { eval "use Digest;"; $have_digest = ! $@; @digest_methods = (); for (qw(MD2 MD5 SHA1 nonExistingDigest)) { eval "use Digest::$_;"; push @digest_methods, $_ unless $@; }; eval "use File::Temp qw( tempfile )"; $have_file_temp = ! $@; # Now set up a list of all methods that will result in isa($method) # without falling back to something else ... @methods = qw(mtime Checksum); push @methods, @digest_methods if $have_digest; plan tests => 5+7 * scalar (@methods) + scalar (@digest_methods) +1; }; BEGIN { use_ok( 'File::Modified' ); }; ######################### # Our script shouldn't have changed its identity : for my $method (@methods) { ok( ! File::Modified->new(method=>$method,files=>[$0])->changed(), "Checking $method identity for our script"); }; # In fact, no module should have changed its identity : for my $method (@methods) { ok( ! File::Modified->new(method=>$method,files=>[values %INC])->changed(), "Checking $method identity for values of %INC"); }; # Let's see that adding returns the right kind and number of things for my $method (@methods) { my $m = File::Modified->new(method=>$method); my @sigs = $m->addfile($0); is(@sigs, 1, "$method: One file added"); @sigs = $m->addfile($0,$0,$0,$0,$0,$0); is(@sigs, 6, "$method: Six files added"); isa_ok($sigs[0], "File::Modified::Signature::$method", "File::Modified->new(method=>$method)"); }; # Test that a signature can be stored and loaded : for my $method (@methods) { my $m = File::Modified->new(method=>$method); my @f = $m->addfile($0); my $persistent = $f[0]->as_scalar(); isa_ok(File::Modified::Signature->from_scalar($persistent),ref $f[0],"Loading back $method"); }; # Now test the fallback to checksums whenever Digest:: is not available SKIP: { skip "Digest:: is not installed", 1 unless $have_digest; is( $File::Modified::Signature::Digest::fallback, undef, "Checksum fallback for MD5 correctly disabled" ); }; SKIP: { skip "Digest:: is installed", 2 unless ! $have_digest; is( $File::Modified::Signature::Digest::fallback, 1, "Checksum fallback for Digest::xx correctly enabled" ); my $m = File::Modified->new(method=>"MD5"); my $s = $m->add($0,'MD5'); isa_ok($s,"File::Modified::Signature::Checksum","Digest::xx fallback"); }; SKIP: { skip "File::Temp is not installed", (scalar @methods)*2 unless $have_file_temp; my %d; my ($fh, $filename); eval { ($fh,$filename) = tempfile(); close $fh; open F, "> $filename" or die "couldn't write to tempfile '$filename'\n"; print F "foo"; close F; sleep 3; for my $method (@methods) { $d{$method} = File::Modified->new(method=>$method,files=>[$filename]); }; open F, "> $filename" or die "couldn't write to tempfile '$filename'\n"; print F "bar"; close F; }; diag $@ if $@; for my $method (@methods) { ok($d{$method}->changed(), "Detecting changed file via $method"); }; # Clean up the tempfile if ($filename) { unlink($filename) or diag "Couldn't remove tempfile $filename : $!\n"; }; }; # Now test the handling of nonexisting signature methods : my $d = File::Modified->new( method => 'DoesNotExist' ); is( $d->add( 'foo' ), undef, "Nonexistent File::Modified::Signature:: classes correctly fail"); TODO: { local $TODO = "Deep comparision of structures not yet implemented"; { package File::Modified::Signature::Complicated; sub signature { my ($self) = @_; my $result = [$self->{Filename}]; return $result; }; }; my $d = File::Modified->new(method => 'Complex',files => ['does_not_need_to_exist']); ok(! $d->changed); }; SKIP: { skip "File::Temp is not installed", 1 unless $have_file_temp; skip "Digest::* is not installed", 1 unless $have_digest; my %d; my $digest; my ($fh, $filename); ($fh,$filename) = tempfile(); close $fh; for $digest (@digest_methods) { eval { open F, "> $filename" or die "couldn't write to tempfile '$filename'\n"; print F "foo\cZbaz"; close F; #sleep 3; $d{$digest} = File::Modified->new(method=>$digest,files=>[$filename]); open F, "> $filename" or die "couldn't write to tempfile '$filename'\n"; print F "foo\cZbar"; close F; }; diag $@ if $@; ok($d{$digest}->changed(), "Detecting changed binary file via Digest::$digest"); }; # Clean up the tempfile if ($filename) { unlink($filename) or diag "Couldn't remove tempfile $filename : $!\n"; }; }; File-Modified-0.10/lib/File/000755 000765 000024 00000000000 12613524434 015714 5ustar00neilbstaff000000 000000 File-Modified-0.10/lib/File/Modified.pm000755 000765 000024 00000026463 12613524434 020010 0ustar00neilbstaff000000 000000 package File::Modified; $File::Modified::VERSION = '0.10'; use 5.006; use strict; use warnings; our @ISA; sub new { my ($class, %args) = @_; my $method = $args{method} || "MD5"; my $files = $args{files} || []; my $self = { Defaultmethod => $method, Files => {}, }; bless $self, $class; $self->addfile(@$files); return $self; }; sub _make_digest_signature { my ($self,$digest) = @_; eval "use Digest::$digest"; if (! $@) { no strict 'refs'; if (@{"Digest::${digest}::ISA"}) { @{"File::Modified::Signature::${digest}::ISA"} = qw(File::Modified::Signature::Digest); return 1; }; }; return undef; }; sub add { my ($self,$filename,$method) = @_; $method ||= $self->{Defaultmethod}; my $signatureclass = "File::Modified::Signature::$method"; my $s = eval { $signatureclass->new($filename) }; if (! $@) { return $self->{Files}->{$filename} = $s; } else { # retry and try Digest::$method if ($self->_make_digest_signature($method)) { my $s = $signatureclass->new($filename); return $self->{Files}->{$filename} = $s; } else { return undef; }; }; }; sub addfile { my ($self,@files) = @_; my @result; # We only return something if the caller wants it if (defined wantarray) { push @result, $self->add($_) for @files; return @result; } else { $self->add($_) for @files; }; }; sub update { my ($self) = @_; $_->initialize() for values %{$self->{Files}}; }; sub changed { my ($self) = @_; return map {$_->{Filename}} grep {$_->changed()} (values %{$self->{Files}}); }; 1; { package File::Modified::Signature; $File::Modified::Signature::VERSION = '0.10'; # This is a case where Python would be nicer. With Python, we could have (paraphrased) # class File::Modified::Signature; # def initialize(self): # self.hash = self.identificate() # return self # def signature(self): # return MD5(self.filename) # def changed(self): # return self.hash != self.signature() # and it would work as expected, (almost) regardless of the structure that is returned # by self.signature(). This is some DWIMmery that I sometimes miss in Perl. # For now, only string comparisions are allowed. sub create { my ($class,$filename,$signature) = @_; my $self = { Filename => $filename, Signature => $signature, }; bless $self, $class; }; sub new { my ($class,$filename) = @_; my $self = $class->create($filename); $self->initialize(); return $self; }; sub initialize { my ($self) = @_; $self->{Signature} = $self->signature(); return $self; }; sub from_scalar { my ($baseclass,$scalar) = @_; die "Strange value in from_scalar: $scalar\n" unless $scalar =~ /^([^|]+)\|([^|]+)\|(.+)$/; my ($class,$filename,$signature) = ($1,$2,$3); return $class->create($filename,$signature); }; sub as_scalar { my ($self) = @_; return ref($self) . "|" . $self->{Filename} . "|" . $self->{Signature}; }; sub changed { my ($self) = @_; my $currsig = $self->signature(); # FIXME: Deep comparision of the two signatures instead of equality ! # And what's this about string comparisions anyway ? if ((ref $currsig) or (ref $self->{Signature})) { die "Implementation error in $self : changed() can't handle references and complex structures (yet) !\n"; #return $currsig != $self->{Signature}; } else { return $currsig ne $self->{Signature}; }; }; }; { package File::Modified::Signature::mtime; $File::Modified::Signature::mtime::VERSION = '0.10'; use base 'File::Modified::Signature'; sub signature { my ($self) = @_; my @stat = stat $self->{Filename} or die "Couldn't stat '$self->{Filename}' : $!"; return $stat[9]; }; }; { package File::Modified::Signature::Checksum; $File::Modified::Signature::Checksum::VERSION = '0.10'; use base 'File::Modified::Signature'; sub signature { my ($self) = @_; my $result; if (-e $self->{Filename} and -r $self->{Filename}) { local *F; open F, $self->{Filename} or die "Couldn't read from file '$self->{Filename}' : $!"; binmode F; my $buf; while (read(F,$buf,32768)) { $result += unpack("%32C*", $buf); $result %= 0xFFFFFFFF; }; close F; }; return $result; }; }; { package File::Modified::Signature::Digest; $File::Modified::Signature::Digest::VERSION = '0.10'; use base 'File::Modified::Signature'; sub digestname { my ($class) = @_; $class = ref $class || $class; return $1 if ($class =~ /^File::Modified::Signature::([^:]+)$/); }; sub digest { my ($self) = @_; if (! exists $self->{Digest}) { my $digestclass = "Digest::" . $self->digestname; eval "use $digestclass"; $self->{Digest} = $digestclass->new(); }; return $self->{Digest}; }; sub signature { my ($self) = @_; my $result; if (-e $self->{Filename} and -r $self->{Filename}) { local *F; open F, $self->{Filename} or die "Couldn't read from file '$self->{Filename}' : $!"; binmode F; $result = $self->digest->addfile(*F)->b64digest(); close F; }; return $result; }; }; 1; __END__ =head1 NAME File::Modified - checks intelligently if files have changed =head1 SYNOPSIS use strict; use File::Modified; my $d = File::Modified->new(files=>['Import.cfg','Export.cfg']); while (1) { my (@changes) = $d->changed; if (@changes) { print "$_ was changed\n" for @changes; $d->update(); }; sleep 60; }; Second example - a script that knows when any of its modules have changed : use File::Modified; my $files = File::Modified->new(files=>[values %INC, $0]); # We want to restart when any module was changed exec $0, @ARGV if $files->changed(); =head1 DESCRIPTION This module provides a simple mechanism for identifying when the contents of one or more files have changed. It was initially intended for programs to detect when their configuration files (or the module they rely on) have changed. There are currently two methods of change detection implemented, C and C. The C method will fall back to use timestamps if the C module cannot be loaded. There are a number of other modules on CPAN that provide similar functionality; they are listed in L below. =over 4 =item new %ARGS Creates a new instance. The C<%ARGS> hash has two possible keys, C, which denotes the method used for checking as default, and C, which takes an array reference to the filenames to watch. =item add filename, method Adds a new file to watch. C is the method (or rather, the subclass of C) to use to determine whether a file has changed or not. The result is either the C subclass or undef if an error occurred. =item addfile LIST Adds a list of files to watch. The method used for watching is the default method as set in the constructor. The result is a list of C subclasses. =item update Updates all signatures to the current state. All pending changes are discarded. =item changed Returns a list of the filenames whose files did change since the construction or the last call to C (whichever last occurred). =back =head2 Signatures The module also creates a new namespace C, which sometime will evolve into its own module in its own file. A file signature is most likely of little interest to you; the only time you might want to access the signature directly is to store the signature in a file for persistence and easy comparision whether an index database is current with the actual data. The interface is settled, there are two methods, C and C, that you use to freeze and thaw the signatures. The implementation of these methods is very frugal, there are no provisions made against filenames that contain weird characters like C<\n> or C<|> (the pipe bar), both will be likely to mess up your one-line-per-file database. An interesting method could be to URL-encode all filenames, but I will visit this topic in the next release. Also, complex (that is, non-scalar) signatures are handled rather ungraceful at the moment. Currently, I'm planning to use L as a quoting mechanism to protect against multiline filenames. =head2 Adding new methods for signatures Adding a new signature method is as simple as creating a new subclass of C. See C for a simple example. There is one point of laziness in the implementation of C, the C method can only compare strings instead of arbitrary structures (yes, there ARE things that are easier in Python than in Perl). C is a wrapper for Gisle Aas' L module and allows you to use any module below the C namespace as a signature, for example C and C. =head2 TODO * Make the simple persistence solution for the signatures better using L. * Allow complex structures for the signatures. * Document C or put it down into another namespace. * Extract the C subclasses out into their own file. * Create an easy option to watch a whole directory tree. =head2 EXPORT None by default. =head1 SEE ALSO L will watch a file or directory, invoking a callback when it changes. L is similar to File::Monitor, but can also let you know about new files being created. L watches a directory for changes to any files whose name matches a regular expression. L provides a function that can be used to check whether a file has been modified since the last time you checked. L provides an API for watching all files in a given directory. It provides several mechanisms for doing this, and a base-class that you can subclass to write your own watcher. L provides some lower-level functions than File::Modified, which are used to identify whether a file has changed by comparing its MD5 digest with an earlier snapshot. L will invoke one of your callbacks if the C details of a file change. L provides a Windows-specific solution for watching for changes to a filesystem. The documentation is extremely limited, so I can't tell if you can limit it a specific directory. L comes with a script that will run a command if any of the files in a directory are changed. L watches an open filehandle or 'named filesystem entity' for changes in its C fields. L watches a directory for new files or directories, invoking a user-supplied callback function when one is seen. L is similar to File::Monitor, but checks URLs rather than files. =head1 REPOSITORY L =head1 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =cut File-Modified-0.10/example/1.pl000755 000765 000024 00000000455 12613524434 016426 0ustar00neilbstaff000000 000000 use lib '..'; use Dependencies; my $d = Dependencies->new(Files=>['Import.cfg','Export.cfg']); while (1) { my (@changes) = $d->changed; if (@changes) { print "$_ was changed\n" for @changes; $d->update(); } else { print "No changes detected.\n"; }; sleep 5; }; File-Modified-0.10/example/Export.cfg000755 000765 000024 00000000000 12613524434 017655 0ustar00neilbstaff000000 000000 File-Modified-0.10/example/Import.cfg000755 000765 000024 00000000000 12613524434 017646 0ustar00neilbstaff000000 000000