.\" Automatically generated by Pod::Man 4.09 (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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "File::Finder 3pm" .TH File::Finder 3pm "2018-01-14" "perl v5.26.1" "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::Finder \- nice wrapper for File::Find ala find(1) .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use File::Finder; \& ## simulate "\-type f" \& my $all_files = File::Finder\->type(\*(Aqf\*(Aq); \& \& ## any rule can be extended: \& my $all_files_printer = $all_files\->print; \& \& ## traditional use: generating "wanted" subroutines: \& use File::Find; \& find($all_files_printer, @starting_points); \& \& ## or, we can gather up the results immediately: \& my @results = $all_files\->in(@starting_points); \& \& ## \-depth and \-follow are noted, but need a bit of help for find: \& my $deep_dirs = File::Finder\->depth\->type(\*(Aqd\*(Aq)\->ls\->exec(\*(Aqrmdir\*(Aq,\*(Aq{}\*(Aq); \& find($deep_dirs\->as_options, @places); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`File::Find\*(C'\fR is great, but constructing the \f(CW\*(C`wanted\*(C'\fR routine can sometimes be a pain. This module provides a \f(CW\*(C`wanted\*(C'\fR\-writer, using syntax that is directly mappable to the \fIfind\fR command's syntax. .PP Also, I find myself (heh) frequently just wanting the list of names that match. With \f(CW\*(C`File::Find\*(C'\fR, I have to write a little accumulator, and then access that from a closure. But with \f(CW\*(C`File::Finder\*(C'\fR, I can turn the problem inside out. .PP A \f(CW\*(C`File::Finder\*(C'\fR object contains a hash of \f(CW\*(C`File::Find\*(C'\fR options, and a series of steps that mimic \fIfind\fR's predicates. Initially, a \&\f(CW\*(C`File::Finder\*(C'\fR object has no steps. Each step method clones the previous object's options and steps, and then adds the new step, returning the new object. In this manner, an object can be grown, step by step, by chaining method calls. Furthermore, a partial sequence can be created and held, and used as the head of many different sequences. .PP For example, a step sequence that finds only files looks like: .PP .Vb 1 \& my $files = File::Finder\->type(\*(Aqf\*(Aq); .Ve .PP Here, \f(CW\*(C`type\*(C'\fR is acting as a class method and thus a constructor. An instance of \f(CW\*(C`File::Finder\*(C'\fR is returned, containing the one step to verify that only files are selected. We could use this immediately as a \f(CW\*(C`File::Find::find\*(C'\fR wanted routine, although it'd be uninteresting: .PP .Vb 2 \& use File::Find; \& find($files, "/tmp"); .Ve .PP Calling a step method on an existing object adds the step, returning the new object: .PP .Vb 1 \& my $files_print = $files\->print; .Ve .PP And now if we use this with \f(CW\*(C`find\*(C'\fR, we get a nice display: .PP .Vb 1 \& find($files_print, "/tmp"); .Ve .PP Of course, we didn't really need that second object: we could have generated it on the fly: .PP .Vb 1 \& find($files\->print, "/tmp"); .Ve .PP \&\f(CW\*(C`File::Find\*(C'\fR supports options to modify behavior, such as depth-first searching. The \f(CW\*(C`depth\*(C'\fR step flags this in the options as well: .PP .Vb 1 \& my $files_depth_print = $files\->depth\->print; .Ve .PP However, the \f(CW\*(C`File::Finder\*(C'\fR object needs to be told explictly to generate an options hash for \f(CW\*(C`File::Find::find\*(C'\fR to pass this information along: .PP .Vb 1 \& find($files_depth_print\->as_options, "/tmp"); .Ve .PP A \f(CW\*(C`File::Finder\*(C'\fR object, like the \fIfind\fR command, supports \s-1AND, OR, NOT,\s0 and parenthesized sub-expressions. \s-1AND\s0 binds tighter than \s-1OR,\s0 and is also implied everywhere that it makes sense. Like \fIfind\fR, the predicates are computed in a \*(L"short-circuit\*(R" fashion, so that a false to the left of the (implied) \s-1AND\s0 keeps the right side from being evaluated, including entire parenthesized subexpressions. Similarly, if the left side of an \s-1OR\s0 is false, the right side is evaluated, and if the left side of the \s-1OR\s0 is true, the right side is skipped. Nested parens are handled properly. Parens are indicated with the rather ugly \f(CW\*(C`left\*(C'\fR and \f(CW\*(C`right\*(C'\fR methods: .PP .Vb 1 \& my $big_or_old_files = $files\->left\->size("+50")\->or\->atime("+30")\->right; .Ve .PP The parens here correspond directly to the parens in: .PP .Vb 1 \& find somewhere \-type f \*(Aq(\*(Aq \-size +50 \-o \-atime +30 \*(Aq)\*(Aq .Ve .PP and are needed so that the \s-1OR\s0 and the implied ANDs have the right nesting. .PP Besides passing the constructed \f(CW\*(C`File::Finder\*(C'\fR object to \&\f(CW\*(C`File::Finder::find\*(C'\fR directly as a \f(CW\*(C`wanted\*(C'\fR routine or an options hash, you can also call \f(CW\*(C`find\*(C'\fR implictly, with \f(CW\*(C`in\*(C'\fR. \f(CW\*(C`in\*(C'\fR provides a list of starting points, and returns all filenames that match the criteria. .PP For example, a list of all names in /tmp can be generated simply with: .PP .Vb 1 \& my @names = File::Finder\->in("/tmp"); .Ve .PP For more flexibility, use \f(CW\*(C`collect\*(C'\fR to execute an arbitrary block in a list context, concatenating all the results (similar to \f(CW\*(C`map\*(C'\fR): .PP .Vb 2 \& my %sizes = File::Finder \& \->collect(sub { $File::Find::name => \-s _ }, "/tmp"); .Ve .PP That's all I can think of for now. The rest is in the detailed reference below. .SS "\s-1META METHODS\s0" .IX Subsection "META METHODS" All of these methods can be used as class or instance methods, except \&\f(CW\*(C`new\*(C'\fR, which is usually not needed and is class only. .IP "new" 4 .IX Item "new" Not strictly needed, because any instance method called on a class will create a new object anyway. .IP "as_wanted" 4 .IX Item "as_wanted" Returns a subroutine suitable for passing to \f(CW\*(C`File::Find::find\*(C'\fR or \&\f(CW\*(C`File::Find::finddepth\*(C'\fR as the \fIwanted\fR routine. If the object is used in a place that wants a coderef, this happens automatically through overloading. .IP "as_options" 4 .IX Item "as_options" Returns a hashref suitable for passing to \f(CW\*(C`File::Find::find\*(C'\fR or \&\f(CW\*(C`File::Find::finddepth\*(C'\fR as the \fIoptions\fR hash. This is necessary if you want the meta-information to carry forward properly. .IP "in(@starting_points)" 4 .IX Item "in(@starting_points)" Calls \f(CW\*(C`File::Find::find($self\->as_options, @starting_points)\*(C'\fR, gathering the results, and returns the results as a list. At the moment, it also returns the count of those items in a scalar context. If that's useful, I'll maintain that. .ie n .IP "collect($coderef, @starting_points)" 4 .el .IP "collect($coderef, \f(CW@starting_points\fR)" 4 .IX Item "collect($coderef, @starting_points)" Calls \f(CW$coderef\fR in a list context for each of the matching items, gathering and concatenating the results, and returning the results as a list. .Sp .Vb 2 \& my $f = File::Finder\->type(\*(Aqf\*(Aq); \& my %sizes = $f\->collect(sub { $File::Find::name, \-s _ }, "/tmp"); .Ve .Sp In fact, \f(CW\*(C`in\*(C'\fR is implemented by calling \f(CW\*(C`collect\*(C'\fR with a coderef of just \f(CW\*(C`sub { $File::Find::name }\*(C'\fR. .SS "\s-1STEPS\s0" .IX Subsection "STEPS" See File::Finder::Steps. .SS "\s-1SPEED\s0" .IX Subsection "SPEED" All the steps can have a compile-time and run-time component. As much work is done during compile-time as possible. Runtime consists of a simple linear pass executing a series of closures representing the individual steps (not method calls). It is hoped that this will produce a speed that is within a factor of 2 or 3 of a handcrafted monolithic \f(CW\*(C`wanted\*(C'\fR routine. .SH "SEE ALSO" .IX Header "SEE ALSO" File::Finder::Steps, File::Find, find2perl, File::Find::Rule .SH "BUGS" .IX Header "BUGS" Please report bugs to \f(CW\*(C`bug\-File\-Finder@rt.cpan.org\*(C'\fR. .SH "AUTHOR" .IX Header "AUTHOR" Randal L. Schwartz, , with a tip of the hat to Richard Clamp for \f(CW\*(C`File::Find::Rule\*(C'\fR. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2003,2004 by Randal L. Schwartz, Stonehenge Consulting Services, Inc. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.