NAME

Data::Consumer::Dir - Data::Consumer implementation for a directory of files resource

VERSION

Version 0.17

SYNOPSIS

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";
} );

FUNCTIONS

CLASS->new(%opts)

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.

unprocessed => $path_spec

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).

working => $path_spec

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).

processed => $path_spec

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).

failed => $path_spec

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).

root => $path_spec

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.

create => $bool
create_mode => $mode_flags

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.

open_mode => $mode_str

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.

$object->reset()

Reset the state of the object.

$object->acquire()

Acquire an item to be processed.

Returns an identifier to be used to identify the item acquired.

$object->release()

Release any locks on the currently held item.

Normally there is no need to call this directly.

$object->fh()

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.

$object->spec()

Return the full filespec for the currently acquired item.

$object->file()

Return the filename (without path) of the currently acquired item.

Note that this is an alias for $object->last_id().

AUTHOR

Yves Orton, <YVES at cpan.org>

BUGS

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.

I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

Igor Sutton <IZUT@cpan.org> for ideas, testing and support

COPYRIGHT & LICENSE

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.