File-Find-Node
view release on metacpan or search on metacpan
ok($f->type eq "p", 'test type() method returns "p" for fifo');
}
});
$f->find;
$f = File::Find::Node->new("/dev/null");
$f->process(sub {
my $ftype = shift->type;
ok($ftype eq "c", 'test type() method returns "c" for char device');
});
$f->follow->find;
# Test level() method
$f = File::Find::Node->new("testdir");
$f->process(sub {
my $f = shift;
my $path = $f->path;
if ($path eq "testdir") {
ok($f->level == 0, "test level() method returns 0 for $path");
}
if ($path eq "testdir/regfile") {
ok($f->level == 1, "test level() method returns 1 for $path");
}
if ($f->path eq "testdir/subdir/regfile2") {
ok($f->level == 2, "test level() method returns 2 for $path");
}
});
$f->find;
# Test parent(), name() and path() methods
$f = File::Find::Node->new("testdir");
$f->process(sub {
my $f = shift;
if ($f->level > 0) {
ok($f->parent->path . "/" . $f->name eq $f->path,
"test parent(), name(), and path() methods for " . $f->path);
}
});
$f->find;
# Test methods that return saved stat information
my @stat1 = lstat("testdir/regfile");
my (@stat2, @stat3);
$f = File::Find::Node->new("testdir/regfile");
$f->process(sub {
my $f = shift;
@stat2 = $f->stat;
@stat3 = ($f->dev, $f->inum, $f->mode, $f->links, $f->uid,
$f->gid, $f->rdev, $f->size, $f->atime, $f->mtime,
$f->ctime, $f->blksize, $f->blocks);
ok($f->perm == ($f->mode & 07777), "test perm() method");
ok($f->ino == $f->inum,
"test ino() and inum() methods are the same");
ok($f->links == $f->nlink,
"test links() and nlink() methods are the same");
my $user = getpwuid($f->uid);
ok($f->user eq $user || $f->user == $f->uid,
"test user() method");
my $group = getgrgid($f->gid);
ok($f->group eq $group || $f->group == $f->gid,
"test group() method");
});
$f->find;
is_deeply(\@stat1, \@stat2, "test stat() method");
is_deeply(\@stat1, \@stat3,
"test dev(), inum(), mode(), etc., methods");
# Test refresh method
chmod(0644, "testdir/regfile");
$f = File::Find::Node->new("testdir/regfile");
$f->process(sub {
my $f = shift;
chmod(0755, $f->path);
ok($f->perm == 0644 && $f->refresh->perm == 0755,
"test refresh() method");
});
$f->find;
# Test filter() method
my (@list1, @list2);
$count = 0;
$f = File::Find::Node->new("testdir");
$f->process(sub {
push(@list1, shift->path);
$count++;
});
$f->filter(sub { sort(grep($_ ne "empty", @_)) })->find;
ok($count == 9, "test filter() method removes empty");
@list2 = sort(@list1);
is_deeply(\@list1, \@list2, "test filter() method sorts");
# Test stop() method
$count = 0;
$f = File::Find::Node->new("testdir");
$f->process(sub {
my $f = shift;
$f->stop if ++$count == 5;
});
$f->find;
ok($count == 5, "test stop() method");
# Test arg() method
$f = File::Find::Node->new("testdir");
$f->process(sub {
my $f = shift;
if ($f->type eq "d") {
$f->arg->{count} = 1;
}
elsif ($f->parent) {
( run in 0.369 second using v1.01-cache-2.11-cpan-e1769b4cff6 )