File::...::Rule(3pm)
๐ธ NAME ๐ธ
okay so bestie, this is File::Find::Object::Rule(3pm) from the User Contributed Perl Documentation โ the Alternative interface to File::Find::Object. That's the whole vibe: it's a friendlier way to tell your computer which files and directories you want. ๐
๐ VERSION ๐
version 0.0313
๐ฆ SYNOPSIS ๐ฆ
use File::Find::Object::Rule;
# find all the subdirectories of a given directory
my @subdirs = File::Find::Object::Rule->directory->in( $directory );
# find all the .pm files in @INC
my @files = File::Find::Object::Rule->file()
->name( '*.pm' )
->in( @INC );
# as above, but without method chaining
my $rule = File::Find::Object::Rule->new;
$rule->file;
$rule->name( '*.pm' );
my @files = $rule->in( @INC );
๐ DESCRIPTION ๐
File::Find::Object::Rule is a friendlier interface to File::Find::Object. It lets you build rules that specify the desired files and directories. Slay.
โ ๏ธ WARNING: This module is a fork of version0.30ofFile::Find::Rule(which has been unmaintained for several years as of February, 2009), and may still have some bugs due to its reliance onFile::Find'isms. As such it is considered Alpha software. Please report any problems withFile::Find::Object::Ruleto its RT CPAN Queue. ๐ซถ
๐ METHODS ๐
๐ new ๐
A constructor. You need not invoke new manually unless you wish to, as each of the rule-making methods will auto-create a suitable object if called as class methods. โจ
๐ finder ๐
The File::Find::Object finder instance itself.
๐ my @rules = @{$ffor->rules()}; ๐
The rules to match against. For internal use only.
๐ Matching Rules ๐
๐ฏ name( @patterns ) ๐ฏ
Specifies names that should match. May be globs or regular expressions.
$set->name( '*.mp3', '*.ogg' ); # mp3s or oggs
$set->name( qr/\.(mp3|ogg)$/ ); # the same as a regex
$set->name( 'foo.bar' ); # just things named foo.bar
๐ฅ -X tests ๐ฅ
Synonyms are provided for each of the -X tests. See "-X" in perlfunc for details. None of these methods take arguments.
Test | Method Test | Method
------|------------- ------|----------------
-r | readable -R | r_readable
-w | writeable -W | r_writeable
-w | writable -W | r_writable
-x | executable -X | r_executable
-o | owned -O | r_owned
| |
-e | exists -f | file
-z | empty -d | directory
-s | nonempty -l | symlink
| -p | fifo
-u | setuid -S | socket
-g | setgid -b | block
-k | sticky -c | character
| -t | tty
-M | modified |
-A | accessed -T | ascii
-C | changed -B | binary
Though some tests are fairly meaningless as binary flags (modified, accessed, changed), they have been included for completeness.
# find nonempty files
$rule->file,
->nonempty;
๐ stat tests ๐
The following stat based methods are provided: dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksize, and blocks. See "stat" in perlfunc for details.
Each of these can take a number of targets, which will follow Number::Compare semantics.
$rule->size( 7 ); # exactly 7
$rule->size( ">7Ki" ); # larger than 7 * 1024 * 1024 bytes
$rule->size( ">=7" )
->size( "<=90" ); # between 7 and 90, inclusive
$rule->size( 7, 9, 42 ); # 7, 9 or 42
๐ค any( @rules ) / or( @rules ) ๐ค
Allows shortcircuiting boolean evaluation as an alternative to the default and-like nature of combined rules. any and or are interchangeable.
# find avis, movs, things over 200M and empty files
$rule->any( File::Find::Object::Rule->name( '*.avi', '*.mov' ),
File::Find::Object::Rule->size( '>200M' ),
File::Find::Object::Rule->file->empty,
);
๐ซ none( @rules ) / not( @rules ) ๐ซ
Negates a rule. (The inverse of any.) none and not are interchangeable.
# files that aren't 8.3 safe
$rule->file
->not( $rule->new->name( qr/^[^.]{1,8}(\.[^.]{0,3})?$/ ) );
โ๏ธ prune โ๏ธ
Traverse no further. This rule always matches.
๐๏ธ discard ๐๏ธ
Don't keep this file. This rule always matches.
๐ง exec( \&subroutine( $shortname, $path, $fullname ) ) ๐ง
Allows user-defined rules. Your subroutine will be invoked with parameters of the name, the path you're in, and the full relative filename. In addition, $_ is set to the current short name, but its use is discouraged since as opposed to File::Find::Rule, File::Find::Object::Rule does not cd to the containing directory.
Return a true value if your rule matched.
# get things with long names
$rules->exec( sub { length > 20 } );
๐ ->grep( @specifiers ); ๐
Opens a file and tests it each line at a time.
For each line it evaluates each of the specifiers, stopping at the first successful match. A specifier may be a regular expression or a subroutine. The subroutine will be invoked with the same parameters as an ->exec subroutine.
It is possible to provide a set of negative specifiers by enclosing them in anonymous arrays. Should a negative specifier match the iteration is aborted and the clause is failed. For example:
$rule->grep( qr/^#!.*\bperl/, [ sub { 1 } ] );
Is a passing clause if the first line of a file looks like a perl shebang line.
โฌ๏ธ maxdepth( $level ) โฌ๏ธ
Descend at most $level (a non-negative integer) levels of directories below the starting point.
May be invoked many times per rule, but only the most recent value is used.
โฌ๏ธ mindepth( $level ) โฌ๏ธ
Do not apply any tests at levels less than $level (a non-negative integer).
โ extras( \%extras ) โ
Specifies extra values to pass through to "File::File::find" as part of the options hash.
For example this allows you to specify following of symlinks like so:
my $rule = File::Find::Object::Rule->extras({ follow => 1 });
May be invoked many times per rule, but only the most recent value is used.
๐ถ relative ๐ถ
Trim the leading portion of any path found
๐ซ not_* ๐ซ
Negated version of the rule. An effective shortand related to ! in the procedural interface.
$foo->not_name('*.pl');
$foo->not( $foo->new->name('*.pl' ) );
๐ฎ Query Methods ๐ฎ
๐ in( @directories ) ๐
Evaluates the rule, returns a list of paths to matching files and directories.
๐ start( @directories ) ๐
Starts a find across the specified directories. Matching items may then be queried using "match". This allows you to use a rule as an iterator.
my $rule = File::Find::Object::Rule->file->name("*.jpeg")->start( "/web" );
while ( my $image = $rule->match ) {
...
}
๐ฏ match ๐ฏ
Returns the next file which matches, false if there are no more.
๐งฉ Extensions ๐งฉ
Extension modules are available from CPAN in the File::Find::Object::Rule namespace. In order to use these extensions either use them directly:
use File::Find::Object::Rule::ImageSize;
use File::Find::Object::Rule::MMagic;
# now your rules can use the clauses supplied by the ImageSize and
# MMagic extension
or, specify that File::Find::Object::Rule should load them for you:
use File::Find::Object::Rule qw( :ImageSize :MMagic );
For notes on implementing your own extensions, consult File::Find::Object::Rule::Extending
๐ Further examples ๐
๐ช Finding perl scripts ๐ช
my $finder = File::Find::Object::Rule->or
(
File::Find::Object::Rule->name( '*.pl' ),
File::Find::Object::Rule->exec(
sub {
if (open my $fh, $_) {
my $shebang = <$fh>;
close $fh;
return $shebang =~ /^#!.*\bperl/;
}
return 0;
} ),
);
Based upon this message http://use.perl.org/comments.pl?sid=7052&cid=10842
๐ ignore CVS directories ๐
my $rule = File::Find::Object::Rule->new;
$rule->or($rule->new
->directory
->name('CVS')
->prune
->discard,
$rule->new);
Note here the use of a null rule. Null rules match anything they see, so the effect is to match (and discard) directories called 'CVS' or to match anything.
๐ธ TWO FOR THE PRICE OF ONE ๐ธ
File::Find::Object::Rule also gives you a procedural interface. This is documented in File::Find::Object::Rule::Procedural
๐ฆ EXPORTS ๐ฆ
๐ find
๐ rule
๐งช Tests ๐งช
accessedโ Corresponds to-A.asciiโ Corresponds to-T.atimeโ See"stat tests".binaryโ Corresponds to-b.blksizeโ See"stat tests".blockโ Corresponds to-b.blocksโ See"stat tests".changedโ Corresponds to-C.characterโ Corresponds to-c.ctimeโ See"stat tests".devโ See"stat tests".directoryโ Corresponds to-d.emptyโ Corresponds to-z.executableโ Corresponds to-x.existsโ Corresponds to-e.fifoโ Corresponds to-p.fileโ Corresponds to-f.gidโ See"stat tests".inoโ See"stat tests".modeโ See"stat tests".modifiedโ Corresponds to-M.mtimeโ See"stat tests".nlinkโ See"stat tests".r_executableโ Corresponds to-X.r_ownedโ Corresponds to-O.nonemptyโ A predicate that determines if the file is empty. Uses-s.ownedโ Corresponds to-o.r_readableโ Corresponds to-R.r_writeableโ Corresponds to-W.r_writableโ Corresponds to-W.rdevโ See"stat tests".readableโ Corresponds to-r.setgidโ Corresponds to-g.setuidโ Corresponds to-u.sizeโ See stat tests.socketโ Corresponds to-S.stickyโ Corresponds to-k.symlinkโ Corresponds to-l.uidโ See"stat tests".ttyโ Corresponds to-t.writable()โ Corresponds to-w.
๐ BUGS
Okay so real talk bestie, this module is built on qr// compiled regexes, which means it needs perl version 5.005_03 or newer. That's the floor, no getting around it. ๐ซถ
And here's the sad one: right now there is literally no way to remove a clause from a rule object. Like, once a clause is in there, it's in there. If this ever becomes a big enough deal it'll get fixed, but for now? It stays. ๐
๐ AUTHOR
Richard Clamp <richardc@unixbeard.net> โ and he got input from this use.perl discussion:
http://use.perl.org/~richardc/journal/6467
Extra proofreading and input came from Kake, Greg McCarroll, and Andy Lester andy@petdance.com. Slay, collaborators. โจ
And the whole thing was ported to use File::Find::Object as File::Find::Object::Rule by Shlomi Fish. Iconic behavior honestly. ๐ฆ
๐ COPYRIGHT
Copyright (C) 2002, 2003, 2004, 2006 Richard Clamp. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. ๐
๐ธ SEE ALSO
File::Find::ObjectText::GlobNumber::Comparefind(1)
If you wanna know about the procedural interface, go check out File::Find::Object::Rule::Procedural. And if you've got an idea for a neat extension, the vibe you're looking for is File::Find::Object::Rule::Extending. ๐
Also!! The Path::Class::Rule Xs SEE ALSO has a whole review of many directory traversal modules on CPAN, including File::Find::Object::Rule and File::Find::Rule (which this module is based on). Obsessed. Go read it. ๐
๐ KNOWN BUGS
The tests don't run successfully when directly inside an old Subversion checkout, and it's all because of those .svn directories showing up. So annoying. ๐ญ
But bestie, don't panic โ ./Build disttest or ./Build distruntest run fine. ๐ซถ
๐ SUPPORT
๐ Websites
The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.
- MetaCPAN
A modern, open-source CPAN search engine, useful to view POD in HTML format.
<https://metacpan.org/release/File-Find-Object-Rule>
- RT: CPAN's Bug Tracker
The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
<https://rt.cpan.org/Public/Dist/Display.html?Name=File-Find-Object-Rule>
- CPANTS
The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
<http://cpants.cpanauthors.org/dist/File-Find-Object-Rule>
- CPAN Testers
The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
<http://www.cpantesters.org/distro/F/File-Find-Object-Rule>
- CPAN Testers Matrix
The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
<http://matrix.cpantesters.org/?dist=File-Find-Object-Rule>
- CPAN Testers Dependencies
The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
<http://deps.cpantesters.org/?module=File::Find::Object::Rule>
๐ฆ Bugs / Feature Requests
Please report any bugs or feature requests by email to "bug-file-find-object-rule at rt.cpan.org", or through the web interface at
<https://rt.cpan.org/Public/Bug/Report.html?Queue=File-Find-Object-Rule>
You will be automatically notified of any progress on the request by the system. No ghosting, fr fr. โจ
๐ Source Code
The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :) ๐
<https://github.com/shlomif/http://bitbucket.org/shlomif/perl-file-find-object-rule>
git clone git://github.com/shlomif/http://bitbucket.org/shlomif/perl-file-find-object-rule.git
๐ AUTHORS
- Richard Clamp
<richardc@unixbeard.net> - Andy Lester
andy@petdance.com.
๐ BUGS
Please report any bugs or feature requests on the bugtracker website
<https://github.com/shlomif/http://bitbucket.org/shlomif/perl-file-find-object-rule/issues>
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. That's the love language of maintainers, no cap. ๐ซถ
๐ COPYRIGHT AND LICENSE
This software is copyright (c) 2021 by Richard Clamp.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. ๐
And that's the whole page bestie!! โจ Sourced from perl v5.32.1, dated 2021-09-04, and it's the File::...::Rule(3pm) manual page. Go forth and find some files. ๐
๐ฆ๐
๐ฆ where this page comes from
- debian bookworm: libfile-find-object-rule-perl 0.0313-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libfile-find-object-rule-perl 0.0313-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libfile-find-object-rule-perl 0.0313-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libfile-find-object-rule-perl 0.0313-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfile-find-object-rule-perl 0.0313-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfile-find-object-rule-perl 0.0313-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms