blib/lib/POE/Component/DirWatch/Object/Touched.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 42 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package POE::Component::DirWatch::Object::Touched;
2 use strict;
3 use warnings;
4 use Moose;
5 use Array::Compare;
6 use POE;
7  
8 our $VERSION = "0.02";
9  
10 extends 'POE::Component::DirWatch::Object::NewFile';
11  
12 has 'cmp' => (is => 'rw', isa => 'Object', required => 1,
13 default => sub{ Array::Compare->new } );
14  
15 #--------#---------#---------#---------#---------#---------#---------#---------#
16  
17 #Remind me of stat:
18 # 7 size total size of file, in bytes
19 # 8 atime last access time in seconds since the epoch
20 # 9 mtime last modify time in seconds since the epoch
21 # 10 ctime inode change time in seconds since the epoch (*)
22  
23 #clean seen files from dispatch list
24  
25 override '_dispatch' => sub{
26 my ($self, $kernel, $fname,$fpath) = @_[OBJECT, KERNEL, ARG0, ARG1];
27  
28 if( exists $self->seen_files->{ $fpath } ){
29 return if $self->cmp->compare( $self->seen_files->{ $fpath },
30 [ ( stat($fpath) )[7..10] ]);
31 }
32
33 $self->seen_files->{$fpath} = [ ( stat($fpath) )[7..10] ];
34 $kernel->yield(callback => [$fname, $fpath])
35 if $self->filter->($fname,$fpath);
36 };
37  
38  
39 1;
40  
41 __END__;
42  
43 #--------#---------#---------#---------#---------#---------#---------#---------#
44  
45  
46 =head1 NAME
47  
48 POE::Component::DirWatch::Object::Touched
49  
50 =head1 SYNOPSIS
51  
52 use POE::Component::DirWatch::Object::Touched;
53  
54 #$watcher is a PoCo::DW:Object::Touched
55 my $watcher = POE::Component::DirWatch::Object::Touched->new
56 (
57 alias => 'dirwatch',
58 directory => '/some_dir',
59 filter => sub { $_[0] =~ /\.gz$/ && -f $_[1] },
60 callback => \&some_sub,
61 interval => 1,
62 );
63  
64 $poe_kernel->run;
65  
66 =head1 DESCRIPTION
67  
68 POE::Component::DirWatch::Object::Touched extends DirWatch::Object::NewFile in order to
69 exclude files that have already been processed, but still pick up files that have been
70 changed.
71  
72 =head1 Accessors
73  
74 =head2 seen_files
75  
76 Read-write. Will return a hash ref in with keys will be the full path
77 of all previously processed documents that still exist in the file system and the
78 values are listrefs containing the size and last changed dates of the files.
79 C<[ ( stat($file) )[7..10] ]>
80  
81 =head2 cmp
82  
83 An Array::Compare object
84  
85 =head1 Extended methods
86  
87 =head2 dispatch
88  
89 C<override 'dispatch'> Don't dispatch if file has been seen before and has the
90 same values for C<stat($file)[7..10]>
91  
92 =head2 meta
93  
94 Keeping tests happy.
95  
96 =head1 SEE ALSO
97  
98 L<POE::Component::DirWatch::Object>, L<Moose>
99  
100 =head1 AUTHOR
101  
102 Guillermo Roditi, <groditi@cpan.org>
103  
104 =head1 BUGS
105  
106 If a file is created and deleted between polls it will never be seen. Also if a file
107 is edited more than once in between polls it will never be picked up.
108  
109 Please report any bugs or feature requests to
110 C<bug-poe-component-dirwatch-object at rt.cpan.org>, or through the web interface at
111 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-DirWatch-Object>.
112 I will be notified, and then you'll automatically be notified of progress on
113 your bug as I make changes.
114  
115 =head1 SUPPORT
116  
117 You can find documentation for this module with the perldoc command.
118  
119 perldoc POE::Component::DirWatch::Object::Touched
120  
121 You can also look for information at:
122  
123 =over 4
124  
125 =item * AnnoCPAN: Annotated CPAN documentation
126  
127 L<http://annocpan.org/dist/POE-Component-DirWatch-Object>
128  
129 =item * CPAN Ratings
130  
131 L<http://cpanratings.perl.org/d/POE-Component-DirWatch-Object>
132  
133 =item * RT: CPAN's request tracker
134  
135 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-DirWatch-Object>
136  
137 =item * Search CPAN
138  
139 L<http://search.cpan.org/dist/POE-Component-DirWatch-Object>
140  
141 =back
142  
143 =head1 ACKNOWLEDGEMENTS
144  
145 People who answered way too many questions from an inquisitive idiot:
146  
147 =over 4
148  
149 =item #PoE & #Moose
150  
151 =item Matt S Trout <mst@shadowcatsystems.co.uk>
152  
153 =item Rocco Caputo
154  
155 =back
156  
157 =head1 COPYRIGHT
158  
159 Copyright 2006 Guillermo Roditi. All Rights Reserved. This is
160 free software; you may redistribute it and/or modify it under the same
161 terms as Perl itself.
162  
163 =cut
164