| 1 | package IO::Dir::Recursive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use IO::All; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use IO::Dir qw(DIR_UNLINK); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | our @ISA = qw(IO::Dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | IO::Dir::Recursive - IO::Dir working recursive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | use IO::Dir::Recursive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | my $dh = IO::Dir::Recursive->new('.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | print "$_\n" while $dh->read(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | tie my %dir, 'IO::Dir::Recursive', '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | print $dir{subdir1}->{subdir2}->{file}->slurp(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | IO::Dir::Recursive gives IO::Dir the ability to work recursive. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | =head1 EXPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | The following constans may be imported on request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | =item * DIR_NOUPWARDS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | This constant can be passed as option to tie to strip out parent directories. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | =item * DIR_UNLINK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | This is inherited from IO::Dir. Deleting an element from the hash will delete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | the corresponding file or subdirectory if this constant is passed as a tie | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | our @EXPORT_OK = qw(DIR_NOUPWARDS); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | sub DIR_NOUPWARDS () { 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | IO::Dir::Recursive inherits from IO::Dir and therefor inherits all its methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | with the following exceptions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | =head2 read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | my $item = $dh->read(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | Reads the next item in $dh and returns the coresponding object for the item: an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | IO::Dir::Recursive instance for directories, an IO::All instance for files or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | undef if there are no other items left. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $dh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | return $dh->_create_io_obj(scalar $dh->_read(@_)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | =head2 _read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | my $next = $dh->_read(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Same as read() above, but returns a string describing the next item instead of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | an object. Mainly for internal use, but maybe it's useful in some other places, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | too. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 20 | ▶ | sub _read { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 20 | my $dh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 20 | return $dh->SUPER::read(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 8 | ▶ | sub _create_io_obj { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_io_obj: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 8 | my ($dh, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 8 | ▶ | return undef unless $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | ▶ | return $dh if $key eq '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | my $file = File::Spec->catdir(${*$dh}{io_dir_path}, $key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 8 | ▶ | return IO::Dir::Recursive->new(File::Spec->updir($file)) if $key eq '..'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | if (-d $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 5 | tie my %subdir, 'IO::Dir::Recursive', $file, (${*$dh}{io_dir_unlink} | ${*$dh}{io_dir_noupwards}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 5 | return \%subdir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | $file = File::Spec->catfile(${*$dh}{io_dir_path}, $key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | ▶ | return IO::All->new($file) if -e $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 7 | ▶ | sub TIEHASH { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 7 | my ($class, $dir, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 7 | ▶ | my $dh = $class->new($dir) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 7 | ▶ | $options ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options ||= 0
MC/DC100%1/1
$options ||= 0
$options
Truth table100%2/2
A
A= $options
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | ${*$dh}{io_dir_unlink} = $options & DIR_UNLINK; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 7 | ${*$dh}{io_dir_noupwards} = $options & DIR_NOUPWARDS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 7 | return $dh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | ▶ | sub FIRSTKEY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FIRSTKEY: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 4 | my $dh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | $dh->rewind(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | my $key = $dh->_read(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | ▶ | return undef unless defined $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 4 | ▶ | while (${*$dh}{io_dir_noupwards} && defined $key && ($key eq '.' || $key eq '..')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
do {
*$dh
}->{"io_dir_noupwards"} and defined $key and $key eq "." || $key eq ".."
do {
*$dh
}->{"io_dir_noupwards"} and defined $key
$key eq "." or $key eq ".."
MC/DC50%2/4
do {
*$dh
}->{"io_dir_noupwards"} and defined $key and $key eq "." || $key eq ".."
do {
*$dh
}->{"io_dir_noupwards"}
defined $key
$key eq "."
$key eq ".."
Truth table60%3/5
A and B and C or D
A= do {
*$dh
}->{"io_dir_noupwards"}B= defined $keyC= $key eq "."D= $key eq ".."
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | $key = $dh->NEXTKEY(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 14 | ▶ | sub NEXTKEY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
NEXTKEY: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 14 | my $dh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 14 | my $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 14 | $key = $dh->_read(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 16 | ▶ | return undef unless defined $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 12 | ▶ | redo if ${*$dh}{io_dir_noupwards} && ($key eq '.' || $key eq '..'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
do {
*$dh
}->{"io_dir_noupwards"} and $key eq "." || $key eq ".."
$key eq "." or $key eq ".."
MC/DC66%2/3
do {
*$dh
}->{"io_dir_noupwards"} and $key eq "." || $key eq ".."
do {
*$dh
}->{"io_dir_noupwards"}
$key eq "."
$key eq ".."
Truth table75%3/4
A and B or C
A= do {
*$dh
}->{"io_dir_noupwards"}B= $key eq "."C= $key eq ".."
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 10 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 8 | my ($dh, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 8 | $dh->_create_io_obj($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | L<IO::Dir>, L<IO::All> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | Florian Ragwitz, E<lt>flora@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | Copyright (C) 2005 by Florian Ragwitz | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | it under the same terms as Perl itself, either Perl version 5.8.7 or, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||