blib/lib/File/Find/Fast.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 69 CC 4 SCAR 15.5
CC
4
Cov
0%
_find_recursive
12.0
find
6.0
BEGIN
2.0
CRAP 4.7
1 #!/usr/bin/env perl
2 package File::Find::Fast;
3 use strict;
4 use warnings;
5 #use Class::Interface qw/implements/;
6 use Exporter qw(import);
7 use File::Basename qw/fileparse basename dirname/;
8 use File::Temp qw/tempdir tempfile/;
9 use File::Spec;
10 use Data::Dumper;
11 use Carp qw/croak confess/;
12  
13 our $VERSION = '0.2.1';
14  
15 our @EXPORT_OK = qw(find);
16  
17 local $0=basename $0;
18  
19 # If this is used in a scalar context, $self->toString() is called
20 use overload '""' => 'toString';
21  
22 =pod
23  
24 =head1 NAME
25  
26 File::Find::Fast
27  
28 =head1 SYNOPSIS
29  
30 A module to find files much more quickly than File::Find
31  
32 =head1 DESCRIPTION
33  
34 =head1 METHODS
35  
36 =over
37  
38 =item find()
39  
40 =back
41  
42 =cut
43  
44 sub find{
45 my($dir) = @_;
46  
47 my @file = ($dir);
48  
49 if(!-d $dir){
50 croak "ERROR: $dir is not a directory";
51 }
52 _find_recursive($dir, \@file);
53  
54 return \@file;
55 }
56  
57 sub _find_recursive{
58 my($parentDir, $files) = @_;
59  
60 opendir(my $dh, $parentDir) || confess "Can't opendir $parentDir: $!";
61 while(my $file = readdir($dh)){
62 next if($file =~ /^\.{1,2}$/);
63 my $path = "$parentDir/$file";
64 #my $path = File::Spec->catfile($parentDir, $file);
65 push(@$files, $path);
66 if(-d $path){
67 _find_recursive($path, $files);
68 }
69 }
70 closedir($dh);
71 return 1;
72 }
73  
74 1;
75