{"id":19640371,"url":"https://github.com/kentnl/test-file-sharedir","last_synced_at":"2025-10-10T13:33:16.187Z","repository":{"id":56833601,"uuid":"1392605","full_name":"kentnl/Test-File-ShareDir","owner":"kentnl","description":"Create a Fake ShareDir for your modules for testing","archived":false,"fork":false,"pushed_at":"2017-03-01T11:39:15.000Z","size":490,"stargazers_count":3,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T13:33:02.923Z","etag":null,"topics":["perl"],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kentnl.png","metadata":{"files":{"readme":"README.mkdn","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":"2011-02-21T11:49:53.000Z","updated_at":"2020-08-10T16:51:49.000Z","dependencies_parsed_at":"2022-09-08T07:50:48.359Z","dependency_job_id":null,"html_url":"https://github.com/kentnl/Test-File-ShareDir","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/kentnl/Test-File-ShareDir","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentnl%2FTest-File-ShareDir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentnl%2FTest-File-ShareDir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentnl%2FTest-File-ShareDir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentnl%2FTest-File-ShareDir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kentnl","download_url":"https://codeload.github.com/kentnl/Test-File-ShareDir/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentnl%2FTest-File-ShareDir/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004060,"owners_count":26083667,"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-10T02:00:06.843Z","response_time":62,"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":["perl"],"created_at":"2024-11-11T14:05:36.209Z","updated_at":"2025-10-10T13:33:16.165Z","avatar_url":"https://github.com/kentnl.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nTest::File::ShareDir - Create a Fake ShareDir for your modules for testing.\n\n# VERSION\n\nversion 1.001003\n\n# SYNOPSIS\n\n    use Test::More;\n\n    # use FindBin; optional\n\n    use Test::File::ShareDir\n        # -root =\u003e \"$FindBin::Bin/../\" # optional,\n        -share =\u003e {\n            -module =\u003e { 'My::Module' =\u003e 'share/MyModule' }\n            -dist   =\u003e { 'My-Dist'    =\u003e 'share/somefolder' }\n        };\n\n    use My::Module;\n\n    use File::ShareDir qw( module_dir dist_dir );\n\n    module_dir( 'My::Module' ) # dir with files from $dist/share/MyModule\n\n    dist_dir( 'My-Dist' ) # dir with files from $dist/share/somefolder\n\n# DESCRIPTION\n\n`Test::File::ShareDir` is some low level plumbing to enable a distribution to perform tests while consuming its own `share`\ndirectories in a manner similar to how they will be once installed.\n\nThis allows `File::ShareDir` to see the _latest_ version of content instead of simply whatever is installed on whichever target\nsystem you happen to be testing on.\n\n**Note:** This module only has support for creating 'new' style share dirs and are NOT compatible with old File::ShareDirs.\n\nFor this reason, unless you have File::ShareDir 1.00 or later installed, this module will not be usable by you.\n\n# SIMPLE INTERFACE\n\nStarting with version `0.4.0`, there are a few extra interfaces you can use.\n\nThese will probably be more useful, and easier to grok, because they don't have a layer of\nindirection in order to simultaneously support both `Module` and `Dist` `ShareDir`'s.\n\n## Simple Exporter Interfaces\n\n### `Test::File::ShareDir::Dist`\n\n[`Test::File::ShareDir::Dist`](https://metacpan.org/pod/Test::File::ShareDir::Dist) provides a simple export interface\nfor making `TempDir` `ShareDir`'s from a given path:\n\n    use Test::File::ShareDir::Dist { \"Dist-Name\" =\u003e \"share/\" };\n\nThis will automatically create a `ShareDir` for `Dist-Name` in a `TempDir` based on the contents of `CWD/share/`\n\nSee [`Test::File::ShareDir::Dist`](https://metacpan.org/pod/Test::File::ShareDir::Dist) for details.\n\n### `Test::File::ShareDir::Module`\n\n[`Test::File::ShareDir::Module`](https://metacpan.org/pod/Test::File::ShareDir::Module) provides a simple export interface\nfor making `TempDir` `ShareDir`'s from a given path:\n\n    use Test::File::ShareDir::Module { \"Module::Name\" =\u003e \"share/\" };\n\nThis will automatically create a `ShareDir` for `Module::Name` in a `TempDir` based on the contents of `CWD/share/`\n\nSee [`Test::File::ShareDir::Module`](https://metacpan.org/pod/Test::File::ShareDir::Module) for details.\n\n## Simple Object Oriented Interfaces\n\n### `Test::File::ShareDir::Object::Dist`\n\n[`Test::File::ShareDir::Object::Dist`](https://metacpan.org/pod/Test::File::ShareDir::Object::Dist) provides a simple object oriented interface for\nmaking `TempDir` `ShareDir`'s from a given path:\n\n    use Test::File::ShareDir::Object::Dist;\n\n    my $obj = Test::File::ShareDir::Object::Dist-\u003enew( dists =\u003e { \"Dist-Name\" =\u003e \"share/\" } );\n    $obj-\u003einstall_all_dists;\n    $obj-\u003eregister;\n\nThis will automatically create a `ShareDir` for `Dist-Name` in a `TempDir` based on the contents of `CWD/share/`\n\nSee [`Test::File::ShareDir::Object::Dist`](https://metacpan.org/pod/Test::File::ShareDir::Object::Dist) for details.\n\n### `Test::File::ShareDir::Object::Module`\n\n[`Test::File::ShareDir::Object::Module`](https://metacpan.org/pod/Test::File::ShareDir::Object::Module) provides a simple object oriented interface\nfor making `TempDir` `ShareDir`'s from a given path:\n\n    use Test::File::ShareDir::Object::Module;\n\n    my $obj = Test::File::ShareDir::Object::Module-\u003enew( modules =\u003e { \"Module::Name\" =\u003e \"share/\" } );\n    $obj-\u003einstall_all_modules;\n    $obj-\u003eregister;\n\nThis will automatically create a `ShareDir` for `Module::Name` in a `TempDir` based on the contents of `CWD/share/`\n\nSee [`Test::File::ShareDir::Object::Module`](https://metacpan.org/pod/Test::File::ShareDir::Object::Module) for details.\n\n# SCOPE LIMITED UTILITIES\n\n`Test::File::ShareDir` provides a few utility functions to aide in temporarily adjusting `ShareDir` behavior.\n\n    use Test::File::ShareDir qw( with_dist_dir with_module_dir );\n\n    with_dist_dir({ 'Dist-Name' =\u003e 'Some/Path' }, sub {\n      # dist_dir() now behaves differently here\n    });\n    with_module_dir({ 'Module::Name' =\u003e 'Some/Path' }, sub {\n      # module_dir() now behaves differently here\n    });\n\nSee [`EXPORTABLE FUNCTIONS`](#exportable-functions) for details.\n\n# IMPORTING\n\nSince `1.001000`, there are 2 ways of passing arguments to `import`\n\n    use Foo { -root =\u003e ... options }, qw( functions to import );\n    use Foo -optname =\u003e option, -optname =\u003e option, qw( functions to import );\n\nBoth should work, but the former might be less prone to accidental issues.\n\n## IMPORT OPTIONS\n\n### -root\n\nThis parameter is the prefix the other paths are relative to.\n\nIf this parameter is not specified, it defaults to the Current Working Directory ( `CWD` ).\n\nIn versions prior to `0.3.0`, this value was mandatory.\n\nThe rationale behind using `CWD` as the default value is as follows.\n\n- Most users of this module are likely to be using it to test distributions\n- Most users of this module will be using it in `$project/t/` to load files from `$project/share/`\n- Most `CPAN` tools run tests with `CWD` = $project\n\nTherefor, defaulting to `CWD` is a reasonably sane default for most people, but where it is not it can\nstill be overridden.\n\n    -root =\u003e \"$FindBin::Bin/../\" # resolves to project root from t/ regardless of Cwd.\n\n### -share\n\nThis parameter is mandatory, and contains a `hashref` containing the data that explains what directories you want shared.\n\n    -share =\u003e  { ..... }\n\n#### -module\n\n`-module` contains a `hashref` mapping Module names to path names for module\\_dir style share dirs.\n\n    -share =\u003e {\n      -module =\u003e { 'My::Module' =\u003e 'share/mymodule/', }\n    }\n\n    ...\n\n    module_dir('My::Module')\n\nNotedly, it is a `hashref`, which means there is a limitation of one share dir per module. This is simply because having more\nthan one share dir per module makes no sense at all.\n\n#### -dist\n\n`-dist` contains a `hashref` mapping Distribution names to path names for dist\\_dir style share dirs. The same limitation\napplied to `-module` applies here.\n\n    -share =\u003e {\n      -dist =\u003e { 'My-Dist' =\u003e 'share/mydist' }\n    }\n    ...\n    dist_dir('My-Dist')\n\n# EXPORTABLE FUNCTIONS\n\n## with\\_dist\\_dir\n\nSets up a `ShareDir` environment with limited context.\n\n    # with_dist_dir(\\%config, \\\u0026sub);\n    with_dist_dir( { 'Dist-Name' =\u003e 'share/' } =\u003e sub {\n\n        # File::ShareDir resolves to a copy of share/ in this context.\n\n    } );\n\n`%config` can contain anything [`Test::File::ShareDir::Dist`](https://metacpan.org/pod/Test::File::ShareDir::Dist) accepts.\n\n- `-root`: Defaults to `$CWD`\n- `_$distName_`: Declare `$distName`'s `ShareDir`.\n\n_Since 1.001000_\n\n## with\\_module\\_dir\n\nSets up a `ShareDir` environment with limited context.\n\n    # with_module_dir(\\%config, \\\u0026sub);\n    with_module_dir( { 'Module::Name' =\u003e 'share/' } =\u003e sub {\n\n        # File::ShareDir resolves to a copy of share/ in this context.\n\n    } );\n\n`%config` can contain anything [`Test::File::ShareDir::Module`](https://metacpan.org/pod/Test::File::ShareDir::Module) accepts.\n\n- `-root`: Defaults to `$CWD`\n- `_$moduleName_`: Declare `$moduleName`'s `ShareDir`.\n\n_Since 1.001000_\n\n# THANKS\n\nThanks to the `#distzilla` crew for ideas,suggestions, code review and debugging, even though not all of it made it into releases.\n\n- [DOLMEN](cpan:///author/dolmen)\n- [ETHER](cpan:///author/ether)\n- [HAARG](cpan:///author/haarg)\n- [RJBS](cpan:///author/rjbs)\n\n# AUTHOR\n\nKent Fredric \u003ckentnl@cpan.org\u003e\n\n# COPYRIGHT AND LICENSE\n\nThis software is copyright (c) 2017 by Kent Fredric \u003ckentnl@cpan.org\u003e.\n\nThis is free software; you can redistribute it and/or modify it under\nthe same terms as the Perl 5 programming language system itself.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkentnl%2Ftest-file-sharedir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkentnl%2Ftest-file-sharedir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkentnl%2Ftest-file-sharedir/lists"}