{"id":18779418,"url":"https://github.com/zostay/raku-io-glob","last_synced_at":"2025-10-11T15:32:53.693Z","repository":{"id":35780139,"uuid":"40060105","full_name":"zostay/raku-IO-Glob","owner":"zostay","description":"Glob matching for paths \u0026 strings and listing files","archived":false,"fork":false,"pushed_at":"2020-06-18T11:56:27.000Z","size":67,"stargazers_count":4,"open_issues_count":8,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T11:40:55.572Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zostay.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-01T21:10:29.000Z","updated_at":"2021-05-14T15:56:57.000Z","dependencies_parsed_at":"2022-09-06T23:51:18.685Z","dependency_job_id":null,"html_url":"https://github.com/zostay/raku-IO-Glob","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/zostay/raku-IO-Glob","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-IO-Glob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-IO-Glob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-IO-Glob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-IO-Glob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zostay","download_url":"https://codeload.github.com/zostay/raku-IO-Glob/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-IO-Glob/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007604,"owners_count":26084334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T20:20:01.033Z","updated_at":"2025-10-11T15:32:53.675Z","avatar_url":"https://github.com/zostay.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"NAME\n====\n\nIO::Glob - Glob matching for paths, strings and file listings.\n\nSYNOPSIS\n========\n\n    use IO::Glob;\n\n    # Need a list of files somewhere?\n    for glob(\"src/core/*.pm\") -\u003e $file { say ~$file }\n\n    # Or apply the glob to a chosen directory\n    with glob(\"*.log\") {\n        for .dir(\"/var/log/error\") -\u003e $err-log { ... }\n        for .dir(\"/var/log/access\") -\u003e $acc-log { ... }\n    }\n\n    # Use a glob to match a string or path\n    if \"some-string\" ~~ glob(\"some-*\") { say \"match string!\" }\n    if \"some/path.txt\".IO ~~ glob(\"some/*.txt\") { say \"match path!\" }\n\n    # Use a glob as a test in built-in IO::Path.dir()\n    for \"/var/log\".IO.dir(test =\u003e glob(\"*.err\")) -\u003e $err-log { ... }\n\n    # Globs are objects, which you can save, reuse, and pass around\n    my $file-match = glob(\"*.txt\");\n    my @files := dir(\"$*HOME/docs\", :test($file-match));\n\n    # Want to use SQL globbing with % and _ instead?\n    for glob(\"src/core/%.pm\", :sql) -\u003e $file { ... }\n\n    # Or want globbing without all the fancy bits?\n    # :simple turns off everything but * and ?\n    for glob(\"src/core/*.pm\", :simple) -\u003e $file { ... }\n\nDESCRIPTION\n===========\n\nTraditionally, globs provide a handy shorthand for describing the files you're interested in based upon their path. This class provides that shorthand using a BSD-style glob grammar that is familiar to Perl devs. However, it is more powerful than its Perl 5 predecessor.\n\n  * Globs are built as `IO::Glob` objects which encapsulate the pattern. You may create them and pass them around.\n\n  * By using them as an iterator, you can put globs to their traditional use: listing all the files in a directory.\n\n  * Globs can also be smart-matched. It will match against strings or anything that stringifies; it will work against [IO::Path](IO::Path)s too.\n\n  * Globbing can be done with different grammars. This class ships with three: simple, BSD, and SQL.\n\n  * **Experimental.** You can use custom grammars for your smart match.\n\nSUBROUTINES\n===========\n\nsub glob\n--------\n\n    sub glob(\n        Str:D $pattern,\n        Bool :$sql,\n        Bool :$bsd,\n        Bool :$simple,\n        :$grammar,\n        :$spec = $*SPEC\n    ) returns IO::Glob:D\n\n    sub glob(\n        Whatever $,\n        Bool :$sql,\n        Bool :$bsd,\n        Bool :$simple,\n        :$grammar,\n        :$spec = $*SPEC\n    ) returns IO::Glob:D\n\nWhen given a string, that string will be stored in the [method pattern/pattern](#method pattern/pattern) attribute and will be parsed according to the [method grammar/grammar](#method grammar/grammar).\n\nWhen given [Whatever](Whatever) (`*`) as the argument, it's the same as:\n\n    glob('*');\n\nwhich will match anything. (Note that what whatever matches may be grammar specific, so `glob(*, :sql)` is the same as `glob('%')`.)\n\nIf you want to pick from one of the built-in grammars, you may use these options:\n\n  * `:bsd` is the default specifying this is explicit, but unnecessary. This grammar supports `*`, `?`, `[abc]`, `[!abc]`, `~`, and `{ab,cd,efg}`.\n\n  * `:sql` uses a SQL-ish grammar that provides `%` and `_` matching.\n\n  * `:simple` is a simplified version of `:bsd`, but only supports `*` and `?`.\n\nThe `:$spec` option allows you to specify the [IO::Spec](IO::Spec) to use when matching paths. It uses `$*SPEC`, by default. The IO::Spec is used to split paths by directory separator when matching paths. (This is ignored when matching against other kinds of objects.)\n\nAn alternative to this is to use the optional `:$grammar` setting lets you select a globbing grammar object to use. These are provided:\n\n  * IO::Glob::BSD\n\n  * IO::Glob::SQL\n\n  * IO::Glob::Simple\n\n**Experimental.** If you want a different grammar, you may create your own as well, but no documentation of that process has been written yet as of this writing.\n\nMETHODS\n=======\n\nmethod pattern\n--------------\n\n    method pattern() returns Str:D\n\nReturns the pattern set during construction.\n\nmethod spec\n-----------\n\n    method spec() returns IO::Spec:D\n\nReturns the spec set during construction.\n\nmethod grammar\n--------------\n\n    method grammar() returns Any:D\n\nReturns the grammar set during construction.\n\nmethod dir\n----------\n\n    method dir(Cool $path = '.') returns Seq:D\n\nReturns a list of files matching the glob. This will descend directories if the pattern contains a [IO::Spec#dir-sep](IO::Spec#dir-sep) using a depth-first search. This method is called implicitly when you use the object as an iterator. For example, these two lines are identical:\n\n    for glob('*.*') -\u003e $every-dos-file { ... }\n    for glob('*.*').dir -\u003e $every-dos-file { ... }\n\nThis is the preferred method for listing files as it will be sure to respect ordering of files by alternates. For example,\n\n    for glob(\"{bc,ab}*\") -\u003e $file { say $file }\n\nThis will print all files starting with \"bc\" before any files starting with ab.\n\nmethod ACCEPTS\n--------------\n\n    method ACCEPTS(Mu:U $) returns Bool:D\n    method ACCEPTS(Str:D(Any) $candiate) returns Bool:D\n    method ACCEPTS(IO::Path:D $path) returns Bool:D\n\nThis implements smart-match. Undefined values never match. Strings are matched using the whole pattern, without reference to any directory separators in the string. Paths, however, are matched and carefully respect directory separators. For most circumstances, this will not make any difference. However, a case like this will be treated very differently in each case:\n\n    my $glob = glob(\"hello{x,y/}world\");\n    say \"String\" if \"helloy/world\" ~~ $glob;      # outputs\u003e String\n    say \"Path\"   if \"helloy/world\".IO ~~ $glob;   # outputs nothing, no match\n    say \"Path 2\" if \"helloy{x,y/}world\" ~~ $glob; # outputs\u003e Path 2\n\nThe reason is that the second and third are matched in parts as follows:\n\n    \"helloy\" ~~ glob(\"hello{x,y\") \u0026\u0026 \"world\" ~~ glob(\"}world\")\n    \"hello{x,y\" ~~ glob(\"hello{x,y\") \u0026\u0026 \"}world\" ~~ glob(\"}world\")\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzostay%2Fraku-io-glob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzostay%2Fraku-io-glob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzostay%2Fraku-io-glob/lists"}