File-Monitor-Lite-0.652003/000755 000765 000024 00000000000 11571041063 015603 5ustar00drymanstaff000000 000000 File-Monitor-Lite-0.652003/Changes000644 000765 000024 00000000254 11544756516 017117 0ustar00drymanstaff000000 000000 Revision history for Perl extension File::Monitor::Lite. 0.01 Thu Mar 31 09:47:58 2011 - original version; created by h2xs 1.23 with options -AXc File::Monitor::Lite File-Monitor-Lite-0.652003/lib/000755 000765 000024 00000000000 11571041063 016351 5ustar00drymanstaff000000 000000 File-Monitor-Lite-0.652003/Makefile.PL000644 000765 000024 00000001354 11570611543 017565 0ustar00drymanstaff000000 000000 use 5.8.6; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'File::Monitor::Lite', VERSION_FROM => 'lib/File/Monitor/Lite.pm', # finds $VERSION PREREQ_PM => {}, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/File/Monitor/Lite.pm', # retrieve abstract from module AUTHOR => 'dryman ') : ()), PREREQ_PM => { "File::Monitor" => 0, "File::Find::Rule" => 0, "File::Touch" => 0, "File::Spec::Functions" => 0, "Class::Accessor::Fast" => 0, } ); File-Monitor-Lite-0.652003/MANIFEST000644 000765 000024 00000000276 11571041063 016741 0ustar00drymanstaff000000 000000 Changes Makefile.PL MANIFEST README.mkd t/01use.t t/02behavior.t t/03multiple_files.t lib/File/Monitor/Lite.pm META.yml Module meta-data (added by MakeMaker) File-Monitor-Lite-0.652003/META.yml000644 000765 000024 00000001105 11571041063 017051 0ustar00drymanstaff000000 000000 --- #YAML:1.0 name: File-Monitor-Lite version: 0.652003 abstract: Monitor file changes license: ~ author: - dryman generated_by: ExtUtils::MakeMaker version 6.42 distribution_type: module requires: Class::Accessor::Fast: 0 File::Find::Rule: 0 File::Monitor: 0 File::Spec::Functions: 0 File::Touch: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 File-Monitor-Lite-0.652003/README.mkd000644 000765 000024 00000002220 11570600501 017226 0ustar00drymanstaff000000 000000 # File::Monitor::Lite File::Monitor::Lite is a perl module for observing file creation, deletion, and modification. # INSTALLATION To install this module, simply type: cpanm -v File::Monitor::Lite If you don't have cpanm, just do the following: curl -LO http://bit.ly/cpanm chmod +x cpanm sudo cp cpanm /usr/local/bin # USAGE use File::Monitor::Lite; my $monitor = File::Monitor::Lite->new ( in => '.', name => '*.html', ); while ($monitor->check() and sleep 1){ my @deleted_files = $monitor->deleted; my @modified_files = $monitor->modified; my @created_files = $monitor->created; my @observing_files = $monitor->observed; } # DEPENDENCIES This module requires these other modules and libraries: File::Monitor File::Find::Rule Cwd But cpanm will help you solve dependency problems. # COPYRIGHT AND LICENCE Copyright (C) 2011 by dryman This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available. File-Monitor-Lite-0.652003/t/000755 000765 000024 00000000000 11571041063 016046 5ustar00drymanstaff000000 000000 File-Monitor-Lite-0.652003/t/01use.t000644 000765 000024 00000000673 11570600501 017173 0ustar00drymanstaff000000 000000 use Test::More tests => 9; use_ok 'File::Monitor::Lite' ; note 'different init test'; new_ok File::Monitor::Lite => [name=> '*.test', in => '.',]; new_ok File::Monitor::Lite => [name=> qr/.+\.haml/, in => '.',]; new_ok File::Monitor::Lite => [name=> ['*.html',qr/.+\.tt$/,], in => '.',]; my $m1 = File::Monitor::Lite->new( name => ['*.test'], in => '.',); foreach $meth (qw(check modified created deleted observed)){ can_ok $m1, $meth; } File-Monitor-Lite-0.652003/t/02behavior.t000644 000765 000024 00000002161 11570611543 020201 0ustar00drymanstaff000000 000000 use Test::More tests => 15; use File::Monitor::Lite; use File::Touch; use File::Spec::Functions ':ALL'; use lib 'lib'; unlink glob '*.test'; my $m = File::Monitor::Lite->new( name => ['*.test'], in => '.',); note 'create t.test'; touch 't.test'; ok $m->check, 'check done'; is_deeply [$m->created], [rel2abs('t.test')], 't.test created'; is_deeply [$m->deleted], [] , 'nothing deleted'; is_deeply [$m->modified], [] , 'nothing modified'; is_deeply [$m->observed], [rel2abs('t.test')], 'observing t.test'; note 'modify t.test'; open FILE, '>t.test'; print FILE 'testing...'; close FILE; ok $m->check, 'check done'; is_deeply [$m->created], [], 'nothing created'; is_deeply [$m->deleted], [] , 'nothing deleted'; is_deeply [$m->modified], [rel2abs('t.test')] , 't.test modified'; is_deeply [$m->observed], [rel2abs('t.test')], 'observing t.test'; note 'delete t.test'; unlink glob '*.test'; ok $m->check, 'check done'; is_deeply [$m->created], [], 'nothing created'; is_deeply [$m->deleted], [rel2abs('t.test')] , 't.test deleted'; is_deeply [$m->modified], [] , 'nothing modified'; is_deeply [$m->observed], [], 'observing nothing'; File-Monitor-Lite-0.652003/t/03multiple_files.t000644 000765 000024 00000003126 11571040423 021414 0ustar00drymanstaff000000 000000 use Test::More tests => 20; use File::Monitor::Lite; use File::Touch; use File::Spec::Functions ':ALL'; use lib 'lib'; unlink glob '*.test'; my $m = File::Monitor::Lite->new( name => ['*.test'], in => '.',); note 'create t1.test'; touch 't1.test'; ok $m->check, 'check done'; is_deeply [$m->created], [rel2abs('t1.test')], 't1.test created'; is_deeply [$m->deleted], [] , 'nothing deleted'; is_deeply [$m->modified], [] , 'nothing modified'; is_deeply [$m->observed], [rel2abs('t1.test')], 'observing t1.test'; note 'create t2.test, t3.test; modify t1.test'; touch 't2.test'; touch 't3.test'; open FILE, '>t1.test'; print FILE 'testing'; close FILE; ok $m->check, 'check done'; is_deeply [$m->created], [rel2abs('t2.test'), rel2abs('t3.test')], 't.test created'; is_deeply [$m->deleted], [] , 'nothing deleted'; is_deeply [$m->modified], [rel2abs('t1.test')] , 'nothing modified'; is_deeply [$m->observed], [rel2abs('t1.test'), rel2abs('t2.test'), rel2abs('t3.test')], 'observing t.test'; note 'delete t2.test t3.test'; unlink 't2.test','t3.test'; ok $m->check, 'check done'; is_deeply [$m->created], [], 'nothing created'; is_deeply [$m->deleted], [rel2abs('t2.test'),rel2abs('t3.test')] , 't.test deleted'; is_deeply [$m->modified], [] , 'nothing modified'; is_deeply [$m->observed], [rel2abs('t1.test')], 'observing nothing'; note 'delete t1.test'; unlink 't1.test'; ok $m->check, 'check done'; is_deeply [$m->created], [], 'nothing created'; is_deeply [$m->deleted], [rel2abs('t1.test')] , 't.test deleted'; is_deeply [$m->modified], [] , 'nothing modified'; is_deeply [$m->observed], [], 'observing nothing'; File-Monitor-Lite-0.652003/lib/File/000755 000765 000024 00000000000 11571041063 017230 5ustar00drymanstaff000000 000000 File-Monitor-Lite-0.652003/lib/File/Monitor/000755 000765 000024 00000000000 11571041063 020657 5ustar00drymanstaff000000 000000 File-Monitor-Lite-0.652003/lib/File/Monitor/Lite.pm000644 000765 000024 00000012234 11571040466 022122 0ustar00drymanstaff000000 000000 package File::Monitor::Lite; use 5.8.6; our $VERSION = '0.652003'; use strict; use warnings; use File::Spec::Functions ':ALL'; use File::Find::Rule; use File::Monitor; use base 'Class::Accessor::Fast'; __PACKAGE__->mk_accessors( qw( monitor watch_list )); sub new { my $class = shift; my $self = {@_}; bless $self, $class; $self->_init; return $self; } sub _init{ my $self = shift; -d $self->{in} or die "invalid director\n"; $self->{in}=rel2abs($self->{in}); my %w_list = map{$_ => 1} File::Find::Rule ->file() ->name($self->{name}) ->in($self->{in}); $self->watch_list(\%w_list); $self->monitor(new File::Monitor); $self->monitor->watch($_)for keys %w_list; $self->monitor->scan; $self->{observed}=[keys %w_list]; $self->{created}=[]; $self->{deleted}=[]; $self->{modified}=[]; 1; } sub check { my $self = shift; my $w_list=$self->watch_list; my @new_file_list = File::Find::Rule ->file() ->name($self->{name}) ->in($self->{in}); my @new_files = grep { not exists $$w_list{$_} } @new_file_list; my @changes = $self->monitor->scan; my @deleted_files = map{$_->name} grep{$_->deleted} @changes; my @modified_files = map{$_->name} grep{not $_->deleted} @changes; # update waching list foreach(@new_files){ $$w_list{$_}=1; $self->monitor->watch($_); } # unwatch deleted files foreach(@deleted_files){ $self->monitor->unwatch($_); delete $$w_list{$_}; } $self->monitor->scan; # do a scan first before next check # else next check $self->monitor cannot find differences $self->{watch_list}=($w_list); $self->{created}= [@new_files]; $self->{modified}=[@modified_files]; $self->{observed}=[ keys %$w_list]; $self->{deleted}= [@deleted_files]; $self->{anychange}= ( scalar(@new_files)+ scalar(@modified_files)+ scalar(@deleted_files)) ? 1 : 0; 1; } sub created { my $self = shift; #return () unless @{$self->{created}}; return sort @{$self->{created}}; } sub modified { my $self = shift; return sort @{$self->{modified}}; } sub observed { my $self = shift; return sort @{$self->{observed}}; } sub deleted { my $self = shift; return sort @{$self->{deleted}}; } sub anychange{ my $self = shift; return $self->{anychange}; } # Preloaded methods go here. 1; __END__ # Below is stub documentation for your module. You'd better edit it! =head1 NAME File::Monitor::Lite - Monitor file changes =head1 SYNOPSIS use File::Monitor::Lite; my $monitor = File::Monitor::Lite->new ( in => '.', name => '*.html', ); while ($monitor->check() and sleep 1){ my @deleted_files = $monitor->deleted; my @modified_files = $monitor->modified; my @created_files = $monitor->created; my @observing_files = $monitor->observed; `do blah..` if $monitor->anychange; } =head1 DESCRIPTION This is another implementaion of File::Monitor. While File::Monitor cannot detect file creation (unless you declare file name first), I use File::Find::Rule to rescan files every time when $monitor->check() is executed. To use this module, just follow synopsis above. Currently one cannot change file observing rules. To do so, create another monitor object with new rules. $m1=File::Monitor::Lite->new( name => '*.html', in => '.', ); $m1->check(); #blah... $m2=File::Monitor::Lite->new( name => '*.css', in => '.', ); $m2->check(); #blah... =head1 INTERFACE =over =item C< new ( args ) > Create a new C object. my $monitor = File::Monitor::Lite->new( in => '.', name => '*.mp3', ); The syntax is inherited from L. It will applied on L as File::Find::Rule ->file() ->name('*.mp3') ->in('.'); As described in L, name can be globs or regular expressions. name => '*.pm', # a simple glob name => qr/.+\.pm$/, # regex name => ['*.mp3', qr/.+\.ogg$/], # array of rules name => @rules, =item C< check() > Check if any file recognized by File::Find::Rule has changed (created, modified, deleted.) The usage is simple: $monitor->check(); =item C< created > Returns an array of file names which has been created since last check. =item C< modified > Returns an array of file names which has been modified since last check. =item C< deleted > Returns an array of file names which has been deleted since last check. =item C< observed > Returns an array of file names which monitor is observing at. =back =head1 SEE ALSO L, L =head1 AUTHOR dryman, Eidryman@gmail.comE =head1 COPYRIGHT AND LICENSE Copyright (C) 2011 by dryman This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available. =cut