| 1 | #!/usr/bin/env perl | ||||||||||
| 2 | package File::Find::Fast; | ||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | #use Class::Interface qw/implements/; | ||||||||||
| 6 | 2 | ▶ | use Exporter qw(import); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use File::Basename qw/fileparse basename dirname/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use File::Temp qw/tempdir tempfile/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use Carp qw/croak confess/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | our $VERSION = '0.2.1'; | |||||||||
| 14 | |||||||||||
| 15 | 2 | our @EXPORT_OK = qw(find); | |||||||||
| 16 | |||||||||||
| 17 | 2 | local $0=basename $0; | |||||||||
| 18 | |||||||||||
| 19 | # If this is used in a scalar context, $self->toString() is called | ||||||||||
| 20 | 2 | ▶ | use overload '""' => 'toString'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 2 | ▶ | my($dir) = @_; | ||||||||
|
Subroutine
find: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 46 | |||||||||||
| 47 | 2 | my @file = ($dir); | |||||||||
| 48 | |||||||||||
| 49 | 2 | ▶ | if(!-d $dir){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | croak "ERROR: $dir is not a directory"; | |||||||||
| 51 | } | ||||||||||
| 52 | 2 | _find_recursive($dir, \@file); | |||||||||
| 53 | |||||||||||
| 54 | 2 | return \@file; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | sub _find_recursive{ | ||||||||||
| 58 | 6 | ▶ | my($parentDir, $files) = @_; | ||||||||
|
Subroutine
_find_recursive: called CC=5 SCAR=16.1
| |||||||||||
| 59 | |||||||||||
| 60 | 6 | ▶ | opendir(my $dh, $parentDir) || confess "Can't opendir $parentDir: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 6 | ▶ | while(my $file = readdir($dh)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 18 | ▶ | next if($file =~ /^\.{1,2}$/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 6 | my $path = "$parentDir/$file"; | |||||||||
| 64 | #my $path = File::Spec->catfile($parentDir, $file); | ||||||||||
| 65 | 6 | push(@$files, $path); | |||||||||
| 66 | 6 | ▶ | if(-d $path){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 4 | _find_recursive($path, $files); | |||||||||
| 68 | } | ||||||||||
| 69 | } | ||||||||||
| 70 | 6 | closedir($dh); | |||||||||
| 71 | 6 | return 1; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 2 | 1; | |||||||||
| 75 | |||||||||||