Filesys::POSIX::Userland::Find - Crawl directories in a filesystem
use Filesys::POSIX; use Filesys::POSIX::Real; use Filesys::POSIX::Userland::Find; my $fs = Filesys::POSIX->new(Filesys::POSIX::Real->new, 'special' => 'real:/home/foo', 'noatime' => 1 ); $fs->find(sub { my ($path, $inode) = @_; printf("0%o %s\n", $inode->{'mode'}, $path->full); }, '/');
This module provides an extension module to Filesys::POSIX that operates very similarly in principle to the Perl Core module File::Find, albeit with some minor differences and fewer options. For the sake of efficiency, tail recursion, rather than pure call recursion, is used to handle very deep hierarchies.
$fs->find($callback, @paths)
$fs->find($callback, $options, @paths)
$fs->find will perform recursive descent into each path passed, printing the full pathname of each item found relative to each item found in the @paths list. For each item found, both a Filesys::POSIX::Path object, and an inode, respectively, are passed as the sole arguments to the callback. With this mechanism, it is possible to retrieve path data from each item in every way currently provided by File::Find, without retaining global state to do so. As a reference to the corresponding item's inode object is passed, there is no need to perform a $fs->stat call to further inspect the item.
$fs->find
@paths
$fs->stat
When called with an $options argument, specified in the form of an anonymous HASH, the following flags (whose values are set nonzero) are honored:
$options
follow
Any symlinks found along the way are resolved; if the paths they resolve to are those of directories, then further descent will be made into said directories.
recursion_mode
Specifies the strategy to use when recursing through directories. Available options are:
Traverse in a breadth-first manner. This is the default mode.
Traverse in a depth-first manner.
Traverse inodes that are on the same device first. This mode also tracks the current filesystem it is processing and invokes the $fs->enter_filesystem and $fs->exit_filesystem methods when the current filesystem changes to optimize these calls.
$fs->enter_filesystem
$fs->exit_filesystem
ignore_missing
When set, ignore if a file or directory becomes missing during recursion. If the value is a coderef, calls that function with the name of the missing file.
ignore_inaccessible
When set, ignore if a file or directory becomes unreadable during recursion. If the value is a coderef, calls that function with the name of the inaccessible file.
Written by Xan Tronix <xan@cpan.org>
Copyright (c) 2014, cPanel, Inc. Distributed under the terms of the Perl Artistic license.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Filesys::POSIX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Filesys::POSIX
CPAN shell
perl -MCPAN -e shell install Filesys::POSIX
For more information on module installation, please visit the detailed CPAN module installation guide.