pax_global_header00006660000000000000000000000064144772153460014527gustar00rootroot0000000000000052 comment=4a70323974cbeb0b78f09e46c2982ea6823af6bf raku-file-find-0.2.0/000077500000000000000000000000001447721534600143235ustar00rootroot00000000000000raku-file-find-0.2.0/.github/000077500000000000000000000000001447721534600156635ustar00rootroot00000000000000raku-file-find-0.2.0/.github/workflows/000077500000000000000000000000001447721534600177205ustar00rootroot00000000000000raku-file-find-0.2.0/.github/workflows/test.yml000066400000000000000000000012361447721534600214240ustar00rootroot00000000000000name: test on: push: branches: - '*' tags-ignore: - '*' pull_request: jobs: raku: strategy: matrix: os: - ubuntu-latest - macos-latest - windows-latest raku-version: - 'latest' runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - uses: Raku/setup-raku@v1 with: raku-version: ${{ matrix.raku-version }} - name: Install Dependencies run: zef install --/test --test-depends --deps-only . - name: Install App::Prove6 run: zef install --/test App::Prove6 - name: Run Tests run: prove6 -I. t raku-file-find-0.2.0/.gitignore000066400000000000000000000000111447721534600163030ustar00rootroot00000000000000.precomp/raku-file-find-0.2.0/.travis.yml000066400000000000000000000002611447721534600164330ustar00rootroot00000000000000language: minimal services: - docker install: - docker pull jjmerelo/raku-test - docker images script: - docker run -t -v $TRAVIS_BUILD_DIR:/test jjmerelo/raku-test raku-file-find-0.2.0/Changes000066400000000000000000000003371447721534600156210ustar00rootroot00000000000000Revision history for File-Find {{$NEXT}} 0.2.0 2023-09-10T03:24:15+02:00 - support for junctions for `name` and `exclude` parameters 0.1.2 2023-07-26T12:50:03+02:00 - First version under raku-community-modules raku-file-find-0.2.0/LICENSE000066400000000000000000000020661447721534600153340ustar00rootroot00000000000000The MIT License Copyright (c) 2010 Tadeusz Sośnierz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. raku-file-find-0.2.0/META6.json000066400000000000000000000012771447721534600160410ustar00rootroot00000000000000{ "auth": "zef:raku-community-modules", "authors": [ "Tadeusz “tadzik” Sośnierz", "Dagur Valberg Johansson", "Elizabeth Mattijsen", "Filip Sergot", "GlitchMr", "Heather", "isleofmax", "Moritz Lenz", "Paul Cochrane", "Steve Mynott", "timo", "Tobias Leich" ], "build-depends": [ ], "depends": [ ], "description": "Get a lazy list of a directory tree", "license": "MIT", "name": "File::Find", "perl": "6.*", "provides": { "File::Find": "lib/File/Find.rakumod" }, "resources": [ ], "source-url": "git://github.com/raku-community-modules/File-Find.git", "tags": [ ], "test-depends": [ ], "version": "0.2.0" } raku-file-find-0.2.0/README.md000066400000000000000000000053771447721534600156160ustar00rootroot00000000000000[![Actions Status](https://github.com/raku-community-modules/File-Find/actions/workflows/test.yml/badge.svg)](https://github.com/raku-community-modules/File-Find/actions) NAME ==== File::Find - Get a lazy list of a directory tree SYNOPSIS ======== use File::Find; my @list := find(dir => 'foo'); say @list[0..3]; my $list = find(dir => 'foo'); say $list[0..3]; DESCRIPTION =========== `File::Find` allows you to get the contents of the given directory, recursively, depth first. The only exported function, `find()`, generates a lazy list of files in given directory. Every element of the list is an `IO::Path` object, described below. `find()` takes one (or more) named arguments. The `dir` argument is mandatory, and sets the directory `find()` will traverse. There are also few optional arguments. If more than one is passed, all of them must match for a file to be returned. name ---- Specify a name of the file `File::Find` is ought to look for. If you pass a string here, `find()` will return only the files with the given name. When passing a regex, only the files with path matching the pattern will be returned. Any other type of argument passed here will just be smartmatched against the path (which is exactly what happens to regexes passed, by the way). type ---- Given a type, `find()` will only return files being the given type. The available types are `file`, `dir` or `symlink`. exclude ------- Exclude is meant to be used for skipping certain big and uninteresting directories, like '.git'. Neither them nor any of their contents will be returned, saving a significant amount of time. The value of `exclude` will be smartmatched against each IO object found by File::Find. It's recommended that it's passed as an IO object (or a Junction of those) so we avoid silly things like slashes vs backslashes on different platforms. keep-going ---------- Parameter `keep-going` tells `find()` to not stop finding files on errors such as 'Access is denied', but rather ignore the errors and keep going. recursive --------- By default, `find` will recursively traverse a directory tree, descending into any subdirectories it finds. This behaviour can be changed by setting `recursive` to a false value. In this case, only the first level entries will be processed. Perl's File::Find ================= Please note, that this module is not trying to be the verbatim port of Perl's File::Find module. Its interface is closer to Perl's File::Find::Rule, and its features are planned to be similar one day. CAVEATS ======= List assignment is eager in Raku, so if You assign `find()` result to an array, the elements will be copied and the laziness will be spoiled. For a proper lazy list, use either binding (`:=`) or assign a result to a scalar value (see SYNOPSIS). raku-file-find-0.2.0/dist.ini000066400000000000000000000002611447721534600157660ustar00rootroot00000000000000name = File-Find [ReadmeFromPod] ; enabled = false filename = lib/File/Find.rakumod [UploadToZef] [PruneFiles] ; match = ^ 'xt/' [Badges] provider = github-actions/test.yml raku-file-find-0.2.0/lib/000077500000000000000000000000001447721534600150715ustar00rootroot00000000000000raku-file-find-0.2.0/lib/File/000077500000000000000000000000001447721534600157505ustar00rootroot00000000000000raku-file-find-0.2.0/lib/File/Find.rakumod000066400000000000000000000075071447721534600202250ustar00rootroot00000000000000unit module File::Find; sub checkrules (IO::Path $elem, %opts) { with %opts -> $opts { return False unless $elem.basename ~~ $opts } with %opts { when 'dir' { return False unless $elem ~~ :d } when 'file' { return False unless $elem ~~ :f } when 'symlink' { return False unless $elem ~~ :l } default { die "type attribute has to be dir, file or symlink"; } } return True } sub find (:$dir!, Mu :$name, :$type, Mu :$exclude = False, Bool :$recursive = True, Bool :$keep-going = False) is export { my @targets = dir($dir); gather while @targets { my $elem = @targets.shift; # exclude is special because it also stops traversing inside, # which checkrules does not next if $elem ~~ $exclude; take $elem if checkrules($elem, { :$name, :$type, :$exclude }); if $recursive { if $elem.IO ~~ :d { @targets.append: dir($elem); CATCH { when X::IO::Dir { $_.throw unless $keep-going; next; }} } } } } =begin pod =head1 NAME File::Find - Get a lazy list of a directory tree =head1 SYNOPSIS use File::Find; my @list := find(dir => 'foo'); say @list[0..3]; my $list = find(dir => 'foo'); say $list[0..3]; =head1 DESCRIPTION C allows you to get the contents of the given directory, recursively, depth first. The only exported function, C, generates a lazy list of files in given directory. Every element of the list is an C object, described below. C takes one (or more) named arguments. The C argument is mandatory, and sets the directory C will traverse. There are also few optional arguments. If more than one is passed, all of them must match for a file to be returned. =head2 name Specify a name of the file C is ought to look for. If you pass a string here, C will return only the files with the given name. When passing a regex, only the files with path matching the pattern will be returned. Any other type of argument passed here will just be smartmatched against the path (which is exactly what happens to regexes passed, by the way). =head2 type Given a type, C will only return files being the given type. The available types are C, C or C. =head2 exclude Exclude is meant to be used for skipping certain big and uninteresting directories, like '.git'. Neither them nor any of their contents will be returned, saving a significant amount of time. The value of C will be smartmatched against each IO object found by File::Find. It's recommended that it's passed as an IO object (or a Junction of those) so we avoid silly things like slashes vs backslashes on different platforms. =head2 keep-going Parameter C tells C to not stop finding files on errors such as 'Access is denied', but rather ignore the errors and keep going. =head2 recursive By default, C will recursively traverse a directory tree, descending into any subdirectories it finds. This behaviour can be changed by setting C to a false value. In this case, only the first level entries will be processed. =head1 Perl's File::Find Please note, that this module is not trying to be the verbatim port of Perl's File::Find module. Its interface is closer to Perl's File::Find::Rule, and its features are planned to be similar one day. =head1 CAVEATS List assignment is eager in Raku, so if You assign C result to an array, the elements will be copied and the laziness will be spoiled. For a proper lazy list, use either binding (C<:=>) or assign a result to a scalar value (see SYNOPSIS). =end pod # vim: ft=perl6 raku-file-find-0.2.0/t/000077500000000000000000000000001447721534600145665ustar00rootroot00000000000000raku-file-find-0.2.0/t/01-file-find.t000066400000000000000000000056651447721534600170420ustar00rootroot00000000000000use Test; use File::Find; plan 21; my $res = find(:dir); my @test = $res.map({ .Str }).sort; equals @test, , 'just a dir'; # names $res = find(:dir, :name(/foo/)); @test = $res.map({ .Str }).sort; equals @test, , 'name with regex'; # (default) recursive find $res = find(:dir, :name); is $res.elems, 2, 'two files with name and string'; # with forced find to Not work recursive $res = find(:dir, :name, recursive => False); is $res.elems, 1, 'name with a string'; $res = find(:dir, :name); is $res.elems, 0, 'no results'; # types $res = find(:dir, :type); @test = $res.map({ .Str }).sort; equals @test, , 'types: dir'; $res = find(:dir, :type, :name(/foo/)); @test = $res.map({ .Str }).sort; equals @test, , 'types: dir, combined with name'; $res = find(:dir, :type, :name(/foo/)); @test = $res.map({ .Str }).sort; equals @test, , 'types: file, combined with name'; #exclude $res = find(:dir, :type, :exclude('t/dir1/another_dir'.IO)); @test = $res.map({ .Str }).sort; equals @test, , 'exclude works'; # exclude with junction $res = find(:dir, :type, :exclude( any(/\.foo/, /\.bar/) )); @test = $res.map({ .Str }).sort; isnt( @test[0].^name, 'Junction', "Return from find should not be a Junction" ); equals @test, < t/dir1/another_dir/empty_file t/dir1/foodir/not_a_dir >, 'exclude with junction'; # name with junction $res = find(:dir, :name( any(/\.foo/, /\.bar/) )); @test = $res.map({ .Str }).sort; isnt( @test[0].^name, 'Junction', "Return from find should not be a Junction" ); equals @test, < t/dir1/another_dir/file.bar t/dir1/file.bar t/dir1/file.foo >, 'name with junction'; #keep-going skip-rest('keep-going tests are brokenz'); if 0 { my $skip-first = True; my $throw = True; # Wrap dir to throw when we want it to. my $w = &dir.wrap({ if $skip-first { $skip-first = False; return callsame; } if $throw { $throw = False; X::IO::Dir.new(path => "dummy", os-error => "dummy").throw } callsame; }); dies-ok(sub { find(:dir) }, "dies due to X::IO::Dir"); $throw = $skip-first = True; $res = find(:dir, :name, keep-going => True); is $res.elems, 1, 'found one of two files due to X::IO::Dir'; LEAVE { &dir.unwrap($w); } } sub equals(\a, \b, $name) { my $is-ok = is a.elems, b.elems, a ~ " and " ~ b ~ " have the same length "; ok ([&&] a >>~~<< b.map(*.IO)), $name if $is-ok; } exit 0; # I have no idea what I'm doing, but I get Non-zero exit status w/o this raku-file-find-0.2.0/t/dir1/000077500000000000000000000000001447721534600154255ustar00rootroot00000000000000raku-file-find-0.2.0/t/dir1/another_dir/000077500000000000000000000000001447721534600177235ustar00rootroot00000000000000raku-file-find-0.2.0/t/dir1/another_dir/empty_file000066400000000000000000000000001447721534600217710ustar00rootroot00000000000000raku-file-find-0.2.0/t/dir1/another_dir/file.bar000066400000000000000000000000001447721534600213160ustar00rootroot00000000000000raku-file-find-0.2.0/t/dir1/file.bar000066400000000000000000000000001447721534600170200ustar00rootroot00000000000000raku-file-find-0.2.0/t/dir1/file.foo000066400000000000000000000000001447721534600170370ustar00rootroot00000000000000raku-file-find-0.2.0/t/dir1/foodir/000077500000000000000000000000001447721534600167075ustar00rootroot00000000000000raku-file-find-0.2.0/t/dir1/foodir/not_a_dir000066400000000000000000000000001447721534600205560ustar00rootroot00000000000000