view release on metacpan or search on metacpan
[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, $_;
# 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
* [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
$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_.
* [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`.
* [File::Find::Iterator](https://metacpan.org/pod/File::Find::Iterator) â Ð¸Ð¼ÐµÐµÑ ÐÐРинÑеÑÑÐµÐ¹Ñ Ñ Ð¸ÑеÑаÑоÑом и ÑÑнкÑии `imap` и `igrep`.
* [File::Find::Match](https://metacpan.org/pod/File::Find::Match) â вÑзÑÐ²Ð°ÐµÑ Ð¾Ð±ÑабоÑÑик на каждÑй подоÑедÑий ÑилÑÑÑ. ÐоÑ
ож на `switch`.
* [File::Find::Node](https://metacpan.org/pod/File::Find::Node) â обÑ
Ð¾Ð´Ð¸Ñ Ð¸ÐµÑаÑÑ
Ð¸Ñ Ñайлов паÑаллелÑно неÑколÑкими пÑоÑеÑÑами: `tie @paths, IPC::Shareable, { key => "GLUE STRING", create => 1 }; F...
* [File::Find::Fast](https://metacpan.org/pod/File::Find::Fast) â `@paths = @{ find($dir) }`.
* [File::Find::Object](https://metacpan.org/pod/File::Find::Object) â Ð¸Ð¼ÐµÐµÑ ÐÐРинÑеÑÑÐµÐ¹Ñ Ñ Ð¸ÑеÑаÑоÑом.
* [File::Find::Parallel](https://metacpan.org/pod/File::Find::Parallel) â ÑÐ¼ÐµÐµÑ ÑÑавниваÑÑ Ð´Ð²Ð° каÑалога и возвÑаÑаÑÑ Ð¸Ñ
обÑединение, пеÑеÑеÑение и колиÑеÑÑвенное пеÑеÑ...
* [File::Find::Random](https://metacpan.org/pod/File::Find::Random) â вÑбиÑÐ°ÐµÑ Ñайл или диÑекÑоÑÐ¸Ñ Ð½Ð°Ñгад из иеÑаÑÑ
ии Ñайлов.
* [File::Find::Rex](https://metacpan.org/pod/File::Find::Rex) â `@paths = File::Find::Rex->new(recursive => 1, ignore_hidden => 1)->query($dir, qr/^b/i)`.
* `unlink` + `rmdir`.
* [File::Path](https://metacpan.org/pod/File::Path) â `remove_tree("dir")`.
* [File::Path::Tiny](https://metacpan.org/pod/File::Path::Tiny) â `File::Path::Tiny::rm($path)`. Ðе вÑбÑаÑÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑений.
* [Mojo::File](https://metacpan.org/pod/Mojo::File) â `path($file)->remove`.
## replace (&sub, @files)
ÐаменÑÐµÑ ÐºÐ°Ð¶Ð´Ñй Ñайл на `$_`, еÑли его изменÑÐµÑ `&sub`. ÐозвÑаÑÐ°ÐµÑ ÑайлÑ, в коÑоÑÑÑ
не бÑло замен.
`@files` Ð¼Ð¾Ð¶ÐµÑ ÑодеÑжаÑÑ Ð¼Ð°ÑÑÐ¸Ð²Ñ Ð¸Ð· двÑÑ
ÑлеменÑов. ÐеÑвÑй ÑаÑÑмаÑÑиваеÑÑÑ ÐºÐ°Ðº пÑÑÑ, а вÑоÑой â как Ñлой. Слой по ÑмолÑÐ°Ð½Ð¸Ñ â `:utf8`.
`&sub` вÑзÑваеÑÑÑ Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð³Ð¾ Ñайла из `@files`. Ð Ð½ÐµÑ Ð¿ÐµÑедаÑÑÑÑ:
* `$_` â ÑодеÑжимое Ñайла.
* `$a` â пÑÑÑ Ðº ÑайлÑ.
* `$b` â Ñлой коÑоÑÑм бÑл ÑÑиÑан Ñайл и коÑоÑÑм он бÑÐ´ÐµÑ Ð·Ð°Ð¿Ð¸Ñан.
РпÑимеÑе ниже Ñайл "replace.ex" ÑÑиÑÑваеÑÑÑ Ñлоем `:utf8`, а запиÑÑваеÑÑÑ Ñлоем `:raw` в ÑÑнкÑии `replace`:
```perl
local $_ = "replace.ex";
lay "abc";
replace { $b = ":utf8"; y/a/¡/ } [$_, ":raw"];
cat # => ¡bc
```
### See also
* [File::Edit](https://metacpan.org/pod/File::Edit) â `File::Edit->new($file)->replace('x', 'y')->save`.
* [File::Edit::Portable](https://metacpan.org/pod/File::Edit::Portable) â `File::Edit::Portable->new->splice(file => $file, line => 10, contens => ["line1", "line2"])`.
* [File::Replace](https://metacpan.org/pod/File::Replace) â `($infh,$outfh,$repl) = replace3($file); while (<$infh>) { print $outfh "X: $_" } $repl->finish`.
* [File::Replace::Inplace](https://metacpan.org/pod/File::Replace::Inplace).
## mkpath (;$path)
Ðак **mkdir -p**, но ÑÑиÑÐ°ÐµÑ Ð¿Ð¾ÑледнÑÑ ÑаÑÑÑ Ð¿ÑÑи (поÑле поÑледней коÑой ÑеÑÑÑ) именем Ñайла и не ÑоздаÑÑ ÐµÑ ÐºÐ°Ñалогом. Ðез паÑамеÑÑа иÑполÑзÑе...
* ÐÑли `$path` не Ñказан, иÑполÑзÑÐµÑ `$_`.
* ÐÑли `$path` ÑвлÑеÑÑÑ ÑÑÑлкой на маÑÑив, Ñогда иÑполÑзÑеÑÑÑ Ð¿ÑÑÑ Ð² каÑеÑÑве пеÑвого ÑлеменÑа и пÑава в каÑеÑÑве вÑоÑого ÑлеменÑа.
* ÐÑава по ÑмолÑÐ°Ð½Ð¸Ñ â `0755`.
* ÐозвÑаÑÐ°ÐµÑ `$path`.
use lib "lib";
include("A")->new # ~> A=HASH\(0x\w+\)
[map include, qw/A N/] # --> [qw/A N/]
{ local $_="N"; include->ex } # -> 123
```
## catonce (;$file)
СÑиÑÑÐ²Ð°ÐµÑ Ñайл в пеÑвÑй Ñаз. ÐÑÐ±Ð°Ñ Ð¿Ð¾ÑледÑÑÑÐ°Ñ Ð¿Ð¾Ð¿ÑÑка ÑÑиÑаÑÑ ÑÑÐ¾Ñ Ñайл возвÑаÑÐ°ÐµÑ `undef`. ÐÑполÑзÑеÑÑÑ Ð´Ð»Ñ Ð²ÑÑавки модÑлей js и css в ÑезÑлÑ...
* `$file` Ð¼Ð¾Ð¶ÐµÑ ÑодеÑжаÑÑ Ð¼Ð°ÑÑÐ¸Ð²Ñ Ð¸Ð· двÑÑ
ÑлеменÑов. ÐеÑвÑй ÑаÑÑмаÑÑиваеÑÑÑ ÐºÐ°Ðº пÑÑÑ, а вÑоÑой â как Ñлой. Слой по ÑмолÑÐ°Ð½Ð¸Ñ â `:utf8`.
* ÐÑли `$file` не Ñказан â иÑполÑзÑÐµÑ `$_`.
```perl
local $_ = "catonce.txt";
lay "result";
catonce # -> "result"
catonce # -> undef
eval { catonce[] }; $@ # ~> catonce not use ref path!
```
i18n/Aion/Fs.ru-en.po view on Meta::CPAN
msgstr "The `IO::All` supermodule is not a competitor to `Aion::Fs`, because uses an OOP approach, and `Aion::Fs` is FP."
msgid "* ÐÐÐ â обÑекÑно-оÑиенÑиÑованное пÑогÑаммиÑование.\n"
"* ФРâ ÑÑнкÑионалÑное пÑогÑаммиÑование."
msgstr "* OOP â object-oriented programming.\n"
"* FP â functional programming."
msgid "СÑиÑÑÐ²Ð°ÐµÑ Ñайл. ÐÑли паÑамеÑÑ Ð½Ðµ Ñказан, иÑполÑзÑÐµÑ `$_`."
msgstr "Reads the file. If no parameter is specified, use `$_`."
msgid "`cat` ÑиÑÐ°ÐµÑ Ñо Ñлоем `:utf8`. Ðо можно ÑказаÑÑ Ð´ÑÑгой Ñлой ÑледÑÑÑим обÑазом:"
msgstr "`cat` reads with layer `:utf8`. But you can specify another layer like this:"
msgid "`cat` вÑзÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑение в ÑлÑÑае оÑибки опеÑаÑии ввода-вÑвода:"
msgstr "`cat` throws an exception if the I/O operation fails:"
msgid ""
"* [autodie](https://metacpan.org/pod/autodie) â `open $f, \"r.txt\"; $s = join \"\", <$f>; close $f`.\n"
"* [File::Slurp](https://metacpan.org/pod/File::Slurp) â `read_file('file.txt')`.\n"
"* [File::Slurper](https://metacpan.org/pod/File::Slurper) â `read_text('file.txt')`, `read_binary('file.txt')`.\n"
"* [File::Util](https://metacpan.org/pod/File::Util) â `File::Util->new->load_file(file => 'file.txt')`.\n"
"* [IO::All](https://metacpan.org/pod/IO::All) â `io('file.txt') > $contents`.\n"
i18n/Aion/Fs.ru-en.po view on Meta::CPAN
"* [File::Slurper](https://metacpan.org/pod/File::Slurper) â `read_text('file.txt')`, `read_binary('file.txt')`.\n"
"* [File::Util](https://metacpan.org/pod/File::Util) â `File::Util->new->load_file(file => 'file.txt')`.\n"
"* [IO::All](https://metacpan.org/pod/IO::All) â `io('file.txt') > $contents`.\n"
"* [IO::Util](https://metacpan.org/pod/IO::Util) - `$contents = ${ slurp 'file.txt' }`.\n"
"* [Mojo::File](https://metacpan.org/pod/Mojo::File) â `path($file)->slurp`."
msgid "ÐапиÑÑÐ²Ð°ÐµÑ `$content` в `$file`."
msgstr "Writes `$content` to `$file`."
msgid "* ÐÑли Ñказан один паÑамеÑÑ, иÑполÑзÑÐµÑ `$_` вмеÑÑо `$file`.\n"
"* `lay`, иÑполÑзÑÐµÑ Ñлой `:utf8`. ÐÐ»Ñ ÑÐºÐ°Ð·Ð°Ð½Ð¸Ñ Ð¸Ð½Ð¾Ð³Ð¾ ÑÐ»Ð¾Ñ Ð¸ÑполÑзÑеÑÑÑ Ð¼Ð°ÑÑив из двÑÑ
ÑлеменÑов в паÑамеÑÑе `$file`:"
msgstr "* If one parameter is specified, use `$_` instead of `$file`.\n"
"* `lay`, uses the `:utf8` layer. To specify a different layer, use an array of two elements in the `$file` parameter:"
msgid ""
"* [autodie](https://metacpan.org/pod/autodie) â `open $f, \">r.txt\"; print $f $contents; close $f`.\n"
"* [File::Slurp](https://metacpan.org/pod/File::Slurp) â `write_file('file.txt', $contents)`.\n"
"* [File::Slurper](https://metacpan.org/pod/File::Slurper) â `write_text('file.txt', $contents)`, `write_binary('file.txt', $contents)`.\n"
"* [IO::All](https://metacpan.org/pod/IO::All) â `io('file.txt') < $contents`.\n"
"* [IO::Util](https://metacpan.org/pod/IO::Util) â `slurp \\$contents, 'file.txt'`.\n"
"* [File::Util](https://metacpan.org/pod/File::Util) â `File::Util->new->write_file(file => 'file.txt', content => $contents, bitmask => 0644)`.\n"
"* [Mojo::File](https://metacpan.org/pod/Mojo::File) â `path($file)->spew($chars, 'UTF-8')`."
msgstr ""
i18n/Aion/Fs.ru-en.po view on Meta::CPAN
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"
"* [File::Find::Iterator](https://metacpan.org/pod/File::Find::Iterator) â Ð¸Ð¼ÐµÐµÑ ÐÐРинÑеÑÑÐµÐ¹Ñ Ñ Ð¸ÑеÑаÑоÑом и ÑÑнкÑии `imap` и `igrep`.\n"
"* [File::Find::Match](https://metacpan.org/pod/File::Find::Match) â вÑзÑÐ²Ð°ÐµÑ Ð¾Ð±ÑабоÑÑик на каждÑй подоÑедÑий ÑилÑÑÑ. ÐоÑ
ож на `switch`.\n"
"* [File::Find::Node](https://metacpan.org/pod/File::Find::Node) â обÑ
Ð¾Ð´Ð¸Ñ Ð¸ÐµÑаÑÑ
Ð¸Ñ Ñайлов паÑаллелÑно неÑколÑкими пÑоÑеÑÑами: `tie @paths, IPC::Shareable, { key => \"GLUE STRING\", create => 1 }...
"* [File::Find::Fast](https://metacpan.org/pod/File::Find::Fast) â `@paths = @{ find($dir) }`.\n"
"* [File::Find::Object](https://metacpan.org/pod/File::Find::Object) â Ð¸Ð¼ÐµÐµÑ ÐÐРинÑеÑÑÐµÐ¹Ñ Ñ Ð¸ÑеÑаÑоÑом.\n"
"* [File::Find::Parallel](https://metacpan.org/pod/File::Find::Parallel) â ÑÐ¼ÐµÐµÑ ÑÑавниваÑÑ Ð´Ð²Ð° каÑалога и возвÑаÑаÑÑ Ð¸Ñ
обÑединение, пеÑеÑеÑение и колиÑеÑÑвенное пеÑеÑ...
"* [File::Find::Random](https://metacpan.org/pod/File::Find::Random) â вÑбиÑÐ°ÐµÑ Ñайл или диÑекÑоÑÐ¸Ñ Ð½Ð°Ñгад из иеÑаÑÑ
ии Ñайлов.\n"
"* [File::Find::Rex](https://metacpan.org/pod/File::Find::Rex) â `@paths = File::Find::Rex->new(recursive => 1, ignore_hidden => 1)->query($dir, qr/^b/i)`.\n"
i18n/Aion/Fs.ru-en.po view on Meta::CPAN
"* [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)`."
msgstr ""
"* [AudioFile::Find](https://metacpan.org/pod/AudioFile::Find) â searches for audio files in the specified directory. Allows you to filter them by attributes: title, artist, genre, album and track.\n"
"* [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) â like [File::Find](https://metacpan.org/pod/File::Find), only file paths are in _utf8_.\n"
"* [File::Find::Age](https://metacpan.org/pod/File::Find::Age) â sorts files by modification time (inherits [File::Find::Rule](https://metacpan.org/pod/File::Find::Rule)): `File::Find::Age->in($dir1, $dir2)`.\n"
"* [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"
"* [File::Find::Iterator](https://metacpan.org/pod/File::Find::Iterator) â has an OOP interface with an iterator and the `imap` and `igrep` functions.\n"
"* [File::Find::Match](https://metacpan.org/pod/File::Find::Match) â calls a handler for each matching filter. Similar to `switch`.\n"
"* [File::Find::Node](https://metacpan.org/pod/File::Find::Node) â traverses the file hierarchy in parallel by several processes: `tie @paths, IPC::Shareable, { key => \"GLUE STRING\", create => 1 }; File::Find::Node->new(\".\")->process(sub { my $...
"* [File::Find::Fast](https://metacpan.org/pod/File::Find::Fast) â `@paths = @{ find($dir) }`.\n"
"* [File::Find::Object](https://metacpan.org/pod/File::Find::Object) â has an OOP interface with an iterator.\n"
"* [File::Find::Parallel](https://metacpan.org/pod/File::Find::Parallel) â can compare two directories and return their union, intersection and quantitative intersection.\n"
"* [File::Find::Random](https://metacpan.org/pod/File::Find::Random) â selects a file or directory at random from the file hierarchy.\n"
"* [File::Find::Rex](https://metacpan.org/pod/File::Find::Rex) â `@paths = File::Find::Rex->new(recursive => 1, ignore_hidden => 1)->query($dir, qr/^b/i)`.\n"
i18n/Aion/Fs.ru-en.po view on Meta::CPAN
"* [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"
"* [Mojo::File](https://metacpan.org/pod/Mojo::File) â `path($file)->remove`."
msgid "ÐаменÑÐµÑ ÐºÐ°Ð¶Ð´Ñй Ñайл на `$_`, еÑли его изменÑÐµÑ `&sub`. ÐозвÑаÑÐ°ÐµÑ ÑайлÑ, в коÑоÑÑÑ
не бÑло замен."
msgstr "Replaces each file with `$_` if it is modified by `&sub`. Returns files that have no replacements."
msgid "`@files` Ð¼Ð¾Ð¶ÐµÑ ÑодеÑжаÑÑ Ð¼Ð°ÑÑÐ¸Ð²Ñ Ð¸Ð· двÑÑ
ÑлеменÑов. ÐеÑвÑй ÑаÑÑмаÑÑиваеÑÑÑ ÐºÐ°Ðº пÑÑÑ, а вÑоÑой â как Ñлой. Слой по ÑмолÑÐ°Ð½Ð¸Ñ â `:utf8`."
msgstr "`@files` can contain arrays of two elements. The first is considered as a path, and the second as a layer. The default layer is `:utf8`."
msgid "`&sub` вÑзÑваеÑÑÑ Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð³Ð¾ Ñайла из `@files`. Ð Ð½ÐµÑ Ð¿ÐµÑедаÑÑÑÑ:"
msgstr "`&sub` is called for each file in `@files`. It transmits:"
msgid ""
"* `$_` â ÑодеÑжимое Ñайла.\n"
"* `$a` â пÑÑÑ Ðº ÑайлÑ.\n"
"* `$b` â Ñлой коÑоÑÑм бÑл ÑÑиÑан Ñайл и коÑоÑÑм он бÑÐ´ÐµÑ Ð·Ð°Ð¿Ð¸Ñан."
msgstr ""
"* `$_` â file contents.\n"
"* `$a` â path to the file.\n"
"* `$b` â the layer with which the file was read and with which it will be written."
msgid "РпÑимеÑе ниже Ñайл \"replace.ex\" ÑÑиÑÑваеÑÑÑ Ñлоем `:utf8`, а запиÑÑваеÑÑÑ Ñлоем `:raw` в ÑÑнкÑии `replace`:"
msgstr "In the example below, the file \"replace.ex\" is read by the `:utf8` layer and written by the `:raw` layer in the `replace` function:"
msgid ""
"* [File::Edit](https://metacpan.org/pod/File::Edit) â `File::Edit->new($file)->replace('x', 'y')->save`.\n"
"* [File::Edit::Portable](https://metacpan.org/pod/File::Edit::Portable) â `File::Edit::Portable->new->splice(file => $file, line => 10, contens => [\"line1\", \"line2\"])`.\n"
"* [File::Replace](https://metacpan.org/pod/File::Replace) â `($infh,$outfh,$repl) = replace3($file); while (<$infh>) { print $outfh \"X: $_\" } $repl->finish`.\n"
"* [File::Replace::Inplace](https://metacpan.org/pod/File::Replace::Inplace)."
msgstr ""
"* [File::Edit](https://metacpan.org/pod/File::Edit) â `File::Edit->new($file)->replace('x', 'y')->save`.\n"
"* [File::Edit::Portable](https://metacpan.org/pod/File::Edit::Portable) â `File::Edit::Portable->new->splice(file => $file, line => 10, contens => [\"line1\", \"line2\"])`.\n"
"* [File::Replace](https://metacpan.org/pod/File::Replace) â `($infh,$outfh,$repl) = replace3($file); while (<$infh>) { print $outfh \"X: $_\" } $repl->finish`.\n"
"* [File::Replace::Inplace](https://metacpan.org/pod/File::Replace::Inplace)."
msgid "Ðак **mkdir -p**, но ÑÑиÑÐ°ÐµÑ Ð¿Ð¾ÑледнÑÑ ÑаÑÑÑ Ð¿ÑÑи (поÑле поÑледней коÑой ÑеÑÑÑ) именем Ñайла и не ÑоздаÑÑ ÐµÑ ÐºÐ°Ñалогом. Ðез паÑамеÑÑа иÑполÑ...
msgstr "Like **mkdir -p**, but considers the last part of the path (after the last slash) to be a filename and does not create it as a directory. Without a parameter, uses `$_`."
msgid ""
"* ÐÑли `$path` не Ñказан, иÑполÑзÑÐµÑ `$_`.\n"
"* ÐÑли `$path` ÑвлÑеÑÑÑ ÑÑÑлкой на маÑÑив, Ñогда иÑполÑзÑеÑÑÑ Ð¿ÑÑÑ Ð² каÑеÑÑве пеÑвого ÑлеменÑа и пÑава в каÑеÑÑве вÑоÑого ÑлеменÑа.\n"
"* ÐÑава по ÑмолÑÐ°Ð½Ð¸Ñ â `0755`.\n"
"* ÐозвÑаÑÐ°ÐµÑ `$path`."
i18n/Aion/Fs.ru-en.po view on Meta::CPAN
msgid "Файл lib/A.pm:"
msgstr "lib/A.pm file:"
msgid "Файл lib/N.pm:"
msgstr "lib/N.pm file:"
msgid "СÑиÑÑÐ²Ð°ÐµÑ Ñайл в пеÑвÑй Ñаз. ÐÑÐ±Ð°Ñ Ð¿Ð¾ÑледÑÑÑÐ°Ñ Ð¿Ð¾Ð¿ÑÑка ÑÑиÑаÑÑ ÑÑÐ¾Ñ Ñайл возвÑаÑÐ°ÐµÑ `undef`. ÐÑполÑзÑеÑÑÑ Ð´Ð»Ñ Ð²ÑÑавки модÑлей js и css в Ñе...
msgstr "Reads the file for the first time. Any subsequent attempt to read this file returns `undef`. Used to insert js and css modules into the resulting file. Without a parameter, uses `$_`."
msgid "* `$file` Ð¼Ð¾Ð¶ÐµÑ ÑодеÑжаÑÑ Ð¼Ð°ÑÑÐ¸Ð²Ñ Ð¸Ð· двÑÑ
ÑлеменÑов. ÐеÑвÑй ÑаÑÑмаÑÑиваеÑÑÑ ÐºÐ°Ðº пÑÑÑ, а вÑоÑой â как Ñлой. Слой по ÑмолÑÐ°Ð½Ð¸Ñ â `:utf8`.\n"
"* ÐÑли `$file` не Ñказан â иÑполÑзÑÐµÑ `$_`."
msgstr "* `$file` can contain arrays of two elements. The first is considered as a path, and the second as a layer. The default layer is `:utf8`.\n"
"* If `$file` is not specified, use `$_`."
msgid "ÐеÑÐµÐ²Ð¾Ð´Ð¸Ñ ÑайловÑÑ Ð¼Ð°ÑÐºÑ Ð² ÑегÑлÑÑное вÑÑажение. Ðез паÑамеÑÑа иÑполÑзÑÐµÑ `$_`."
msgstr "Converts a file mask to a regular expression. Without a parameter, uses `$_`."
msgid ""
"* `**` - `[^/]*`\n"
"* `*` - `.*`\n"
"* `?` - `.`\n"
"* `??` - `[^/]`\n"
lib/Aion/Fs.md view on Meta::CPAN
[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, $_;
lib/Aion/Fs.md view on Meta::CPAN
# 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
lib/Aion/Fs.md view on Meta::CPAN
* [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
lib/Aion/Fs.md view on Meta::CPAN
$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_.
* [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`.
* [File::Find::Iterator](https://metacpan.org/pod/File::Find::Iterator) â Ð¸Ð¼ÐµÐµÑ ÐÐРинÑеÑÑÐµÐ¹Ñ Ñ Ð¸ÑеÑаÑоÑом и ÑÑнкÑии `imap` и `igrep`.
* [File::Find::Match](https://metacpan.org/pod/File::Find::Match) â вÑзÑÐ²Ð°ÐµÑ Ð¾Ð±ÑабоÑÑик на каждÑй подоÑедÑий ÑилÑÑÑ. ÐоÑ
ож на `switch`.
* [File::Find::Node](https://metacpan.org/pod/File::Find::Node) â обÑ
Ð¾Ð´Ð¸Ñ Ð¸ÐµÑаÑÑ
Ð¸Ñ Ñайлов паÑаллелÑно неÑколÑкими пÑоÑеÑÑами: `tie @paths, IPC::Shareable, { key => "GLUE STRING", create => 1 }; F...
* [File::Find::Fast](https://metacpan.org/pod/File::Find::Fast) â `@paths = @{ find($dir) }`.
* [File::Find::Object](https://metacpan.org/pod/File::Find::Object) â Ð¸Ð¼ÐµÐµÑ ÐÐРинÑеÑÑÐµÐ¹Ñ Ñ Ð¸ÑеÑаÑоÑом.
* [File::Find::Parallel](https://metacpan.org/pod/File::Find::Parallel) â ÑÐ¼ÐµÐµÑ ÑÑавниваÑÑ Ð´Ð²Ð° каÑалога и возвÑаÑаÑÑ Ð¸Ñ
обÑединение, пеÑеÑеÑение и колиÑеÑÑвенное пеÑеÑ...
* [File::Find::Random](https://metacpan.org/pod/File::Find::Random) â вÑбиÑÐ°ÐµÑ Ñайл или диÑекÑоÑÐ¸Ñ Ð½Ð°Ñгад из иеÑаÑÑ
ии Ñайлов.
* [File::Find::Rex](https://metacpan.org/pod/File::Find::Rex) â `@paths = File::Find::Rex->new(recursive => 1, ignore_hidden => 1)->query($dir, qr/^b/i)`.
lib/Aion/Fs.md view on Meta::CPAN
* `unlink` + `rmdir`.
* [File::Path](https://metacpan.org/pod/File::Path) â `remove_tree("dir")`.
* [File::Path::Tiny](https://metacpan.org/pod/File::Path::Tiny) â `File::Path::Tiny::rm($path)`. Ðе вÑбÑаÑÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑений.
* [Mojo::File](https://metacpan.org/pod/Mojo::File) â `path($file)->remove`.
## replace (&sub, @files)
ÐаменÑÐµÑ ÐºÐ°Ð¶Ð´Ñй Ñайл на `$_`, еÑли его изменÑÐµÑ `&sub`. ÐозвÑаÑÐ°ÐµÑ ÑайлÑ, в коÑоÑÑÑ
не бÑло замен.
`@files` Ð¼Ð¾Ð¶ÐµÑ ÑодеÑжаÑÑ Ð¼Ð°ÑÑÐ¸Ð²Ñ Ð¸Ð· двÑÑ
ÑлеменÑов. ÐеÑвÑй ÑаÑÑмаÑÑиваеÑÑÑ ÐºÐ°Ðº пÑÑÑ, а вÑоÑой â как Ñлой. Слой по ÑмолÑÐ°Ð½Ð¸Ñ â `:utf8`.
`&sub` вÑзÑваеÑÑÑ Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð³Ð¾ Ñайла из `@files`. Ð Ð½ÐµÑ Ð¿ÐµÑедаÑÑÑÑ:
* `$_` â ÑодеÑжимое Ñайла.
* `$a` â пÑÑÑ Ðº ÑайлÑ.
* `$b` â Ñлой коÑоÑÑм бÑл ÑÑиÑан Ñайл и коÑоÑÑм он бÑÐ´ÐµÑ Ð·Ð°Ð¿Ð¸Ñан.
РпÑимеÑе ниже Ñайл "replace.ex" ÑÑиÑÑваеÑÑÑ Ñлоем `:utf8`, а запиÑÑваеÑÑÑ Ñлоем `:raw` в ÑÑнкÑии `replace`:
```perl
local $_ = "replace.ex";
lay "abc";
replace { $b = ":utf8"; y/a/¡/ } [$_, ":raw"];
cat # => ¡bc
```
### See also
* [File::Edit](https://metacpan.org/pod/File::Edit) â `File::Edit->new($file)->replace('x', 'y')->save`.
* [File::Edit::Portable](https://metacpan.org/pod/File::Edit::Portable) â `File::Edit::Portable->new->splice(file => $file, line => 10, contens => ["line1", "line2"])`.
* [File::Replace](https://metacpan.org/pod/File::Replace) â `($infh,$outfh,$repl) = replace3($file); while (<$infh>) { print $outfh "X: $_" } $repl->finish`.
* [File::Replace::Inplace](https://metacpan.org/pod/File::Replace::Inplace).
## mkpath (;$path)
Ðак **mkdir -p**, но ÑÑиÑÐ°ÐµÑ Ð¿Ð¾ÑледнÑÑ ÑаÑÑÑ Ð¿ÑÑи (поÑле поÑледней коÑой ÑеÑÑÑ) именем Ñайла и не ÑоздаÑÑ ÐµÑ ÐºÐ°Ñалогом. Ðез паÑамеÑÑа иÑполÑзÑе...
* ÐÑли `$path` не Ñказан, иÑполÑзÑÐµÑ `$_`.
* ÐÑли `$path` ÑвлÑеÑÑÑ ÑÑÑлкой на маÑÑив, Ñогда иÑполÑзÑеÑÑÑ Ð¿ÑÑÑ Ð² каÑеÑÑве пеÑвого ÑлеменÑа и пÑава в каÑеÑÑве вÑоÑого ÑлеменÑа.
* ÐÑава по ÑмолÑÐ°Ð½Ð¸Ñ â `0755`.
* ÐозвÑаÑÐ°ÐµÑ `$path`.
lib/Aion/Fs.md view on Meta::CPAN
use lib "lib";
include("A")->new # ~> A=HASH\(0x\w+\)
[map include, qw/A N/] # --> [qw/A N/]
{ local $_="N"; include->ex } # -> 123
```
## catonce (;$file)
СÑиÑÑÐ²Ð°ÐµÑ Ñайл в пеÑвÑй Ñаз. ÐÑÐ±Ð°Ñ Ð¿Ð¾ÑледÑÑÑÐ°Ñ Ð¿Ð¾Ð¿ÑÑка ÑÑиÑаÑÑ ÑÑÐ¾Ñ Ñайл возвÑаÑÐ°ÐµÑ `undef`. ÐÑполÑзÑеÑÑÑ Ð´Ð»Ñ Ð²ÑÑавки модÑлей js и css в ÑезÑлÑ...
* `$file` Ð¼Ð¾Ð¶ÐµÑ ÑодеÑжаÑÑ Ð¼Ð°ÑÑÐ¸Ð²Ñ Ð¸Ð· двÑÑ
ÑлеменÑов. ÐеÑвÑй ÑаÑÑмаÑÑиваеÑÑÑ ÐºÐ°Ðº пÑÑÑ, а вÑоÑой â как Ñлой. Слой по ÑмолÑÐ°Ð½Ð¸Ñ â `:utf8`.
* ÐÑли `$file` не Ñказан â иÑполÑзÑÐµÑ `$_`.
```perl
local $_ = "catonce.txt";
lay "result";
catonce # -> "result"
catonce # -> undef
eval { catonce[] }; $@ # ~> catonce not use ref path!
```
lib/Aion/Fs.pm view on Meta::CPAN
mkdir $cat, $permission or ($! != FILE_EXISTS? die "mkpath $cat: $!": ());
}
}
$path
}
# СÑиÑаÑÑ Ñайл
sub cat(;$) {
my ($file) = @_ == 0? $_: @_;
my $layer = ":utf8";
($file, $layer) = @$file if ref $file;
open my $f, "<$layer", $file or die "cat $file: $!";
read $f, my $x, -s $f;
close $f;
$x
}
# ÐапиÑаÑÑ Ñайл
sub lay ($;$) {
my ($file, $s) = @_ == 1? ($_, @_): @_;
my $layer = ":utf8";
($file, $layer) = @$file if ref $file;
open my $f, ">$layer", $file or die "lay $file: $!";
local $\;
print $f $s;
close $f;
$file
}
# СÑиÑаÑÑ Ñайл, еÑли он еÑÑ Ð½Ðµ бÑл ÑÑиÑан
our %FILE_INC;
lib/Aion/Fs.pm view on Meta::CPAN
sub find_stop() {
die bless {}, "Aion::Fs::stop"
}
# ÐÑÐ¾Ð¸Ð·Ð²Ð¾Ð´Ð¸Ñ Ð·Ð°Ð¼ÐµÐ½Ñ Ð²Ð¾ вÑеÑ
ÑказаннÑÑ
ÑайлаÑ
. ÐозвÑаÑÐ°ÐµÑ ÑÐ°Ð¹Ð»Ñ Ð² коÑоÑÑÑ
замен не бÑло
sub replace(&@) {
my $fn = shift;
my @noreplace; local $_; my $pkg = caller;
my $aref = "${pkg}::a"; my $bref = "${pkg}::b";
for $$aref (@_) {
if(ref $$aref) { ($$aref, $$bref) = @$$aref } else { $$bref = ":utf8" }
my $file = $_ = cat [$$aref, $$bref];
$fn->();
if($file ne $_) { lay [$$aref, $$bref], $_ } else { push @noreplace, $$aref if defined wantarray }
}
@noreplace
}
# СÑиÑÐ°ÐµÑ Ð²Ñе ÑказаннÑе ÑайлÑ. ÐозвÑаÑÐ°ÐµÑ Ð¿ÐµÑеданнÑе ÑайлÑ
sub erase(@) {
-d? rmdir: unlink or die "erase ${\(-d? 'dir': 'file')} $_: $!" for @_;
lib/Aion/Fs.pm view on Meta::CPAN
my $path = from_pkg $pkg;
return $pkg if exists $INC{$path};
require $path;
$pkg
}
1;
__END__
=encoding utf-8
=head1 NAME
Aion::Fs - utilities for the file system: reading, writing, searching, replacing files, etc.
=head1 VERSION
0.2.2
=head1 SYNOPSIS
lib/Aion/Fs.pm view on Meta::CPAN
[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, $_;
lib/Aion/Fs.pm view on Meta::CPAN
=back
=head1 SUBROUTINES/METHODS
=head2 cat ($file)
Reads the file. If no parameter is specified, use C<$_>.
cat "/etc/passwd" # ~> root
C<cat> reads with layer C<:utf8>. But you can specify another layer like this:
lay "unicode.txt", "â¯";
length cat "unicode.txt" # -> 1
length cat["unicode.txt", ":raw"] # -> 3
C<cat> throws an exception if the I/O operation fails:
eval { cat "A" }; $@ # ~> cat A: No such file or directory
=head3 See also
lib/Aion/Fs.pm view on Meta::CPAN
=back
=head2 lay ($file?, $content)
Writes C<$content> to C<$file>.
=over
=item * If one parameter is specified, use C<$_> instead of C<$file>.
=item * C<lay>, uses the C<:utf8> layer. To specify a different layer, use an array of two elements in the C<$file> parameter:
=back
lay "unicode.txt", "â¯" # => unicode.txt
lay ["unicode.txt", ":raw"], "â¯" # => unicode.txt
eval { lay "/", "â¯" }; $@ # ~> lay /: Is a directory
=head3 See also
lib/Aion/Fs.pm view on Meta::CPAN
=item * L<AudioFile::Find> â searches for audio files in the specified directory. Allows you to filter them by attributes: title, artist, genre, album and track.
=item * L<Directory::Iterator> â C<< $it = Directory::Iterator-E<gt>new($dir, %opts); push @paths, $_ while E<lt>$itE<gt> >>.
=item * L<IO::All> â C<< @paths = map { "$_" } grep { -f $_ && $_-E<gt>size E<gt> 10*1024 } io(".")-E<gt>all(0) >>.
=item * L<IO::All::Rule> â C<< $next = IO::All::Rule-E<gt>new-E<gt>file-E<gt>size("E<gt>10k")-E<gt>iter($dir1, $dir2); push @paths, "$f" while $f = $next-E<gt>() >>.
=item * L<File::Find> â C<find( sub { push @paths, $File::Find::name if /\.png/ }, $dir )>.
=item * L<File::Find::utf8> â like L<File::Find>, only file paths are in I<utf8>.
=item * L<File::Find::Age> â sorts files by modification time (inherits L<File::Find::Rule>): C<< File::Find::Age-E<gt>in($dir1, $dir2) >>.
=item * L<File::Find::Declare> â C<< @paths = File::Find::Declare-E<gt>new({ size =E<gt> 'E<gt>10K', perms =E<gt> 'wr-wr-wr-', modified =E<gt> 'E<lt>2010-01-30', recurse =E<gt> 1, dirs =E<gt> [$dir1] })-E<gt>find >>.
=item * L<File::Find::Iterator> â has an OOP interface with an iterator and the C<imap> and C<igrep> functions.
=item * L<File::Find::Match> â calls a handler for each matching filter. Similar to C<switch>.
=item * L<File::Find::Node> â traverses the file hierarchy in parallel by several processes: C<< tie @paths, IPC::Shareable, { key =E<gt> "GLUE STRING", create =E<gt> 1 }; File::Find::Node-E<gt>new(".")-E<gt>process(sub { my $f = shift; $f-E<gt>for...
lib/Aion/Fs.pm view on Meta::CPAN
=item * L<File::Path::Tiny> â C<File::Path::Tiny::rm($path)>. Does not throw exceptions.
=item * L<Mojo::File> â C<< path($file)-E<gt>remove >>.
=back
=head2 replace (&sub, @files)
Replaces each file with C<$_> if it is modified by C<&sub>. Returns files that have no replacements.
C<@files> can contain arrays of two elements. The first is considered as a path, and the second as a layer. The default layer is C<:utf8>.
C<&sub> is called for each file in C<@files>. It transmits:
=over
=item * C<$_> â file contents.
=item * C<$a> â path to the file.
=item * C<$b> â the layer with which the file was read and with which it will be written.
=back
In the example below, the file "replace.ex" is read by the C<:utf8> layer and written by the C<:raw> layer in the C<replace> function:
local $_ = "replace.ex";
lay "abc";
replace { $b = ":utf8"; y/a/¡/ } [$_, ":raw"];
cat # => ¡bc
=head3 See also
=over
=item * L<File::Edit> â C<< File::Edit-E<gt>new($file)-E<gt>replace('x', 'y')-E<gt>save >>.
=item * L<File::Edit::Portable> â C<< File::Edit::Portable-E<gt>new-E<gt>splice(file =E<gt> $file, line =E<gt> 10, contens =E<gt> ["line1", "line2"]) >>.
=item * L<File::Replace> â C<< ($infh,$outfh,$repl) = replace3($file); while (E<lt>$infhE<gt>) { print $outfh "X: $_" } $repl-E<gt>finish >>.
=item * L<File::Replace::Inplace>.
=back
=head2 mkpath (;$path)
Like B<mkdir -p>, but considers the last part of the path (after the last slash) to be a filename and does not create it as a directory. Without a parameter, uses C<$_>.
=over
lib/Aion/Fs.pm view on Meta::CPAN
include("A")->new # ~> A=HASH\(0x\w+\)
[map include, qw/A N/] # --> [qw/A N/]
{ local $_="N"; include->ex } # -> 123
=head2 catonce (;$file)
Reads the file for the first time. Any subsequent attempt to read this file returns C<undef>. Used to insert js and css modules into the resulting file. Without a parameter, uses C<$_>.
=over
=item * C<$file> can contain arrays of two elements. The first is considered as a path, and the second as a layer. The default layer is C<:utf8>.
=item * If C<$file> is not specified, use C<$_>.
=back
local $_ = "catonce.txt";
lay "result";
catonce # -> "result"
catonce # -> undef
lib/Aion/Fs/Find.pm view on Meta::CPAN
die if ref $@ ne "Aion::Fs::stop";
}
$path
}
1;
__END__
=encoding utf-8
=head1 NAME
Aion::Fs::Find - file search iterator for Aion::Fs#find
=head1 SYNOPSIS
use Aion::Fs::Find;
my $iter = Aion::Fs::Find->new(
t/aion/fs.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Carp qw//; use Cwd qw//; use File::Basename qw//; use File::Find qw//; use File::Slurper qw//; use File::Spec qw//; use File::Path qw//; use Scalar::Util qw//; use Test::More 0.98; BEGIN { $SIG{__DI...
# # NAME
#
# Aion::Fs - ÑÑилиÑÑ Ð´Ð»Ñ Ñайловой ÑиÑÑемÑ: ÑÑение, запиÑÑ, поиÑк, замена Ñайлов и Ñ.д.
#
# # VERSION
#
# 0.2.1
#
# # SYNOPSIS
#
t/aion/fs.t view on Meta::CPAN
::is_deeply scalar do {[map cat, grep -f, find ["hello/big", "hello/small"]];}, scalar do {[qw/ hellow! noenter /]}, '[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 $_: $!" };
::is_deeply scalar do {\@noreplaced;}, scalar do {["hello/moon.txt"]}, '\@noreplaced; # --> ["hello/moon.txt"]';
::is scalar do {cat "hello/world.txt";}, "hello/world.txt :utf8 Hi!", 'cat "hello/world.txt"; # => hello/world.txt :utf8 Hi!';
::is scalar do {cat "hello/moon.txt";}, "noreplace", 'cat "hello/moon.txt"; # => noreplace';
::is scalar do {cat "hello/big/world.txt";}, "hello/big/world.txt :utf8 Hellow!", 'cat "hello/big/world.txt"; # => hello/big/world.txt :utf8 Hellow!';
::is scalar do {cat "hello/small/world.txt";}, "noenter", 'cat "hello/small/world.txt"; # => noenter';
::is_deeply scalar do {[find "hello", "*.txt"];}, scalar do {[qw! hello/moon.txt hello/world.txt hello/big/world.txt hello/small/world.txt !]}, '[find "hello", "*.txt"]; # --> [qw! hello/moon.txt hello/world.txt hello/big/world.txt hello/sma...
my @dirs;
my $iter = find "hello", "-d";
while(<$iter>) {
push @dirs, $_;
t/aion/fs.t view on Meta::CPAN
# # SUBROUTINES/METHODS
#
# ## cat ($file)
#
# СÑиÑÑÐ²Ð°ÐµÑ Ñайл. ÐÑли паÑамеÑÑ Ð½Ðµ Ñказан, иÑполÑзÑÐµÑ `$_`.
#
::done_testing; }; subtest 'cat ($file)' => sub {
::like scalar do {cat "/etc/passwd"}, qr{root}, 'cat "/etc/passwd" # ~> root';
#
# `cat` ÑиÑÐ°ÐµÑ Ñо Ñлоем `:utf8`. Ðо можно ÑказаÑÑ Ð´ÑÑгой Ñлой ÑледÑÑÑим обÑазом:
#
lay "unicode.txt", "â¯";
::is scalar do {length cat "unicode.txt"}, scalar do{1}, 'length cat "unicode.txt" # -> 1';
::is scalar do {length cat["unicode.txt", ":raw"]}, scalar do{3}, 'length cat["unicode.txt", ":raw"] # -> 3';
#
# `cat` вÑзÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑение в ÑлÑÑае оÑибки опеÑаÑии ввода-вÑвода:
#
t/aion/fs.t view on Meta::CPAN
# * [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`:
#
::done_testing; }; subtest 'lay ($file?, $content)' => sub {
::is scalar do {lay "unicode.txt", "â¯"}, "unicode.txt", 'lay "unicode.txt", "â¯" # => unicode.txt';
::is scalar do {lay ["unicode.txt", ":raw"], "â¯"}, "unicode.txt", 'lay ["unicode.txt", ":raw"], "â¯" # => unicode.txt';
::like scalar do {eval { lay "/", "â¯" }; $@}, qr{lay /: Is a directory}, 'eval { lay "/", "â¯" }; $@ # ~> lay /: Is a directory';
#
# ### See also
#
t/aion/fs.t view on Meta::CPAN
::is scalar do {$count}, scalar do{3}, '$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_.
# * [File::Find::Age](https://metacpan.org/pod/File::Find::Age) â ÑоÑÑиÑÑÐµÑ ÑÐ°Ð¹Ð»Ñ Ð¿Ð¾ вÑемени модиÑикаÑии (наÑледÑÐµÑ [File::Find::Rule](https://metacpan.org/pod/File::Find::Rule)): `File::Find::Age->in($dir...
# * [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`.
# * [File::Find::Iterator](https://metacpan.org/pod/File::Find::Iterator) â Ð¸Ð¼ÐµÐµÑ ÐÐРинÑеÑÑÐµÐ¹Ñ Ñ Ð¸ÑеÑаÑоÑом и ÑÑнкÑии `imap` и `igrep`.
# * [File::Find::Match](https://metacpan.org/pod/File::Find::Match) â вÑзÑÐ²Ð°ÐµÑ Ð¾Ð±ÑабоÑÑик на каждÑй подоÑедÑий ÑилÑÑÑ. ÐоÑ
ож на `switch`.
# * [File::Find::Node](https://metacpan.org/pod/File::Find::Node) â обÑ
Ð¾Ð´Ð¸Ñ Ð¸ÐµÑаÑÑ
Ð¸Ñ Ñайлов паÑаллелÑно неÑколÑкими пÑоÑеÑÑами: `tie @paths, IPC::Shareable, { key => "GLUE STRING", create => 1 };...
# * [File::Find::Fast](https://metacpan.org/pod/File::Find::Fast) â `@paths = @{ find($dir) }`.
# * [File::Find::Object](https://metacpan.org/pod/File::Find::Object) â Ð¸Ð¼ÐµÐµÑ ÐÐРинÑеÑÑÐµÐ¹Ñ Ñ Ð¸ÑеÑаÑоÑом.
# * [File::Find::Parallel](https://metacpan.org/pod/File::Find::Parallel) â ÑÐ¼ÐµÐµÑ ÑÑавниваÑÑ Ð´Ð²Ð° каÑалога и возвÑаÑаÑÑ Ð¸Ñ
обÑединение, пеÑеÑеÑение и колиÑеÑÑвенное пеÑе...
# * [File::Find::Random](https://metacpan.org/pod/File::Find::Random) â вÑбиÑÐ°ÐµÑ Ñайл или диÑекÑоÑÐ¸Ñ Ð½Ð°Ñгад из иеÑаÑÑ
ии Ñайлов.
# * [File::Find::Rex](https://metacpan.org/pod/File::Find::Rex) â `@paths = File::Find::Rex->new(recursive => 1, ignore_hidden => 1)->query($dir, qr/^b/i)`.
t/aion/fs.t view on Meta::CPAN
#
# * `unlink` + `rmdir`.
# * [File::Path](https://metacpan.org/pod/File::Path) â `remove_tree("dir")`.
# * [File::Path::Tiny](https://metacpan.org/pod/File::Path::Tiny) â `File::Path::Tiny::rm($path)`. Ðе вÑбÑаÑÑÐ²Ð°ÐµÑ Ð¸ÑклÑÑений.
# * [Mojo::File](https://metacpan.org/pod/Mojo::File) â `path($file)->remove`.
#
# ## replace (&sub, @files)
#
# ÐаменÑÐµÑ ÐºÐ°Ð¶Ð´Ñй Ñайл на `$_`, еÑли его изменÑÐµÑ `&sub`. ÐозвÑаÑÐ°ÐµÑ ÑайлÑ, в коÑоÑÑÑ
не бÑло замен.
#
# `@files` Ð¼Ð¾Ð¶ÐµÑ ÑодеÑжаÑÑ Ð¼Ð°ÑÑÐ¸Ð²Ñ Ð¸Ð· двÑÑ
ÑлеменÑов. ÐеÑвÑй ÑаÑÑмаÑÑиваеÑÑÑ ÐºÐ°Ðº пÑÑÑ, а вÑоÑой â как Ñлой. Слой по ÑмолÑÐ°Ð½Ð¸Ñ â `:utf8`.
#
# `&sub` вÑзÑваеÑÑÑ Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð³Ð¾ Ñайла из `@files`. Ð Ð½ÐµÑ Ð¿ÐµÑедаÑÑÑÑ:
#
# * `$_` â ÑодеÑжимое Ñайла.
# * `$a` â пÑÑÑ Ðº ÑайлÑ.
# * `$b` â Ñлой коÑоÑÑм бÑл ÑÑиÑан Ñайл и коÑоÑÑм он бÑÐ´ÐµÑ Ð·Ð°Ð¿Ð¸Ñан.
#
# РпÑимеÑе ниже Ñайл "replace.ex" ÑÑиÑÑваеÑÑÑ Ñлоем `:utf8`, а запиÑÑваеÑÑÑ Ñлоем `:raw` в ÑÑнкÑии `replace`:
#
::done_testing; }; subtest 'replace (&sub, @files)' => sub {
local $_ = "replace.ex";
lay "abc";
replace { $b = ":utf8"; y/a/¡/ } [$_, ":raw"];
::is scalar do {cat}, "¡bc", 'cat # => ¡bc';
#
# ### See also
#
# * [File::Edit](https://metacpan.org/pod/File::Edit) â `File::Edit->new($file)->replace('x', 'y')->save`.
# * [File::Edit::Portable](https://metacpan.org/pod/File::Edit::Portable) â `File::Edit::Portable->new->splice(file => $file, line => 10, contens => ["line1", "line2"])`.
# * [File::Replace](https://metacpan.org/pod/File::Replace) â `($infh,$outfh,$repl) = replace3($file); while (<$infh>) { print $outfh "X: $_" } $repl->finish`.
# * [File::Replace::Inplace](https://metacpan.org/pod/File::Replace::Inplace).
#
# ## mkpath (;$path)
#
# Ðак **mkdir -p**, но ÑÑиÑÐ°ÐµÑ Ð¿Ð¾ÑледнÑÑ ÑаÑÑÑ Ð¿ÑÑи (поÑле поÑледней коÑой ÑеÑÑÑ) именем Ñайла и не ÑоздаÑÑ ÐµÑ ÐºÐ°Ñалогом. Ðез паÑамеÑÑа иÑполÑзÑ...
#
# * ÐÑли `$path` не Ñказан, иÑполÑзÑÐµÑ `$_`.
# * ÐÑли `$path` ÑвлÑеÑÑÑ ÑÑÑлкой на маÑÑив, Ñогда иÑполÑзÑеÑÑÑ Ð¿ÑÑÑ Ð² каÑеÑÑве пеÑвого ÑлеменÑа и пÑава в каÑеÑÑве вÑоÑого ÑлеменÑа.
# * ÐÑава по ÑмолÑÐ°Ð½Ð¸Ñ â `0755`.
# * ÐозвÑаÑÐ°ÐµÑ `$path`.
t/aion/fs.t view on Meta::CPAN
use lib "lib";
::like scalar do {include("A")->new}, qr{A=HASH\(0x\w+\)}, 'include("A")->new # ~> A=HASH\(0x\w+\)';
::is_deeply scalar do {[map include, qw/A N/]}, scalar do {[qw/A N/]}, '[map include, qw/A N/] # --> [qw/A N/]';
::is scalar do {{ local $_="N"; include->ex }}, scalar do{123}, '{ local $_="N"; include->ex } # -> 123';
#
# ## catonce (;$file)
#
# СÑиÑÑÐ²Ð°ÐµÑ Ñайл в пеÑвÑй Ñаз. ÐÑÐ±Ð°Ñ Ð¿Ð¾ÑледÑÑÑÐ°Ñ Ð¿Ð¾Ð¿ÑÑка ÑÑиÑаÑÑ ÑÑÐ¾Ñ Ñайл возвÑаÑÐ°ÐµÑ `undef`. ÐÑполÑзÑеÑÑÑ Ð´Ð»Ñ Ð²ÑÑавки модÑлей js и css в ÑезÑÐ...
#
# * `$file` Ð¼Ð¾Ð¶ÐµÑ ÑодеÑжаÑÑ Ð¼Ð°ÑÑÐ¸Ð²Ñ Ð¸Ð· двÑÑ
ÑлеменÑов. ÐеÑвÑй ÑаÑÑмаÑÑиваеÑÑÑ ÐºÐ°Ðº пÑÑÑ, а вÑоÑой â как Ñлой. Слой по ÑмолÑÐ°Ð½Ð¸Ñ â `:utf8`.
# * ÐÑли `$file` не Ñказан â иÑполÑзÑÐµÑ `$_`.
#
::done_testing; }; subtest 'catonce (;$file)' => sub {
local $_ = "catonce.txt";
lay "result";
::is scalar do {catonce}, scalar do{"result"}, 'catonce # -> "result"';
::is scalar do {catonce}, scalar do{undef}, 'catonce # -> undef';
::like scalar do {eval { catonce[] }; $@}, qr{catonce not use ref path\!}, 'eval { catonce[] }; $@ # ~> catonce not use ref path!';
t/aion/fs/find.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Carp qw//; use Cwd qw//; use File::Basename qw//; use File::Find qw//; use File::Slurper qw//; use File::Spec qw//; use File::Path qw//; use Scalar::Util qw//; use Test::More 0.98; BEGIN { $SIG{__DI...
# # NAME
#
# Aion::Fs::Find - иÑеÑаÑÐ¾Ñ Ð¿Ð¾Ð¸Ñка Ñайлов Ð´Ð»Ñ Aion::Fs#find
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
use Aion::Fs::Find;
my $iter = Aion::Fs::Find->new(