view release on metacpan or search on metacpan
- change translate from ru to en
0.0.8 2024-11-08T16:27:58Z
- add subroutines "path" and "transpath" with more OS
0.0.7 2024-09-17T22:22:33Z
- add subroutines path and sta. sta while on ro
- find optimize by memory
- find safe use $_ in filters, noenter and errorenter
- find may be stop with find_stop
0.0.6 2023-11-15T09:59:00Z
- add unsupported os
0.0.5 2023-11-15T09:28:51Z
- fix pod
lay mkpath "hello/big/world.txt", "hellow!";
lay mkpath "hello/small/world.txt", "noenter";
mtime "hello"; # ~> ^\d+(\.\d+)?$
[map cat, grep -f, find ["hello/big", "hello/small"]]; # --> [qw/ hellow! noenter /]
my @noreplaced = replace { s/h/$a $b H/ }
find "hello", "-f", "*.txt", qr/\.txt$/, sub { /\.txt$/ },
noenter "*small*",
errorenter { warn "find $_: $!" };
\@noreplaced; # --> ["hello/moon.txt"]
cat "hello/world.txt"; # => hello/world.txt :utf8 Hi!
cat "hello/moon.txt"; # => noreplace
cat "hello/big/world.txt"; # => hello/big/world.txt :utf8 Hellow!
cat "hello/small/world.txt"; # => noenter
[find "hello", "*.txt"]; # --> [qw! hello/moon.txt hello/world.txt hello/big/world.txt hello/small/world.txt !]
* ÐÑÑалÑнÑе ÑÑÑоки пÑевÑаÑаÑÑÑÑ ÑÑнкÑией `wildcard` (Ñм. ниже) в ÑегÑлÑÑное вÑÑажение Ð´Ð»Ñ Ð¿ÑовеÑки каждого пÑÑи.
ÐÑÑи, не пÑоÑедÑие пÑовеÑÐºÑ `@filters`, не возвÑаÑаÑÑÑÑ.
ÐÑли ÑилÑÑÑ -X не ÑвлÑеÑÑÑ Ñайловой ÑÑнкÑией perl, Ñо вÑбÑаÑÑваеÑÑÑ Ð¸ÑклÑÑение:
```perl
eval { find "example", "-h" }; $@ # ~> Undefined subroutine &Aion::Fs::h called
```
Ð ÑÑом пÑимеÑе `find` не Ð¼Ð¾Ð¶ÐµÑ Ð²Ð¾Ð¹Ñи в подкаÑалог и пеÑедаÑÑ Ð¾ÑÐ¸Ð±ÐºÑ Ð² ÑÑнкÑÐ¸Ñ `errorenter` (Ñм. ниже) Ñ ÑÑÑановленнÑми пеÑеменнÑми `$_` и `$!` (пÑÑÑм к Ð...
**Ðнимание!** ÐÑли `errorenter` не Ñказана, Ñо вÑе оÑибки **игноÑиÑÑÑÑÑÑ**!
```perl
mkpath ["example/", 0];
[find "example"] # --> ["example"]
[find "example", noenter "-d"] # --> ["example"]
eval { find "example", errorenter { die "find $_: $!" } }; $@ # ~> find example: Permission denied
mkpath for qw!ex/1/11 ex/1/12 ex/2/21 ex/2/22!;
my $count = 0;
find "ex", sub { find_stop if ++$count == 3; 1};
$count # -> 3
```
### See also
* [Path::Extended::Dir](https://metacpan.org/pod/Path::Extended::Dir) â `@paths = Path::Extended::Dir->new($dir)->find('*.txt')`.
* [Path::Iterator::Rule](https://metacpan.org/pod/Path::Iterator::Rule) â `$i = Path::Iterator::Rule->new->file; @paths = $i->clone->size(">10k")->all(@dirs); $i->size("<10k")...`.
* [Path::Class::Each](https://metacpan.org/pod/Path::Class::Each) â `dir($dir)->each(sub { push @paths, "$_" })`.
* [Path::Class::Iterator](https://metacpan.org/pod/Path::Class::Iterator) â `$i = Path::Class::Iterator->new(root => $dir, depth => 2); until ($i->done) { push @paths, $i->next->stringify }`.
* [Path::Class::Rule](https://metacpan.org/pod/Path::Class::Rule) â `@paths = Path::Class::Rule->new->file->size(">10k")->all($dir)`.
## noenter (@filters)
ÐовоÑÐ¸Ñ `find` не вÑ
одиÑÑ Ð² каÑалоги ÑооÑвеÑÑÑвÑÑÑие ÑилÑÑÑам за ним.
## errorenter (&block)
ÐÑзÑÐ²Ð°ÐµÑ `&block` Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð¹ оÑибки возникаÑÑей пÑи невозможноÑÑи войÑи в какой-либо каÑалог.
## find_stop ()
ÐÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ `find` бÑдÑÑи вÑзван в одном из его ÑилÑÑÑов, `errorenter` или `noenter`.
```perl
my $count = 0;
find "ex", sub { find_stop if ++$count == 3; 1};
$count # -> 3
```
## erase (@paths)
УдалÑÐµÑ ÑÐ°Ð¹Ð»Ñ Ð¸ пÑÑÑÑе каÑалоги. ÐозвÑаÑÐ°ÐµÑ `@paths`. ÐÑи оÑибке ввода-вÑвода вÑбÑаÑÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑение.
i18n/Aion/Fs.ru-en.po view on Meta::CPAN
"* Regexp â tests each path with a regular expression.\n"
"* String in the form \"-Xxx\", where `Xxx` is one or more characters. Similar to Perl operators for testing files. Example: `-fr` checks the path with file testers [-f and -r](https://perldoc.perl.org/functions/-X).\n"
"* The remaining lines are turned by the `wildcard` function (see below) into a regular expression to test each path."
msgid "ÐÑÑи, не пÑоÑедÑие пÑовеÑÐºÑ `@filters`, не возвÑаÑаÑÑÑÑ."
msgstr "Paths that fail the `@filters` check are not returned."
msgid "ÐÑли ÑилÑÑÑ -X не ÑвлÑеÑÑÑ Ñайловой ÑÑнкÑией perl, Ñо вÑбÑаÑÑваеÑÑÑ Ð¸ÑклÑÑение:"
msgstr "If the -X filter is not a perl file function, an exception is thrown:"
msgid "Ð ÑÑом пÑимеÑе `find` не Ð¼Ð¾Ð¶ÐµÑ Ð²Ð¾Ð¹Ñи в подкаÑалог и пеÑедаÑÑ Ð¾ÑÐ¸Ð±ÐºÑ Ð² ÑÑнкÑÐ¸Ñ `errorenter` (Ñм. ниже) Ñ ÑÑÑановленнÑми пеÑеменнÑми `$_` и `$!` (пÑÑÑ...
msgstr "In this example, `find` cannot enter the subdirectory and passes an error to the `errorenter` function (see below) with the `$_` and `$!` variables set (to the directory path and the OS error message)."
msgid "**Ðнимание!** ÐÑли `errorenter` не Ñказана, Ñо вÑе оÑибки **игноÑиÑÑÑÑÑÑ**!"
msgstr "**Attention!** If `errorenter` is not specified, then all errors are **ignored**!"
msgid ""
"* [AudioFile::Find](https://metacpan.org/pod/AudioFile::Find) â иÑÐµÑ Ð°ÑдиоÑÐ°Ð¹Ð»Ñ Ð² Ñказанной диÑекÑоÑии. ÐозволÑÐµÑ ÑилÑÑÑоваÑÑ Ð¸Ñ
по аÑÑибÑÑам: названиÑ, аÑÑиÑÑÑ, жÐ...
"* [Directory::Iterator](https://metacpan.org/pod/Directory::Iterator) â `$it = Directory::Iterator->new($dir, %opts); push @paths, $_ while <$it>`.\n"
"* [IO::All](https://metacpan.org/pod/IO::All) â `@paths = map { \"$_\" } grep { -f $_ && $_->size > 10*1024 } io(\".\")->all(0)`.\n"
"* [IO::All::Rule](https://metacpan.org/pod/IO::All::Rule) â `$next = IO::All::Rule->new->file->size(\">10k\")->iter($dir1, $dir2); push @paths, \"$f\" while $f = $next->()`.\n"
"* [File::Find](https://metacpan.org/pod/File::Find) â `find( sub { push @paths, $File::Find::name if /\\.png/ }, $dir )`.\n"
"* [File::Find::utf8](https://metacpan.org/pod/File::Find::utf8) â как [File::Find](https://metacpan.org/pod/File::Find), ÑолÑко пÑÑи Ñайлов в _utf8_.\n"
"* [File::Find::Age](https://metacpan.org/pod/File::Find::Age) â ÑоÑÑиÑÑÐµÑ ÑÐ°Ð¹Ð»Ñ Ð¿Ð¾ вÑемени модиÑикаÑии (наÑледÑÐµÑ [File::Find::Rule](https://metacpan.org/pod/File::Find::Rule)): `File::Find::Age->in($dir1...
"* [File::Find::Declare](https://metacpan.org/pod/File::Find::Declare) â `@paths = File::Find::Declare->new({ size => '>10K', perms => 'wr-wr-wr-', modified => '<2010-01-30', recurse => 1, dirs => [$dir1] })->find`.\n"
i18n/Aion/Fs.ru-en.po view on Meta::CPAN
"* [Path::Extended::Dir](https://metacpan.org/pod/Path::Extended::Dir) â `@paths = Path::Extended::Dir->new($dir)->find('*.txt')`.\n"
"* [Path::Iterator::Rule](https://metacpan.org/pod/Path::Iterator::Rule) â `$i = Path::Iterator::Rule->new->file; @paths = $i->clone->size(\">10k\")->all(@dirs); $i->size(\"<10k\")...`.\n"
"* [Path::Class::Each](https://metacpan.org/pod/Path::Class::Each) â `dir($dir)->each(sub { push @paths, \"$_\" })`.\n"
"* [Path::Class::Iterator](https://metacpan.org/pod/Path::Class::Iterator) â `$i = Path::Class::Iterator->new(root => $dir, depth => 2); until ($i->done) { push @paths, $i->next->stringify }`.\n"
"* [Path::Class::Rule](https://metacpan.org/pod/Path::Class::Rule) â `@paths = Path::Class::Rule->new->file->size(\">10k\")->all($dir)`."
msgid "ÐовоÑÐ¸Ñ `find` не вÑ
одиÑÑ Ð² каÑалоги ÑооÑвеÑÑÑвÑÑÑие ÑилÑÑÑам за ним."
msgstr "Tells `find` not to enter directories matching the filters behind it."
msgid "ÐÑзÑÐ²Ð°ÐµÑ `&block` Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð¹ оÑибки возникаÑÑей пÑи невозможноÑÑи войÑи в какой-либо каÑалог."
msgstr "Calls `&block` for every error that occurs when a directory cannot be entered."
msgid "ÐÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ `find` бÑдÑÑи вÑзван в одном из его ÑилÑÑÑов, `errorenter` или `noenter`."
msgstr "Stops `find` being called in one of its filters, `errorenter` or `noenter`."
msgid "УдалÑÐµÑ ÑÐ°Ð¹Ð»Ñ Ð¸ пÑÑÑÑе каÑалоги. ÐозвÑаÑÐ°ÐµÑ `@paths`. ÐÑи оÑибке ввода-вÑвода вÑбÑаÑÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑение."
msgstr "Removes files and empty directories. Returns `@paths`. If there is an I/O error, it throws an exception."
msgid ""
"* `unlink` + `rmdir`.\n"
"* [File::Path](https://metacpan.org/pod/File::Path) â `remove_tree(\"dir\")`.\n"
"* [File::Path::Tiny](https://metacpan.org/pod/File::Path::Tiny) â `File::Path::Tiny::rm($path)`. Ðе вÑбÑаÑÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑений.\n"
"* [Mojo::File](https://metacpan.org/pod/Mojo::File) â `path($file)->remove`."
msgstr ""
"* `unlink` + `rmdir`.\n"
"* [File::Path](https://metacpan.org/pod/File::Path) â `remove_tree(\"dir\")`.\n"
"* [File::Path::Tiny](https://metacpan.org/pod/File::Path::Tiny) â `File::Path::Tiny::rm($path)`. Does not throw exceptions.\n"
lib/Aion/Fs.md view on Meta::CPAN
lay mkpath "hello/big/world.txt", "hellow!";
lay mkpath "hello/small/world.txt", "noenter";
mtime "hello"; # ~> ^\d+(\.\d+)?$
[map cat, grep -f, find ["hello/big", "hello/small"]]; # --> [qw/ hellow! noenter /]
my @noreplaced = replace { s/h/$a $b H/ }
find "hello", "-f", "*.txt", qr/\.txt$/, sub { /\.txt$/ },
noenter "*small*",
errorenter { warn "find $_: $!" };
\@noreplaced; # --> ["hello/moon.txt"]
cat "hello/world.txt"; # => hello/world.txt :utf8 Hi!
cat "hello/moon.txt"; # => noreplace
cat "hello/big/world.txt"; # => hello/big/world.txt :utf8 Hellow!
cat "hello/small/world.txt"; # => noenter
[find "hello", "*.txt"]; # --> [qw! hello/moon.txt hello/world.txt hello/big/world.txt hello/small/world.txt !]
lib/Aion/Fs.md view on Meta::CPAN
* ÐÑÑалÑнÑе ÑÑÑоки пÑевÑаÑаÑÑÑÑ ÑÑнкÑией `wildcard` (Ñм. ниже) в ÑегÑлÑÑное вÑÑажение Ð´Ð»Ñ Ð¿ÑовеÑки каждого пÑÑи.
ÐÑÑи, не пÑоÑедÑие пÑовеÑÐºÑ `@filters`, не возвÑаÑаÑÑÑÑ.
ÐÑли ÑилÑÑÑ -X не ÑвлÑеÑÑÑ Ñайловой ÑÑнкÑией perl, Ñо вÑбÑаÑÑваеÑÑÑ Ð¸ÑклÑÑение:
```perl
eval { find "example", "-h" }; $@ # ~> Undefined subroutine &Aion::Fs::h called
```
Ð ÑÑом пÑимеÑе `find` не Ð¼Ð¾Ð¶ÐµÑ Ð²Ð¾Ð¹Ñи в подкаÑалог и пеÑедаÑÑ Ð¾ÑÐ¸Ð±ÐºÑ Ð² ÑÑнкÑÐ¸Ñ `errorenter` (Ñм. ниже) Ñ ÑÑÑановленнÑми пеÑеменнÑми `$_` и `$!` (пÑÑÑм к Ð...
**Ðнимание!** ÐÑли `errorenter` не Ñказана, Ñо вÑе оÑибки **игноÑиÑÑÑÑÑÑ**!
```perl
mkpath ["example/", 0];
[find "example"] # --> ["example"]
[find "example", noenter "-d"] # --> ["example"]
eval { find "example", errorenter { die "find $_: $!" } }; $@ # ~> find example: Permission denied
mkpath for qw!ex/1/11 ex/1/12 ex/2/21 ex/2/22!;
my $count = 0;
find "ex", sub { find_stop if ++$count == 3; 1};
$count # -> 3
```
### See also
lib/Aion/Fs.md view on Meta::CPAN
* [Path::Extended::Dir](https://metacpan.org/pod/Path::Extended::Dir) â `@paths = Path::Extended::Dir->new($dir)->find('*.txt')`.
* [Path::Iterator::Rule](https://metacpan.org/pod/Path::Iterator::Rule) â `$i = Path::Iterator::Rule->new->file; @paths = $i->clone->size(">10k")->all(@dirs); $i->size("<10k")...`.
* [Path::Class::Each](https://metacpan.org/pod/Path::Class::Each) â `dir($dir)->each(sub { push @paths, "$_" })`.
* [Path::Class::Iterator](https://metacpan.org/pod/Path::Class::Iterator) â `$i = Path::Class::Iterator->new(root => $dir, depth => 2); until ($i->done) { push @paths, $i->next->stringify }`.
* [Path::Class::Rule](https://metacpan.org/pod/Path::Class::Rule) â `@paths = Path::Class::Rule->new->file->size(">10k")->all($dir)`.
## noenter (@filters)
ÐовоÑÐ¸Ñ `find` не вÑ
одиÑÑ Ð² каÑалоги ÑооÑвеÑÑÑвÑÑÑие ÑилÑÑÑам за ним.
## errorenter (&block)
ÐÑзÑÐ²Ð°ÐµÑ `&block` Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð¹ оÑибки возникаÑÑей пÑи невозможноÑÑи войÑи в какой-либо каÑалог.
## find_stop ()
ÐÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ `find` бÑдÑÑи вÑзван в одном из его ÑилÑÑÑов, `errorenter` или `noenter`.
```perl
my $count = 0;
find "ex", sub { find_stop if ++$count == 3; 1};
$count # -> 3
```
## erase (@paths)
УдалÑÐµÑ ÑÐ°Ð¹Ð»Ñ Ð¸ пÑÑÑÑе каÑалоги. ÐозвÑаÑÐ°ÐµÑ `@paths`. ÐÑи оÑибке ввода-вÑвода вÑбÑаÑÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑение.
lib/Aion/Fs.pm view on Meta::CPAN
if(ref $path eq "HASH") {
local $_ = $path;
return $fs->{join}->();
}
($path) = @$path if ref $path;
$path = $fs->{before_split}->($path) if exists $fs->{before_split};
+{
$path =~ $fs->{regexp}? (map { $_ ne "ext" && $+{$_} eq ""? (): ($_ => $+{$_}) } keys %+): (error => 1),
path => $path,
}
}
# ÐеÑÐµÐ²Ð¾Ð´Ð¸Ñ Ð¿ÑÑÑ Ð¸Ð· ÑоÑмаÑа одной ÐС в дÑÑгÑÑ
sub transpath ($$;$) {
my ($path, $from, $to) = @_ == 2? ($_, @_): @_;
my (@dir, @folder, @ext);
{ local $^O = $from;
$path = path $path;
lib/Aion/Fs.pm view on Meta::CPAN
}
else { my $re = wildcard(); sub { $_ =~ $re } }
} @_
}
# ÐайÑи ÑайлÑ
sub find(;@) {
my $files = @_? shift: $_;
$files = [$files] unless ref $files;
my @noenters; my $errorenter = sub {};
my $ex = @_ && ref($_[$#_]) eq 'Aion::Fs::Find'
? pop
: undef;
if($ex) {
bless $ex, 'Aion::Fs';
if(Scalar::Util::reftype $ex eq 'CODE') {
$errorenter = $ex;
} else {
$errorenter = bless pop @$ex, undef if Scalar::Util::reftype($ex->[$#$ex]) eq "CODE";
push @noenters, _filters @$ex;
}
}
my @filters = _filters @_;
my $iter = Aion::Fs::Find->new(
noenters => \@noenters,
errorenter => $errorenter,
filters => \@filters,
files => $files,
);
defined(wantarray)
? (wantarray? @$iter: $iter)
: do { while(defined $iter->next) {} };
}
# Ðе вÑ
одиÑÑ Ð² подкаÑалоги
sub noenter(@) {
bless [@_], "Aion::Fs::Find"
}
# ÐÑзÑваеÑÑÑ Ð´Ð»Ñ Ð²ÑеÑ
оÑибок ввода-вÑвода
sub errorenter(&) {
bless shift, "Aion::Fs::Find"
}
# ÐÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ find бÑдÑÑи вÑзван Ñ Ð¾Ð´Ð½Ð¾Ð³Ð¾ из его ÑилÑÑÑов, errorenter или noenter
sub find_stop() {
die bless \(my $stop = 1), "Aion::Fs::Find"
}
# ÐÑÐ¾Ð¸Ð·Ð²Ð¾Ð´Ð¸Ñ Ð·Ð°Ð¼ÐµÐ½Ñ Ð²Ð¾ вÑеÑ
ÑказаннÑÑ
ÑайлаÑ
. ÐозвÑаÑÐ°ÐµÑ ÑÐ°Ð¹Ð»Ñ Ð² коÑоÑÑÑ
замен не бÑло
sub replace(&@) {
my $fn = shift;
my @noreplace; local $_; my $pkg = caller;
my $aref = "$pkg\::a"; my $bref = "$pkg\::b";
for $$aref (@_) {
lib/Aion/Fs.pm view on Meta::CPAN
lay mkpath "hello/big/world.txt", "hellow!";
lay mkpath "hello/small/world.txt", "noenter";
mtime "hello"; # ~> ^\d+(\.\d+)?$
[map cat, grep -f, find ["hello/big", "hello/small"]]; # --> [qw/ hellow! noenter /]
my @noreplaced = replace { s/h/$a $b H/ }
find "hello", "-f", "*.txt", qr/\.txt$/, sub { /\.txt$/ },
noenter "*small*",
errorenter { warn "find $_: $!" };
\@noreplaced; # --> ["hello/moon.txt"]
cat "hello/world.txt"; # => hello/world.txt :utf8 Hi!
cat "hello/moon.txt"; # => noreplace
cat "hello/big/world.txt"; # => hello/big/world.txt :utf8 Hellow!
cat "hello/small/world.txt"; # => noenter
[find "hello", "*.txt"]; # --> [qw! hello/moon.txt hello/world.txt hello/big/world.txt hello/small/world.txt !]
lib/Aion/Fs.pm view on Meta::CPAN
=item * The remaining lines are turned by the C<wildcard> function (see below) into a regular expression to test each path.
=back
Paths that fail the C<@filters> check are not returned.
If the -X filter is not a perl file function, an exception is thrown:
eval { find "example", "-h" }; $@ # ~> Undefined subroutine &Aion::Fs::h called
In this example, C<find> cannot enter the subdirectory and passes an error to the C<errorenter> function (see below) with the C<$_> and C<$!> variables set (to the directory path and the OS error message).
B<Attention!> If C<errorenter> is not specified, then all errors are B<ignored>!
mkpath ["example/", 0];
[find "example"] # --> ["example"]
[find "example", noenter "-d"] # --> ["example"]
eval { find "example", errorenter { die "find $_: $!" } }; $@ # ~> find example: Permission denied
mkpath for qw!ex/1/11 ex/1/12 ex/2/21 ex/2/22!;
my $count = 0;
find "ex", sub { find_stop if ++$count == 3; 1};
$count # -> 3
=head3 See also
=over
lib/Aion/Fs.pm view on Meta::CPAN
=item * L<Path::Class::Iterator> â C<< $i = Path::Class::Iterator-E<gt>new(root =E<gt> $dir, depth =E<gt> 2); until ($i-E<gt>done) { push @paths, $i-E<gt>next-E<gt>stringify } >>.
=item * L<Path::Class::Rule> â C<< @paths = Path::Class::Rule-E<gt>new-E<gt>file-E<gt>size("E<gt>10k")-E<gt>all($dir) >>.
=back
=head2 noenter (@filters)
Tells C<find> not to enter directories matching the filters behind it.
=head2 errorenter (&block)
Calls C<&block> for every error that occurs when a directory cannot be entered.
=head2 find_stop ()
Stops C<find> being called in one of its filters, C<errorenter> or C<noenter>.
my $count = 0;
find "ex", sub { find_stop if ++$count == 3; 1};
$count # -> 3
=head2 erase (@paths)
Removes files and empty directories. Returns C<@paths>. If there is an I/O error, it throws an exception.
eval { erase "/" }; $@ # ~> erase dir /: Device or resource busy
eval { erase "/dev/null" }; $@ # ~> erase file /dev/null: Permission denied
=head3 See also
=over
=item * C<unlink> + C<rmdir>.
lib/Aion/Fs/Find.md view on Meta::CPAN
Aion::Fs::Find - иÑеÑаÑÐ¾Ñ Ð¿Ð¾Ð¸Ñка Ñайлов Ð´Ð»Ñ Aion::Fs#find
# SYNOPSIS
```perl
use Aion::Fs::Find;
my $iter = Aion::Fs::Find->new(
files => ["."],
filters => [],
errorenter => sub {},
noenters => [],
);
my @files;
while (<$iter>) {
push @files, $_;
}
\@files # --> ["."]
```
lib/Aion/Fs/Find.pm view on Meta::CPAN
if(opendir my $dir, $path) {
my @file;
while(my $f = readdir $dir) {
push @file, Aion::Fs::joindir($path, $f) if $f !~ /^\.{1,2}\z/;
}
push @$files, sort @file;
closedir $dir;
}
else {
local $_ = $path;
$self->{errorenter}->();
};
}
}
my $valid = 1;
for my $filter (@{$self->{filters}}) {
local $_ = $path;
$valid = 0, last unless $filter->();
}
lib/Aion/Fs/Find.pm view on Meta::CPAN
Aion::Fs::Find - file search iterator for Aion::Fs#find
=head1 SYNOPSIS
use Aion::Fs::Find;
my $iter = Aion::Fs::Find->new(
files => ["."],
filters => [],
errorenter => sub {},
noenters => [],
);
my @files;
while (<$iter>) {
push @files, $_;
}
\@files # --> ["."]
t/aion/fs.t view on Meta::CPAN
lay mkpath "hello/big/world.txt", "hellow!";
lay mkpath "hello/small/world.txt", "noenter";
::like scalar do {mtime "hello";}, qr{^\d+(\.\d+)?$}, 'mtime "hello"; # ~> ^\d+(\.\d+)?$'; undef $::_g0; undef $::_e0;
local ($::_g0 = do {[map cat, grep -f, find ["hello/big", "hello/small"]];}, $::_e0 = do {[qw/ hellow! noenter /]}); ::is_deeply $::_g0, $::_e0, '[map cat, grep -f, find ["hello/big", "hello/small"]]; # --> [qw/ hellow! noenter /]' or ::diag ::_stru...
my @noreplaced = replace { s/h/$a $b H/ }
find "hello", "-f", "*.txt", qr/\.txt$/, sub { /\.txt$/ },
noenter "*small*",
errorenter { warn "find $_: $!" };
local ($::_g0 = do {\@noreplaced;}, $::_e0 = do {["hello/moon.txt"]}); ::is_deeply $::_g0, $::_e0, '\@noreplaced; # --> ["hello/moon.txt"]' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {cat "hello/world.txt";}, $::_e0 = "hello/world.txt :utf8 Hi!"); ::ok $::_g0 eq $::_e0, 'cat "hello/world.txt"; # => hello/world.txt :utf8 Hi!' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {cat "hello/moon.txt";}, $::_e0 = "noreplace"); ::ok $::_g0 eq $::_e0, 'cat "hello/moon.txt"; # => noreplace' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {cat "hello/big/world.txt";}, $::_e0 = "hello/big/world.txt :utf8 Hellow!"); ::ok $::_g0 eq $::_e0, 'cat "hello/big/world.txt"; # => hello/big/world.txt :utf8 Hellow!' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef...
local ($::_g0 = do {cat "hello/small/world.txt";}, $::_e0 = "noenter"); ::ok $::_g0 eq $::_e0, 'cat "hello/small/world.txt"; # => noenter' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {[find "hello", "*.txt"];}, $::_e0 = do {[qw! hello/moon.txt hello/world.txt hello/big/world.txt hello/small/world.txt !]}); ::is_deeply $::_g0, $::_e0, '[find "hello", "*.txt"]; # --> [qw! hello/moon.txt hello/world.txt he...
t/aion/fs.t view on Meta::CPAN
# * ÐÑÑалÑнÑе ÑÑÑоки пÑевÑаÑаÑÑÑÑ ÑÑнкÑией `wildcard` (Ñм. ниже) в ÑегÑлÑÑное вÑÑажение Ð´Ð»Ñ Ð¿ÑовеÑки каждого пÑÑи.
#
# ÐÑÑи, не пÑоÑедÑие пÑовеÑÐºÑ `@filters`, не возвÑаÑаÑÑÑÑ.
#
# ÐÑли ÑилÑÑÑ -X не ÑвлÑеÑÑÑ Ñайловой ÑÑнкÑией perl, Ñо вÑбÑаÑÑваеÑÑÑ Ð¸ÑклÑÑение:
#
::done_testing; }; subtest 'find (;$path, @filters)' => sub {
::like scalar do {eval { find "example", "-h" }; $@}, qr{Undefined subroutine &Aion::Fs::h called}, 'eval { find "example", "-h" }; $@ # ~> Undefined subroutine &Aion::Fs::h called'; undef $::_g0; undef $::_e0;
#
# Ð ÑÑом пÑимеÑе `find` не Ð¼Ð¾Ð¶ÐµÑ Ð²Ð¾Ð¹Ñи в подкаÑалог и пеÑедаÑÑ Ð¾ÑÐ¸Ð±ÐºÑ Ð² ÑÑнкÑÐ¸Ñ `errorenter` (Ñм. ниже) Ñ ÑÑÑановленнÑми пеÑеменнÑми `$_` и `$!` (пÑÑÑм к...
#
# **Ðнимание!** ÐÑли `errorenter` не Ñказана, Ñо вÑе оÑибки **игноÑиÑÑÑÑÑÑ**!
#
mkpath ["example/", 0];
local ($::_g0 = do {[find "example"]}, $::_e0 = do {["example"]}); ::is_deeply $::_g0, $::_e0, '[find "example"] # --> ["example"]' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {[find "example", noenter "-d"]}, $::_e0 = do {["example"]}); ::is_deeply $::_g0, $::_e0, '[find "example", noenter "-d"] # --> ["example"]' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
::like scalar do {eval { find "example", errorenter { die "find $_: $!" } }; $@}, qr{find example: Permission denied}, 'eval { find "example", errorenter { die "find $_: $!" } }; $@ # ~> find example: Permission denied'; undef $::_g0; undef $::_e0;
mkpath for qw!ex/1/11 ex/1/12 ex/2/21 ex/2/22!;
my $count = 0;
find "ex", sub { find_stop if ++$count == 3; 1};
local ($::_g0 = do {$count}, $::_e0 = do {3}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, '$count # -> 3' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
#
# ### See also
#
t/aion/fs.t view on Meta::CPAN
# * [Path::Extended::Dir](https://metacpan.org/pod/Path::Extended::Dir) â `@paths = Path::Extended::Dir->new($dir)->find('*.txt')`.
# * [Path::Iterator::Rule](https://metacpan.org/pod/Path::Iterator::Rule) â `$i = Path::Iterator::Rule->new->file; @paths = $i->clone->size(">10k")->all(@dirs); $i->size("<10k")...`.
# * [Path::Class::Each](https://metacpan.org/pod/Path::Class::Each) â `dir($dir)->each(sub { push @paths, "$_" })`.
# * [Path::Class::Iterator](https://metacpan.org/pod/Path::Class::Iterator) â `$i = Path::Class::Iterator->new(root => $dir, depth => 2); until ($i->done) { push @paths, $i->next->stringify }`.
# * [Path::Class::Rule](https://metacpan.org/pod/Path::Class::Rule) â `@paths = Path::Class::Rule->new->file->size(">10k")->all($dir)`.
#
# ## noenter (@filters)
#
# ÐовоÑÐ¸Ñ `find` не вÑ
одиÑÑ Ð² каÑалоги ÑооÑвеÑÑÑвÑÑÑие ÑилÑÑÑам за ним.
#
# ## errorenter (&block)
#
# ÐÑзÑÐ²Ð°ÐµÑ `&block` Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð¹ оÑибки возникаÑÑей пÑи невозможноÑÑи войÑи в какой-либо каÑалог.
#
# ## find_stop ()
#
# ÐÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ `find` бÑдÑÑи вÑзван в одном из его ÑилÑÑÑов, `errorenter` или `noenter`.
#
::done_testing; }; subtest 'find_stop ()' => sub {
my $count = 0;
find "ex", sub { find_stop if ++$count == 3; 1};
local ($::_g0 = do {$count}, $::_e0 = do {3}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, '$count # -> 3' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
#
# ## erase (@paths)
#
# УдалÑÐµÑ ÑÐ°Ð¹Ð»Ñ Ð¸ пÑÑÑÑе каÑалоги. ÐозвÑаÑÐ°ÐµÑ `@paths`. ÐÑи оÑибке ввода-вÑвода вÑбÑаÑÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑение.
t/aion/fs/find.t view on Meta::CPAN
# Aion::Fs::Find - иÑеÑаÑÐ¾Ñ Ð¿Ð¾Ð¸Ñка Ñайлов Ð´Ð»Ñ Aion::Fs#find
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
use Aion::Fs::Find;
my $iter = Aion::Fs::Find->new(
files => ["."],
filters => [],
errorenter => sub {},
noenters => [],
);
my @files;
while (<$iter>) {
push @files, $_;
}
local ($::_g0 = do {\@files}, $::_e0 = do {["."]}); ::is_deeply $::_g0, $::_e0, '\@files # --> ["."]' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;