/usr/share/perl5/Data/Stream/Bulk/Path/Class.pm is in libdata-stream-bulk-perl 0.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | package Data::Stream::Bulk::Path::Class;
BEGIN {
$Data::Stream::Bulk::Path::Class::AUTHORITY = 'cpan:NUFFIN';
}
{
$Data::Stream::Bulk::Path::Class::VERSION = '0.11';
}
use Moose;
# ABSTRACT: L<Path::Class::Dir> traversal
use Path::Class;
use Carp qw(croak);
use namespace::clean -except => 'meta';
with qw(Data::Stream::Bulk);
has dir => (
isa => "Path::Class::Dir",
is => "ro",
required => 1,
);
has depth_first => (
isa => "Bool",
is => "rw",
default => 1,
);
has only_files => (
isa => "Bool",
is => "ro",
);
has chunk_size => (
isa => "Int",
is => "rw",
default => 250,
);
has _stack => (
isa => "ArrayRef",
is => "ro",
default => sub { [] },
);
has _queue => (
isa => "ArrayRef",
is => "ro",
lazy => 1,
default => sub {
my $self = shift;
return [ $self->dir ],
},
);
sub is_done {
my $self = shift;
return (
@{ $self->_stack } == 0
and
@{ $self->_queue } == 0
);
}
sub next {
my $self = shift;
my $queue = $self->_queue;
my $stack = $self->_stack;
my $depth_first = $self->depth_first;
my $only_files = $self->only_files;
my $chunk_size = $self->chunk_size;
my @ret;
{
outer: while ( @$stack ) {
my $frame = $stack->[-1];
my ( $dh, $parent ) = @$frame;
while ( defined(my $entry = $dh->read) ) {
next if $entry eq '.' || $entry eq '..';
my $path = $parent->file($entry);
if ( -d $path ) {
my $dir = $parent->subdir($entry);
if ( $depth_first ) {
unshift @$queue, $dir;
} else {
push @$queue, $dir;
}
last outer;
} else {
push @ret, $path;
return \@ret if @ret >= $chunk_size;
}
}
# we're done reading this dir
pop @$stack;
}
if ( @$queue ) {
my $dir = shift @$queue;
my $dh = $dir->open || croak("Can't open directory $dir: $!");
if ( $depth_first ) {
push @$stack, [ $dh, $dir ];
} else {
unshift @$stack, [ $dh, $dir ];
}
unless ( $only_files ) {
push @ret, $dir;
return \@ret if @ret >= $chunk_size;
}
redo;
}
}
return unless @ret;
return \@ret;
}
__PACKAGE__->meta->make_immutable;
__PACKAGE__;
=pod
=head1 NAME
Data::Stream::Bulk::Path::Class - L<Path::Class::Dir> traversal
=head1 VERSION
version 0.11
=head1 SYNOPSIS
use Data::Stream::Bulk::Path::Class;
my $dir = Data::Stream::Bulk::Path::Class->new(
dir => Path::Class::Dir->new( ... ),
);
=head1 DESCRIPTION
This stream produces depth or breadth first traversal order recursion through
L<Path::Class::Dir> objects.
Items are read iteratively, and a stack of open directory handles is used to
keep track of state.
=head1 ATTRIBUTES
=over 4
=item chunk_size
Defaults to 250.
=item depth_first
Chooses between depth first and breadth first traversal order.
=item only_files
If true only L<Path::Class::File> items will be returned in the output streams
(no directories).
=back
=head1 METHODS
=over 4
=item is_done
Returns true when no more files are left to iterate.
=item next
Returns the next chunk of L<Path::Class> objects
=back
=head1 AUTHOR
Yuval Kogman <nothingmuch@woobling.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Yuval Kogman.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
__END__
|