Data::Consumer::Dir - Data::Consumer implementation for a directory of files resource
Version 0.16
use Data::Consumer::Dir; my $consumer = Data::Consumer::Dir->new( root => '/some/dir', create => 1, open_mode => '+<', ); $consumer->consume( sub { my $id = shift; print "processed $id\n"; } );
Constructor for a Data::Consumer::Dir instance.
Either the root option must be provided or both unprocessed and processed arguments must be defined. Will die if the directories do not exist unless the create option is set to a true value.
root
unprocessed
processed
create
Directory within which unprocessed files will be found.
May also be a callback which is responsible for marking the item as unprocessed. This will be called with the arguments ($consumer, 'unprocessed', $spec, $fh, $name).
($consumer, 'unprocessed', $spec, $fh, $name)
Files will be moved to this directory prior to be processed.
May also be a callback which is responsible for marking the item as working. This will be called with the arguments ($consumer, 'working', $spec, $fh, $name).
($consumer, 'working', $spec, $fh, $name)
Once successfully processed the files will be moved to this directory.
May also be a callback which is responsible for marking the item as processed. This will be called with the arguments ($consumer, 'processed', $spec, $fh, $name).
($consumer, 'processed', $spec, $fh, $name)
If processing fails then the files will be moved to this directory.
May also be a callback which is responsible for marking the item as failed. This will be called with the arguments ($consumer, 'failed', $spec, $fh, $name).
($consumer, 'failed', $spec, $fh, $name)
Automatically creates any of the unprocessed, working, processed, or failed directories below a specified root. Only those directories not explicitly defined will be automatically created so this can be used in conjunction with the other options.
working
failed
If true then directories specified by not existing will be created. If create_mode is specified then the directories will be created with that mode.
create_mode
In order to lock a file a filehandle must be opened, normally in read-only mode (<), however it may be useful to open with other modes.
<
Reset the state of the object.
Acquire an item to be processed.
Returns an identifier to be used to identify the item acquired.
Release any locks on the currently held item.
Normally there is no need to call this directly.
Return a filehandle to the currently acquired item. See the open_mode argument in new() for details on how to control the mode that the filehandle is opened with.
open_mode
new()
Return the full filespec for the currently acquired item.
Return the filename (without path) of the currently acquired item.
Note that this is an alias for $object->last_id().
$object->last_id()
Yves Orton, <YVES at cpan.org>
<YVES at cpan.org>
Please report any bugs or feature requests to bug-data-consumer at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-Consumer.
bug-data-consumer at rt.cpan.org
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
Igor Sutton <IZUT@cpan.org> for ideas, testing and support
Copyright 2008 Yves Orton, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Data::Consumer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Consumer
CPAN shell
perl -MCPAN -e shell install Data::Consumer
For more information on module installation, please visit the detailed CPAN module installation guide.