File Coverage

blib/lib/POE/Component/DirWatch/Object/NewFile.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package POE::Component::DirWatch::Object::NewFile;
2 3     3   2343 use strict;
  3         5  
  3         105  
3 3     3   11 use warnings;
  3         4  
  3         73  
4 3     3   519 use Moose;
  3         368288  
  3         21  
5 3     3   15755 use POE;
  3         4  
  3         19  
6              
7             our $VERSION = "0.1200";
8              
9             extends 'POE::Component::DirWatch::Object';
10              
11             has 'seen_files' => (is => 'rw', isa => 'HashRef', default => sub{{}});
12              
13             #--------#---------#---------#---------#---------#---------#---------#---------#
14              
15             override '_dispatch' => sub{
16             my ($self, $kernel, $fname, $fpath) = @_[OBJECT, KERNEL, ARG0, ARG1];
17              
18             return if( $self->seen_files->{ $fpath } );
19             $self->seen_files->{ $fpath } = 1;
20             super;
21             };
22              
23             before '_poll' => sub{
24             my $self = shift;
25              
26             %{ $self->seen_files } = map {$_ => $self->seen_files->{$_} }
27             grep {-e $_ } keys %{ $self->seen_files };
28             };
29              
30             1;
31              
32             __END__;
33              
34             #--------#---------#---------#---------#---------#---------#---------#---------#
35              
36              
37             =head1 NAME
38              
39             POE::Component::DirWatch::Object::NewFile
40              
41             =head1 SYNOPSIS
42              
43             use POE::Component::DirWatch::Object::NewFile;
44              
45             #$watcher is a PoCo::DW:Object::NewFile
46             my $watcher = POE::Component::DirWatch::Object::NewFile->new
47             (
48             alias => 'dirwatch',
49             directory => '/some_dir',
50             filter => sub { $_[0] =~ /\.gz$/ && -f $_[1] },
51             callback => \&some_sub,
52             interval => 1,
53             );
54              
55             $poe_kernel->run;
56              
57             =head1 DESCRIPTION
58              
59             POE::Component::DirWatch::Object::NewFile extends DirWatch::Object in order to
60             exclude files that have already been processed
61              
62             =head1 Accessors
63              
64             =head2 seen_files
65              
66             Read-write. Will return a hash ref in with keys will be the full path
67             of all previously processed documents.
68              
69             =head1 Extended methods
70              
71             =head2 dispatch
72              
73             C<override 'dispatch'> Don't dispatch if file has been seen.
74              
75             =head2 poll
76              
77             C<before 'poll'> the list of known files is checked and if any of the files no
78             longer exist they are removed from the list of known files to avoid the list
79             growing out of control.
80              
81             =head2 meta
82              
83             Keeping tests happy.
84              
85             =head1 SEE ALSO
86              
87             L<POE::Component::DirWatch::Object>, L<Moose>
88              
89             =head1 AUTHOR
90              
91             Guillermo Roditi, <groditi@cpan.org>
92              
93             Please report any bugs or feature requests to
94             C<bug-poe-component-dirwatch-object at rt.cpan.org>, or through the web interface at
95             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-DirWatch-Object>.
96             I will be notified, and then you'll automatically be notified of progress on
97             your bug as I make changes.
98              
99             =head1 SUPPORT
100              
101             You can find documentation for this module with the perldoc command.
102              
103             perldoc POE::Component::DirWatch::Object::NewFile
104              
105             You can also look for information at:
106              
107             =over 4
108              
109             =item * AnnoCPAN: Annotated CPAN documentation
110              
111             L<http://annocpan.org/dist/POE-Component-DirWatch-Object>
112              
113             =item * CPAN Ratings
114              
115             L<http://cpanratings.perl.org/d/POE-Component-DirWatch-Object>
116              
117             =item * RT: CPAN's request tracker
118              
119             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-DirWatch-Object>
120              
121             =item * Search CPAN
122              
123             L<http://search.cpan.org/dist/POE-Component-DirWatch-Object>
124              
125             =back
126              
127             =head1 ACKNOWLEDGEMENTS
128              
129             People who answered way too many questions from an inquisitive idiot:
130              
131             =over 4
132              
133             =item #PoE & #Moose
134              
135             =item Matt S Trout <mst@shadowcatsystems.co.uk>
136              
137             =item Rocco Caputo
138              
139             =back
140              
141             =head1 COPYRIGHT
142              
143             Copyright 2006 Guillermo Roditi. All Rights Reserved. This is
144             free software; you may redistribute it and/or modify it under the same
145             terms as Perl itself.
146              
147             =cut
148