File::Collector::Processor - Base class for custom File::Collector::Processor classes for processing files classified by a File::Collector class.
version 0.038
This is the base class for custom File::Collector::Processor classes and is intended to package methods used to manipulate and inspect files and data contained in a File::Collector object. To keep this class small and manageable, it's recommended any heavy file processing be done inside the objects associated with the files.
File::Collector::Processor
File::Collector::Processor objects are not intended to be constructed directly. Instead, they are created by their respective File::Collector classes for you automatically.
File::Collector
# package name must be the same as the custom Collector class with # "::Processor" tacked on to the end package File::Collector::CustomClassifier::Processor use parent 'File::Collector::Processor'; sub a_useful_method { my $s = shift; # do useful stuff ... } sub another_useful_method { my $s = shift; # do more useful stuff ... } sub get_data { my $s = shift; return $s->get_obj_prop ( 'obj_name', 'some_values' ); }
Methods in the Processor classes are typically called from a custom File::Collector class which should use your custom Processor class. All methods described will be available to your Collector class as well as the Processor class.
Processor
use
Collector
IMPORTANT: The name of your Processor class must be the same as your Collector class but with ::Processor tacked on to the end.
::Processor
The methods can be run on Collector objects after they've been constructed.
$collector->some_files->do->run_method;
The do method iterates over all the files classified under the name of the method call preceding it. In the example above, it will iterate over all the files classified under "some" by the custom Collector classes using the _classify_file method. For each file found in the specified category, it will call run_method of the Processor class returned by the do call.
do
_classify_file
run_method
So for example, if you wanted to delete all the files classified as "bad" files, that might look something like this:
$collector->bad_files->do->delete;
The example delete method will takes care of deleting the file for you and might look somethink like this:
delete
sub delete { my $s = shift; unlink $s->selected }
Note that we use $s->selected to refer to the file currently selected by the Processor's iterator. See File::Collector::Base for more details.
$s->selected
Initiates a Processor class' iterator on the first call. Iterates over the files in the Processor on subsequent calls. Returns a boolean false when the iterator is exhausted/empty. Otherwise, it returns the full path the current file in the iterator.
parent
strict
warnings
You can make new bug reports, and view existing ones, through the web interface at https://github.com/sdondley/File-Collector/issues.
See perlmodinstall for information and options on installing Perl modules.
Steve Dondley <s@dondley.com>
This software is copyright (c) 2019 by Steve Dondley.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install File::Collector, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Collector
CPAN shell
perl -MCPAN -e shell install File::Collector
For more information on module installation, please visit the detailed CPAN module installation guide.