Aion-Fs
view release on metacpan or search on metacpan
lib/Aion/Fs.md view on Meta::CPAN
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 !]
my @dirs;
my $iter = find "hello", "-d";
while(<$iter>) {
push @dirs, $_;
}
\@dirs; # --> [qw! hello hello/big hello/small !]
erase reverse find "hello";
-e "hello"; # -> undef
```
# DESCRIPTION
ÐÑÐ¾Ñ Ð¼Ð¾Ð´ÑÐ»Ñ Ð¾Ð±Ð»ÐµÐ³ÑÐ°ÐµÑ Ð¸ÑполÑзование Ñайловой ÑиÑÑемÑ.
ÐодÑли `File::Path`, `File::Slurper` и
`File::Find` обÑÐµÐ¼ÐµÐ½ÐµÐ½Ñ ÑазлиÑнÑми возможноÑÑÑми, коÑоÑÑе иÑполÑзÑÑÑÑÑ Ñедко, но ÑÑебÑÑÑ Ð²Ñемени на ознакомление и Ñем ÑамÑм повÑÑаÑÑ Ð¿Ð¾Ñог Ð...
Ð `Aion::Fs` же иÑполÑзован пÑинÑип пÑогÑаммиÑÐ¾Ð²Ð°Ð½Ð¸Ñ KISS - Ñем пÑоÑе, Ñем лÑÑÑе!
СÑпеÑмодÑÐ»Ñ `IO::All` не ÑвлÑеÑÑÑ ÐºÐ¾Ð½ÐºÑÑенÑом `Aion::Fs`, Ñ.к. иÑполÑзÑÐµÑ ÐÐРподÑ
од, а `Aion::Fs` â ФÐ.
* ÐÐÐ â обÑекÑно-оÑиенÑиÑованное пÑогÑаммиÑование.
* ФРâ ÑÑнкÑионалÑное пÑогÑаммиÑование.
# SUBROUTINES/METHODS
## cat ($file)
СÑиÑÑÐ²Ð°ÐµÑ Ñайл. ÐÑли паÑамеÑÑ Ð½Ðµ Ñказан, иÑполÑзÑÐµÑ `$_`.
```perl
cat "/etc/passwd" # ~> root
```
`cat` ÑиÑÐ°ÐµÑ Ñо Ñлоем `:utf8`. Ðо можно ÑказаÑÑ Ð´ÑÑгой Ñлой ÑледÑÑÑим обÑазом:
```perl
lay "unicode.txt", "â¯";
length cat "unicode.txt" # -> 1
length cat["unicode.txt", ":raw"] # -> 3
```
`cat` вÑзÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑение в ÑлÑÑае оÑибки опеÑаÑии ввода-вÑвода:
```perl
eval { cat "A" }; $@ # ~> cat A: No such file or directory
```
### See also
* [autodie](https://metacpan.org/pod/autodie) â `open $f, "r.txt"; $s = join "", <$f>; close $f`.
* [File::Slurp](https://metacpan.org/pod/File::Slurp) â `read_file('file.txt')`.
* [File::Slurper](https://metacpan.org/pod/File::Slurper) â `read_text('file.txt')`, `read_binary('file.txt')`.
* [File::Util](https://metacpan.org/pod/File::Util) â `File::Util->new->load_file(file => 'file.txt')`.
* [IO::All](https://metacpan.org/pod/IO::All) â `io('file.txt') > $contents`.
* [IO::Util](https://metacpan.org/pod/IO::Util) â `$contents = ${ slurp 'file.txt' }`.
* [Mojo::File](https://metacpan.org/pod/Mojo::File) â `path($file)->slurp`.
## lay ($file?, $content)
ÐапиÑÑÐ²Ð°ÐµÑ `$content` в `$file`.
* ÐÑли Ñказан один паÑамеÑÑ, иÑполÑзÑÐµÑ `$_` вмеÑÑо `$file`.
* `lay`, иÑполÑзÑÐµÑ Ñлой `:utf8`. ÐÐ»Ñ ÑÐºÐ°Ð·Ð°Ð½Ð¸Ñ Ð¸Ð½Ð¾Ð³Ð¾ ÑÐ»Ð¾Ñ Ð¸ÑполÑзÑеÑÑÑ Ð¼Ð°ÑÑив из двÑÑ
ÑлеменÑов в паÑамеÑÑе `$file`:
```perl
lay "unicode.txt", "â¯" # => unicode.txt
lay ["unicode.txt", ":raw"], "â¯" # => unicode.txt
eval { lay "/", "â¯" }; $@ # ~> lay /: Is a directory
```
### See also
* [autodie](https://metacpan.org/pod/autodie) â `open $f, ">r.txt"; print $f $contents; close $f`.
* [File::Slurp](https://metacpan.org/pod/File::Slurp) â `write_file('file.txt', $contents)`.
* [File::Slurper](https://metacpan.org/pod/File::Slurper) â `write_text('file.txt', $contents)`, `write_binary('file.txt', $contents)`.
* [IO::All](https://metacpan.org/pod/IO::All) â `io('file.txt') < $contents`.
* [IO::Util](https://metacpan.org/pod/IO::Util) â `slurp \$contents, 'file.txt'`.
* [File::Util](https://metacpan.org/pod/File::Util) â `File::Util->new->write_file(file => 'file.txt', content => $contents, bitmask => 0644)`.
* [Mojo::File](https://metacpan.org/pod/Mojo::File) â `path($file)->spew($chars, 'UTF-8')`.
## find (;$path, @filters)
РекÑÑÑивно обÑ
Ð¾Ð´Ð¸Ñ Ð¸ возвÑаÑÐ°ÐµÑ Ð¿ÑÑи из Ñказанного пÑÑи или пÑÑей, еÑли `$path` ÑвлÑеÑÑÑ ÑÑÑлкой на маÑÑив. Ðез паÑамеÑÑов иÑполÑзÑÐµÑ `$_` каÐ...
ФилÑÑÑÑ Ð¼Ð¾Ð³ÑÑ Ð±ÑÑÑ:
* ÐодпÑогÑаммой â пÑÑÑ Ðº ÑекÑÑÐµÐ¼Ñ ÑÐ°Ð¹Ð»Ñ Ð¿ÐµÑедаÑÑÑÑ Ð² `$_`, а подпÑогÑамма должна веÑнÑÑÑ Ð¸ÑÑÐ¸Ð½Ñ Ð¸Ð»Ð¸ ложÑ, как они понимаÑÑÑÑ perl-ом.
* Regexp â ÑеÑÑиÑÑÐµÑ ÐºÐ°Ð¶Ð´Ñй пÑÑÑ ÑегÑлÑÑнÑм вÑÑажением.
* СÑÑока в виде "-Xxx", где `Xxx` â один или неÑколÑко Ñимволов. ÐналогиÑна опеÑаÑоÑам perl-а Ð´Ð»Ñ ÑеÑÑиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Ñайлов. ÐÑимеÑ: `-fr` пÑовеÑÑÐµÑ Ð¿ÑÑÑ Ñ...
* ÐÑÑалÑнÑе ÑÑÑоки пÑевÑаÑаÑÑÑÑ ÑÑнкÑией `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
* [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>`.
* [IO::All](https://metacpan.org/pod/IO::All) â `@paths = map { "$_" } grep { -f $_ && $_->size > 10*1024 } io(".")->all(0)`.
* [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->()`.
* [File::Find](https://metacpan.org/pod/File::Find) â `find( sub { push @paths, $File::Find::name if /\.png/ }, $dir )`.
* [File::Find::utf8](https://metacpan.org/pod/File::Find::utf8) â как [File::Find](https://metacpan.org/pod/File::Find), ÑолÑко пÑÑи Ñайлов в _utf8_.
( run in 0.630 second using v1.01-cache-2.11-cpan-f56aa216473 )