NAME
File::Rules - humane syntax for matching files and directories
SYNOPSIS
use File::Rules;
my $rules = File::Rules->new([
'directory is foo',
'filename contains bar'
]);
$rules->add('dirname regex white');
for my $path (('foo/123','abc/bar')) {
if ($rules->match($path)) {
print "rules match $path\n";
}
else {
print "rules do not match $path\n";
}
}
DESCRIPTION
File::Rules is based on the Swish-e search configuration option FileRules. See the ACKNOWLEDGEMENTS section.
In the course of refactoring SWISH::Prog to expand the support for the FileRules config feature, it seemed obvious to me (so many things become obvious after staring at them for years) to extract the FileRules logic into its own module.
METHODS
new
Constructor. Takes array or arrayref of FileRule-type strings, and returns a File::Rules object.
add( str )
Add a FileRule to the object.
rules([ rules ])
Get/set the rule structures. rules should be an array or arrayref of hashrefs conforming to the internal structure.
match_dir( str [, opts] )
Compares str to the rules as if it were a directory path. opts can be a hashref of options. The only supported option currently is strict
which will test str with the -d operator. Example:
$dir = '/foo/bar'; # -d $dir would return false
$rules->match_dir($dir, { strict => 1 }); # returns false regardless of rules
match_file( str [, opts] )
Compares str to the rules as if it were a file path. opts can be a hashref of options. The only supported option currently is strict
which will test str with the -d operator. Example:
$file = '/path/to/some/dir'; # -d $dir would return true
$rules->match_dir($file, { strict => 1 }); # returns false regardless of rules
match( str )
Returns true if str matches any of the rules. Calling match() will test str with the -d operator, similar to calling match_dir() or match_file() with the strict
option.
AUTHOR
Peter Karman, <karman at cpan.org>
BUGS
Please report any bugs or feature requests to bug-file-rules at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Rules. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc File::Rules
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
Syntax based on the Swish-e configuration feature FileRules and FileMatch: http://swish-e.org/docs/swish-config.html#item_filerules
COPYRIGHT & LICENSE
Copyright 2010 Peter Karman.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.