File-Find-Rule-Filesys-Virtual-1.22/0002775000175000017500000000000010441310007017252 5ustar richardcrichardcFile-Find-Rule-Filesys-Virtual-1.22/t/0002775000175000017500000000000010441310007017515 5ustar richardcrichardcFile-Find-Rule-Filesys-Virtual-1.22/t/subdir/0002775000175000017500000000000010441310007021005 5ustar richardcrichardcFile-Find-Rule-Filesys-Virtual-1.22/t/subdir/bigfile0000664000175000017500000000000610441310007022323 0ustar richardcrichardcirony File-Find-Rule-Filesys-Virtual-1.22/t/findvirtual.t0000664000175000017500000000361710441310007022236 0ustar richardcrichardc#!perl -w use strict; use Test::More tests => 8; use File::Find::Rule; use File::Find::Rule::Filesys::Virtual; use Filesys::Virtual::Plain; use Cwd; if (eval { require Test::Differences; 1 }) { no warnings 'redefine'; *is_deeply = \&Test::Differences::eq_or_diff; } my $virtual = Filesys::Virtual::Plain->new({ root_path => getcwd, cwd => '/', root => '/', }); sub new_real { File::Find::Rule->new } sub new_virt { File::Find::Rule::Filesys::Virtual->new->virtual( $virtual ) } isa_ok( new_real, "File::Find::Rule" ); isa_ok( new_virt, "File::Find::Rule::Filesys::Virtual" ); is_deeply( [ new_virt->file->name('*.t')->in( 't' ) ], [ new_real->file->name('*.t')->in( 't' ) ], "files in t/" ); is_deeply( [ new_virt->size('>600')->name('*.t')->in( 't' ) ], [ new_real->size('>600')->name('*.t')->in( 't' ) ], "stat in t/" ); is_deeply( [ new_virt->or( new_virt->name('.svn')->prune->discard, new_virt->file )->in( 't' ) ], [ new_real->or( new_real->name('.svn')->prune->discard, new_real->file )->in( 't' ) ], "prune .svn" ); is_deeply( [ new_virt->grep(qr/irony/)->in('t') ], [ new_real->grep(qr/irony/)->in('t') ], "find irony in our big file"); # the in may not always be a directory is_deeply( [ new_virt->size('>600')->name('*.t')->in( 't/findvirtual.t' ) ], [ new_real->size('>600')->name('*.t')->in( 't/findvirtual.t' ) ], "stat of t/findvirtual.t" ); # and it may be a file and a directory is_deeply( [ new_virt->size('>600')->name('*.t')->in( 't/findvirtual.t', 't/subdir' ) ], [ new_real->size('>600')->name('*.t')->in( 't/findvirtual.t', 't/subdir' ) ], "stat of t/findvirtual.t t/subdir" ); File-Find-Rule-Filesys-Virtual-1.22/MANIFEST0000664000175000017500000000020410441310007020375 0ustar richardcrichardcChanges META.yml Makefile.PL Build.PL lib/File/Find/Rule/Filesys/Virtual.pm MANIFEST MANIFEST.SKIP t/findvirtual.t t/subdir/bigfile File-Find-Rule-Filesys-Virtual-1.22/lib/0002775000175000017500000000000010441310007020020 5ustar richardcrichardcFile-Find-Rule-Filesys-Virtual-1.22/lib/File/0002775000175000017500000000000010441310007020677 5ustar richardcrichardcFile-Find-Rule-Filesys-Virtual-1.22/lib/File/Find/0002775000175000017500000000000010441310007021557 5ustar richardcrichardcFile-Find-Rule-Filesys-Virtual-1.22/lib/File/Find/Rule/0002775000175000017500000000000010441310007022466 5ustar richardcrichardcFile-Find-Rule-Filesys-Virtual-1.22/lib/File/Find/Rule/Filesys/0002775000175000017500000000000010441310007024104 5ustar richardcrichardcFile-Find-Rule-Filesys-Virtual-1.22/lib/File/Find/Rule/Filesys/Virtual.pm0000664000175000017500000001125110441310007026066 0ustar richardcrichardcpackage File::Find::Rule::Filesys::Virtual; use strict; use warnings; use File::Find::Rule 0.28; use base qw( File::Find::Rule ); our $VERSION = 1.22; =head1 NAME File::Find::Rule::Filesys::Virtual - File::Find::Rule adapted to Filesys::Virtual =head1 SYNOPSIS use File::Find::Rule::Filesys::Virtual; use Filesys::Virtual::Ninja; my $vfs = Filesys::Virtual::Ninja->new; my @virtual_ninja_foos = File::Find::Rule::Filesys::Virtual ->virtual( $vfs ) ->name( "foo.*' ) ->in( '/' ); =head1 DESCRIPTION This module allows you to use File::Find::Rule file finding semantics to Filesys::Virtual derived filesystems. =cut BEGIN { *_force_object = \&File::Find::Rule::_force_object } sub virtual { my $self = _force_object shift; $self->{_virtual} = shift; return $self; } our %X_tests; *X_tests = \%File::Find::Rule::X_tests; for my $test (keys %X_tests) { $test =~ s/^-//; my $sub = eval 'sub () { my $self = _force_object shift; push @{ $self->{rules} }, { code => "\$File::Find::vfs->test(q{' . $test . '}, \$_)", rule => "'.$X_tests{"-$test"}.'", }; return $self; } '; no strict 'refs'; *{ $X_tests{"-$test"} } = $sub; } { our @stat_tests; *stat_tests = \@File::Find::Rule::stat_tests; my $i = 0; for my $test (@stat_tests) { my $index = $i++; # to close over my $sub = sub { my $self = _force_object shift; my @tests = map { Number::Compare->parse_to_perl($_) } @_; push @{ $self->{rules} }, { rule => $test, args => \@_, code => 'do { my $val = ($File::Find::vfs->stat($_))['.$index.'] || 0;'. join ('||', map { "(\$val $_)" } @tests ).' }', }; return $self; }; no strict 'refs'; *$test = $sub; } } sub grep { my $self = _force_object shift; my @pattern = map { ref $_ ? ref $_ eq 'ARRAY' ? map { [ ( ref $_ ? $_ : qr/$_/ ) => 0 ] } @$_ : [ $_ => 1 ] : [ qr/$_/ => 1 ] } @_; $self->exec( sub { my $vfs = $File::Find::vfs; my $fh = $vfs->open_read($_) or return; local ($_, $.); while (<$fh>) { for my $p (@pattern) { my ($rule, $ret) = @$p; if (ref $rule eq 'Regexp' ? /$rule/ : $rule->(@_)) { $vfs->close_read($fh); return $ret; } } } $vfs->close_read($fh); return; } ); } sub _call_find { my $self = shift; my %args = %{ shift() }; my $path = shift; my $vfs = local $File::Find::vfs = $self->{_virtual}; my $cwd = $vfs->cwd; __inner_find( $args{wanted}, $path, "" ); $vfs->chdir( $cwd ); } # fake the behaviour of File::Find. It burns! sub __inner_find { my $wanted = shift; my $path = shift; my $parent = shift; my $vfs = $File::Find::vfs; unless ( $vfs->chdir( $path ) ) { # Couldn't chdir into it, so we see if it's a file. # Actually because there are many forms of "file" (plain, # symlink, socket, block, character) we just check if it # exists and that it's not a directory. if ($vfs->test('e', $path) && !$vfs->test('d', $path)) { my ($dir, $name) = $path =~ m{^(.*/)(.*)}; local $_ = $name; local $File::Find::dir = $dir; local $File::Find::name = $path; local $File::Find::prune; $vfs->chdir($dir); $wanted->(); } return; # I have no clue - bail } local $File::Find::dir = $parent ? "$parent/$path" : $path; for my $name ($vfs->list) { local $_ = $name; local $File::Find::name = "$File::Find::dir/$name"; local $File::Find::prune; #print "_: $_\n"; #print "dir: $File::Find::dir\n"; #print "name: $File::Find::name\n"; $wanted->(); if ($vfs->test("d", $name ) && !$File::Find::prune && $name !~ /^\..?$/) { my $cwd = $vfs->cwd; __inner_find( $wanted, $name, $File::Find::dir ); $vfs->chdir( $cwd ); } } } 1; __END__ =head1 CAVEATS =over =item The File::Find emulation will probably not be full enough for other File::Find::Rule extensions to do their thang. =back =head1 AUTHOR Richard Clamp =head1 COPYRIGHT Copyright 2004, 2006 Richard Clamp. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L, L =cut File-Find-Rule-Filesys-Virtual-1.22/MANIFEST.SKIP0000664000175000017500000000026610441310007021152 0ustar richardcrichardcCVS/.* \.svn/.* \.cvsignore$ \.Inline/.* _Inline/.* \.bak$ \.tar$ \.tgz$ \.tar\.gz$ ~$ ^mess/ ^tmp/ ^testdata/ ^blib/ ^Makefile$ ^Makefile\.[a-z]+$ ^Build$ ^pm_to_blib$ ^_build/.* ~$File-Find-Rule-Filesys-Virtual-1.22/META.yml0000664000175000017500000000071610441310007020525 0ustar richardcrichardc--- name: File-Find-Rule-Filesys-Virtual version: 1.22 author: - Richard Clamp abstract: File::Find::Rule adapted to Filesys::Virtual license: perl requires: File::Find::Rule: 0.28 Filesys::Virtual: 0 perl: 5.006 build_requires: Filesys::Virtual::Plain: 0 Test::More: 0 provides: File::Find::Rule::Filesys::Virtual: file: lib/File/Find/Rule/Filesys/Virtual.pm version: 1.22 generated_by: Module::Build version 0.25 File-Find-Rule-Filesys-Virtual-1.22/Changes0000664000175000017500000000043510441310007020545 0ustar richardcrichardc1.22 Tuesday 6th June, 2006 Fixed a dependency error caused by the Filesys::Virtual distribution being split up. Norman Nunley implemented ->grep Fixed the TODO case of what to do when an argument to ->in is a file. 1.21 Tuesday 18th May, 2004 Initial CPAN release File-Find-Rule-Filesys-Virtual-1.22/Build.PL0000664000175000017500000000120610441310007020543 0ustar richardcrichardcuse strict; use Module::Build; Module::Build->new( module_name => 'File::Find::Rule::Filesys::Virtual', license => 'perl', requires => { 'perl' => 5.006, 'Filesys::Virtual' => 0, # only really needed for the tests, # but if you're not going to install # it what the heck do you want with # this module? 'File::Find::Rule' => 0.28, }, build_requires => { 'Filesys::Virtual::Plain' => 0, 'Test::More' => 0, }, create_makefile_pl => 'traditional', )->create_build_script; File-Find-Rule-Filesys-Virtual-1.22/Makefile.PL0000664000175000017500000000111710441310007021222 0ustar richardcrichardc# Note: this file was auto-generated by Module::Build::Compat version 0.03 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'File::Find::Rule::Filesys::Virtual', 'VERSION_FROM' => 'lib/File/Find/Rule/Filesys/Virtual.pm', 'PREREQ_PM' => { 'File::Find::Rule' => '0.28', 'Filesys::Virtual' => '0', 'Filesys::Virtual::Plain' => '0', 'Test::More' => '0' }, 'INSTALLDIRS' => 'site', 'PL_FILES' => {} ) ;