.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "File::Find::Rule 3"
.TH File::Find::Rule 3 "2015-12-03" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
File::Find::Rule \- Alternative interface to File::Find
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 3
\& use File::Find::Rule;
\& # find all the subdirectories of a given directory
\& my @subdirs = File::Find::Rule\->directory\->in( $directory );
\&
\& # find all the .pm files in @INC
\& my @files = File::Find::Rule\->file()
\& \->name( \*(Aq*.pm\*(Aq )
\& \->in( @INC );
\&
\& # as above, but without method chaining
\& my $rule = File::Find::Rule\->new;
\& $rule\->file;
\& $rule\->name( \*(Aq*.pm\*(Aq );
\& my @files = $rule\->in( @INC );
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
File::Find::Rule is a friendlier interface to File::Find. It allows
you to build rules which specify the desired files and directories.
.SH "METHODS"
.IX Header "METHODS"
.ie n .IP """new""" 4
.el .IP "\f(CWnew\fR" 4
.IX Item "new"
A constructor. You need not invoke \f(CW\*(C`new\*(C'\fR manually unless you wish
to, as each of the rule-making methods will auto-create a suitable
object if called as class methods.
.SS "Matching Rules"
.IX Subsection "Matching Rules"
.ie n .IP """name( @patterns )""" 4
.el .IP "\f(CWname( @patterns )\fR" 4
.IX Item "name( @patterns )"
Specifies names that should match. May be globs or regular
expressions.
.Sp
.Vb 3
\& $set\->name( \*(Aq*.mp3\*(Aq, \*(Aq*.ogg\*(Aq ); # mp3s or oggs
\& $set\->name( qr/\e.(mp3|ogg)$/ ); # the same as a regex
\& $set\->name( \*(Aqfoo.bar\*(Aq ); # just things named foo.bar
.Ve
.IP "\-X tests" 4
.IX Item "-X tests"
Synonyms are provided for each of the \-X tests. See \*(L"\-X\*(R" in perlfunc for
details. None of these methods take arguments.
.Sp
.Vb 10
\& 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
.Ve
.Sp
Though some tests are fairly meaningless as binary flags (\f(CW\*(C`modified\*(C'\fR,
\&\f(CW\*(C`accessed\*(C'\fR, \f(CW\*(C`changed\*(C'\fR), they have been included for completeness.
.Sp
.Vb 3
\& # find nonempty files
\& $rule\->file,
\& \->nonempty;
.Ve
.IP "stat tests" 4
.IX Item "stat tests"
The following \f(CW\*(C`stat\*(C'\fR based methods are provided: \f(CW\*(C`dev\*(C'\fR, \f(CW\*(C`ino\*(C'\fR,
\&\f(CW\*(C`mode\*(C'\fR, \f(CW\*(C`nlink\*(C'\fR, \f(CW\*(C`uid\*(C'\fR, \f(CW\*(C`gid\*(C'\fR, \f(CW\*(C`rdev\*(C'\fR, \f(CW\*(C`size\*(C'\fR, \f(CW\*(C`atime\*(C'\fR,
\&\f(CW\*(C`mtime\*(C'\fR, \f(CW\*(C`ctime\*(C'\fR, \f(CW\*(C`blksize\*(C'\fR, and \f(CW\*(C`blocks\*(C'\fR. See \*(L"stat\*(R" in perlfunc
for details.
.Sp
Each of these can take a number of targets, which will follow
Number::Compare semantics.
.Sp
.Vb 5
\& $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
.Ve
.ie n .IP """any( @rules )""" 4
.el .IP "\f(CWany( @rules )\fR" 4
.IX Item "any( @rules )"
.PD 0
.ie n .IP """or( @rules )""" 4
.el .IP "\f(CWor( @rules )\fR" 4
.IX Item "or( @rules )"
.PD
Allows shortcircuiting boolean evaluation as an alternative to the
default and-like nature of combined rules. \f(CW\*(C`any\*(C'\fR and \f(CW\*(C`or\*(C'\fR are
interchangeable.
.Sp
.Vb 5
\& # find avis, movs, things over 200M and empty files
\& $rule\->any( File::Find::Rule\->name( \*(Aq*.avi\*(Aq, \*(Aq*.mov\*(Aq ),
\& File::Find::Rule\->size( \*(Aq>200M\*(Aq ),
\& File::Find::Rule\->file\->empty,
\& );
.Ve
.ie n .IP """none( @rules )""" 4
.el .IP "\f(CWnone( @rules )\fR" 4
.IX Item "none( @rules )"
.PD 0
.ie n .IP """not( @rules )""" 4
.el .IP "\f(CWnot( @rules )\fR" 4
.IX Item "not( @rules )"
.PD
Negates a rule. (The inverse of \f(CW\*(C`any\*(C'\fR.) \f(CW\*(C`none\*(C'\fR and \f(CW\*(C`not\*(C'\fR are
interchangeable.
.Sp
.Vb 3
\& # files that aren\*(Aqt 8.3 safe
\& $rule\->file
\& \->not( $rule\->new\->name( qr/^[^.]{1,8}(\e.[^.]{0,3})?$/ ) );
.Ve
.ie n .IP """prune""" 4
.el .IP "\f(CWprune\fR" 4
.IX Item "prune"
Traverse no further. This rule always matches.
.ie n .IP """discard""" 4
.el .IP "\f(CWdiscard\fR" 4
.IX Item "discard"
Don't keep this file. This rule always matches.
.ie n .IP """exec( \e&subroutine( $shortname, $path, $fullname ) )""" 4
.el .IP "\f(CWexec( \e&subroutine( $shortname, $path, $fullname ) )\fR" 4
.IX Item "exec( &subroutine( $shortname, $path, $fullname ) )"
Allows user-defined rules. Your subroutine will be invoked with \f(CW$_\fR
set to the current short name, and with parameters of the name, the
path you're in, and the full relative filename.
.Sp
Return a true value if your rule matched.
.Sp
.Vb 2
\& # get things with long names
\& $rules\->exec( sub { length > 20 } );
.Ve
.ie n .IP """grep( @specifiers )""" 4
.el .IP "\f(CWgrep( @specifiers )\fR" 4
.IX Item "grep( @specifiers )"
Opens a file and tests it each line at a time.
.Sp
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.
.Sp
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:
.Sp
.Vb 1
\& $rule\->grep( qr/^#!.*\ebperl/, [ sub { 1 } ] );
.Ve
.Sp
Is a passing clause if the first line of a file looks like a perl
shebang line.
.ie n .IP """maxdepth( $level )""" 4
.el .IP "\f(CWmaxdepth( $level )\fR" 4
.IX Item "maxdepth( $level )"
Descend at most \f(CW$level\fR (a non-negative integer) levels of directories
below the starting point.
.Sp
May be invoked many times per rule, but only the most recent value is
used.
.ie n .IP """mindepth( $level )""" 4
.el .IP "\f(CWmindepth( $level )\fR" 4
.IX Item "mindepth( $level )"
Do not apply any tests at levels less than \f(CW$level\fR (a non-negative
integer).
.ie n .IP """extras( \e%extras )""" 4
.el .IP "\f(CWextras( \e%extras )\fR" 4
.IX Item "extras( %extras )"
Specifies extra values to pass through to \f(CW\*(C`File::File::find\*(C'\fR as part
of the options hash.
.Sp
For example this allows you to specify following of symlinks like so:
.Sp
.Vb 1
\& my $rule = File::Find::Rule\->extras({ follow => 1 });
.Ve
.Sp
May be invoked many times per rule, but only the most recent value is
used.
.ie n .IP """relative""" 4
.el .IP "\f(CWrelative\fR" 4
.IX Item "relative"
Trim the leading portion of any path found
.ie n .IP """canonpath""" 4
.el .IP "\f(CWcanonpath\fR" 4
.IX Item "canonpath"
Normalize paths found using \f(CW\*(C`File::Spec\-\*(C'\fRcanonpath>. This will return paths
with a file-seperator that is native to your \s-1OS\s0 (as determined by File::Spec),
instead of the default \f(CW\*(C`/\*(C'\fR.
.Sp
For example, this will return \f(CW\*(C`tmp/foobar\*(C'\fR on Unix-ish OSes
and \f(CW\*(C`tmp\efoobar\*(C'\fR on Win32.
.ie n .IP """not_*""" 4
.el .IP "\f(CWnot_*\fR" 4
.IX Item "not_*"
Negated version of the rule. An effective shortand related to ! in
the procedural interface.
.Sp
.Vb 1
\& $foo\->not_name(\*(Aq*.pl\*(Aq);
\&
\& $foo\->not( $foo\->new\->name(\*(Aq*.pl\*(Aq ) );
.Ve
.SS "Query Methods"
.IX Subsection "Query Methods"
.ie n .IP """in( @directories )""" 4
.el .IP "\f(CWin( @directories )\fR" 4
.IX Item "in( @directories )"
Evaluates the rule, returns a list of paths to matching files and
directories.
.ie n .IP """start( @directories )""" 4
.el .IP "\f(CWstart( @directories )\fR" 4
.IX Item "start( @directories )"
Starts a find across the specified directories. Matching items may
then be queried using \*(L"match\*(R". This allows you to use a rule as an
iterator.
.Sp
.Vb 4
\& my $rule = File::Find::Rule\->file\->name("*.jpeg")\->start( "/web" );
\& while ( defined ( my $image = $rule\->match ) ) {
\& ...
\& }
.Ve
.ie n .IP """match""" 4
.el .IP "\f(CWmatch\fR" 4
.IX Item "match"
Returns the next file which matches, false if there are no more.
.SS "Extensions"
.IX Subsection "Extensions"
Extension modules are available from \s-1CPAN\s0 in the File::Find::Rule
namespace. In order to use these extensions either use them directly:
.PP
.Vb 2
\& use File::Find::Rule::ImageSize;
\& use File::Find::Rule::MMagic;
\&
\& # now your rules can use the clauses supplied by the ImageSize and
\& # MMagic extension
.Ve
.PP
or, specify that File::Find::Rule should load them for you:
.PP
.Vb 1
\& use File::Find::Rule qw( :ImageSize :MMagic );
.Ve
.PP
For notes on implementing your own extensions, consult
File::Find::Rule::Extending
.SS "Further examples"
.IX Subsection "Further examples"
.IP "Finding perl scripts" 4
.IX Item "Finding perl scripts"
.Vb 10
\& my $finder = File::Find::Rule\->or
\& (
\& File::Find::Rule\->name( \*(Aq*.pl\*(Aq ),
\& File::Find::Rule\->exec(
\& sub {
\& if (open my $fh, $_) {
\& my $shebang = <$fh>;
\& close $fh;
\& return $shebang =~ /^#!.*\ebperl/;
\& }
\& return 0;
\& } ),
\& );
.Ve
.Sp
Based upon this message http://use.perl.org/comments.pl?sid=7052&cid=10842
.IP "ignore \s-1CVS\s0 directories" 4
.IX Item "ignore CVS directories"
.Vb 7
\& my $rule = File::Find::Rule\->new;
\& $rule\->or($rule\->new
\& \->directory
\& \->name(\*(AqCVS\*(Aq)
\& \->prune
\& \->discard,
\& $rule\->new);
.Ve
.Sp
Note here the use of a null rule. Null rules match anything they see,
so the effect is to match (and discard) directories called '\s-1CVS\s0' or to
match anything.
.SH "TWO FOR THE PRICE OF ONE"
.IX Header "TWO FOR THE PRICE OF ONE"
File::Find::Rule also gives you a procedural interface. This is
documented in File::Find::Rule::Procedural
.SH "EXPORTS"
.IX Header "EXPORTS"
\&\*(L"find\*(R", \*(L"rule\*(R"
.SH "TAINT MODE INTERACTION"
.IX Header "TAINT MODE INTERACTION"
As of 0.32 File::Find::Rule doesn't capture the current working directory in
a taint-unsafe manner. File::Find itself still does operations that the taint
system will flag as insecure but you can use the \*(L"extras\*(R" feature to ask
File::Find to internally \f(CW\*(C`untaint\*(C'\fR file paths with a regex like so:
.PP
.Vb 1
\& my $rule = File::Find::Rule\->extras({ untaint => 1 });
.Ve
.PP
Please consult File::Find's documentation for \f(CW\*(C`untaint\*(C'\fR,
\&\f(CW\*(C`untaint_pattern\*(C'\fR, and \f(CW\*(C`untaint_skip\*(C'\fR for more information.
.SH "BUGS"
.IX Header "BUGS"
The code makes use of the \f(CW\*(C`our\*(C'\fR keyword and as such requires perl version
5.6.0 or newer.
.PP
Currently it isn't possible to remove a clause from a rule object. If
this becomes a significant issue it will be addressed.
.SH "AUTHOR"
.IX Header "AUTHOR"
Richard Clamp <richardc@unixbeard.net> with input gained from this
use.perl discussion: http://use.perl.org/~richardc/journal/6467
.PP
Additional proofreading and input provided by Kake, Greg McCarroll,
and Andy Lester andy@petdance.com.
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (C) 2002, 2003, 2004, 2006, 2009, 2011 Richard Clamp. All Rights Reserved.
.PP
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
File::Find, Text::Glob, Number::Compare, \fBfind\fR\|(1)
.PP
If you want to know about the procedural interface, see
File::Find::Rule::Procedural, and if you have an idea for a neat
extension File::Find::Rule::Extending