lib-relative-1.000000755001750001750 013444010620 14064 5ustar00grinnzgrinnz000000000000README100644001750001750 540113444010620 15025 0ustar00grinnzgrinnz000000000000lib-relative-1.000NAME lib::relative - Add paths relative to the current file to @INC SYNOPSIS # Path is relative to this file, not current working directory use lib::relative 'path/to/lib'; use lib::relative '../../lib'; # Add two lib paths, as in lib.pm use lib::relative 'foo', 'bar'; # Absolute paths are passed through unchanged use lib::relative 'foo/baz', '/path/to/lib'; # Equivalent code using core modules use Cwd (); use File::Basename (); use File::Spec (); use lib File::Spec->catdir(File::Basename::dirname(Cwd::abs_path __FILE__), 'path/to/lib'); DESCRIPTION Adding a path to @INC to load modules from a local directory may seem simple, but has a few common pitfalls to be aware of. Directly adding a relative path to @INC means that any later code that changes the current working directory will change where modules are loaded from. This applies to the . path that used to be in @INC by default until perl 5.26.0, or a relative path added in code like use lib 'path/to/lib', and may be a vulnerability if such a location is not supposed to be writable. Additionally, the commonly used FindBin module relies on interpreter state and the path to the original script invoked by the perl interpreter, sometimes requiring workarounds in uncommon cases like generated or embedded code. This module proposes a more straightforward method: take a path relative to the current file, absolutize it, and add it to @INC. If this module is already available to be loaded, it can be used as with lib.pm, passing relative paths, which will be absolutized relative to the current file then passed on to lib. Multiple arguments will be separately absolutized, and absolute paths will be passed on unchanged. For cases where this module cannot be loaded beforehand, the last section of the "SYNOPSIS" can be copy-pasted into a file to perform the same task. CAVEATS Due to __FILE__ possibly being a path relative to the current working directory, be sure to use lib::relative or the equivalent code from "SYNOPSIS" as early as possible in the file. If a chdir occurs before this code, it will add the incorrect directory path. All file paths are expected to be in a format appropriate to the current operating system, e.g. ..\\foo\\bar on Windows. "catdir" in File::Spec can be used to form directory paths portably. BUGS Report any issues on the public bugtracker. AUTHOR Dan Book COPYRIGHT AND LICENSE This software is Copyright (c) 2017 by Dan Book. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) SEE ALSO lib, FindBin, Dir::Self Changes100644001750001750 66013444010620 15422 0ustar00grinnzgrinnz000000000000lib-relative-1.0001.000 2019-03-18 17:45:50 EDT - Stable release 0.999 2019-03-01 13:49:33 EST (TRIAL RELEASE) - Now uses Cwd::abs_path to resolve __FILE__, so in the rare case where __FILE__ is a symlink, lib paths will be loaded relative to the target file and not the symlink. 0.002 2017-07-08 00:46:56 EDT - Stable release 0.001 2017-06-26 20:31:05 EDT (TRIAL RELEASE) - Trial release, to determine portability LICENSE100644001750001750 2151513444010620 15176 0ustar00grinnzgrinnz000000000000lib-relative-1.000This software is Copyright (c) 2017 by Dan Book. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) The Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. INSTALL100644001750001750 433213444010620 15200 0ustar00grinnzgrinnz000000000000lib-relative-1.000This is the Perl distribution lib-relative. Installing lib-relative is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm lib::relative If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment. ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan lib::relative ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, install configure prerequisites (see below), then build it: % perl Makefile.PL % make && make test Then install it: % make install On Windows platforms, you should use `dmake` or `nmake`, instead of `make`. If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib The prerequisites of this distribution will also have to be installed manually. The prerequisites are listed in one of the files: `MYMETA.yml` or `MYMETA.json` generated by running the manual build process described above. ## Configure Prerequisites This distribution requires other modules to be installed before this distribution's installer can be run. They can be found under the "configure_requires" key of META.yml or the "{prereqs}{configure}{requires}" key of META.json. ## Other Prerequisites This distribution may require additional modules to be installed after running Makefile.PL. Look for prerequisites in the following phases: * to run make, PHASE = build * to use the module code itself, PHASE = runtime * to run tests, PHASE = test They can all be found in the "PHASE_requires" key of MYMETA.yml or the "{prereqs}{PHASE}{requires}" key of MYMETA.json. ## Documentation lib-relative documentation is available as POD. You can run `perldoc` from a shell to read the documentation: % perldoc lib::relative For more information on installing Perl modules via CPAN, please see: https://www.cpan.org/modules/INSTALL.html cpanfile100644001750001750 27513444010620 15635 0ustar00grinnzgrinnz000000000000lib-relative-1.000requires 'perl' => '5.006001'; requires 'Cwd'; requires 'File::Spec'; requires 'File::Basename'; requires 'lib'; test_requires 'Test::More' => '0.88'; test_requires 'File::Temp' => '0.19'; dist.ini100644001750001750 27413444010620 15574 0ustar00grinnzgrinnz000000000000lib-relative-1.000name = lib-relative author = Dan Book license = Artistic_2_0 copyright_holder = Dan Book copyright_year = 2017 [@Author::DBOOK] :version = 0.032 pod_tests = syntax META.yml100644001750001750 2650113444010620 15442 0ustar00grinnzgrinnz000000000000lib-relative-1.000--- abstract: 'Add paths relative to the current file to @INC' author: - 'Dan Book ' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' File::Temp: '0.19' Test::More: '0.88' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010' license: artistic_2 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: lib-relative no_index: directory: - eg - examples - inc - share - t - xt provides: lib::relative: file: lib/lib/relative.pm version: '1.000' requires: Cwd: '0' File::Basename: '0' File::Spec: '0' lib: '0' perl: '5.006001' resources: bugtracker: https://github.com/Grinnz/lib-relative/issues homepage: https://github.com/Grinnz/lib-relative repository: https://github.com/Grinnz/lib-relative.git version: '1.000' x_Dist_Zilla: perl: version: '5.028001' plugins: - class: Dist::Zilla::Plugin::GithubMeta name: '@Author::DBOOK/GithubMeta' version: '0.58' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: '@Author::DBOOK/Readme_Github' version: '0.163250' - class: Dist::Zilla::Plugin::GenerateFile name: '@Author::DBOOK/Generate_Contrib' version: '6.012' - class: Dist::Zilla::Plugin::MetaConfig name: '@Author::DBOOK/MetaConfig' version: '6.012' - class: Dist::Zilla::Plugin::MetaProvides::Package config: Dist::Zilla::Plugin::MetaProvides::Package: finder_objects: - class: Dist::Zilla::Plugin::FinderCode name: '@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.012' include_underscores: 0 Dist::Zilla::Role::MetaProvider::Provider: $Dist::Zilla::Role::MetaProvider::Provider::VERSION: '2.002004' inherit_missing: '1' inherit_version: '1' meta_noindex: '1' Dist::Zilla::Role::ModuleMetadata: Module::Metadata: '1.000033' version: '0.006' name: '@Author::DBOOK/MetaProvides::Package' version: '2.004003' - class: Dist::Zilla::Plugin::Prereqs::FromCPANfile name: '@Author::DBOOK/Prereqs::FromCPANfile' version: '0.08' - class: Dist::Zilla::Plugin::Git::Contributors config: Dist::Zilla::Plugin::Git::Contributors: git_version: 2.20.1 include_authors: 0 include_releaser: 1 order_by: name paths: [] name: '@Author::DBOOK/Git::Contributors' version: '0.035' - class: Dist::Zilla::Plugin::MetaNoIndex name: '@Author::DBOOK/MetaNoIndex' version: '6.012' - class: Dist::Zilla::Plugin::CheckChangesHasContent name: '@Author::DBOOK/CheckChangesHasContent' version: '0.011' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - README.pod - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.20.1 repo_root: . name: '@Author::DBOOK/Git::Check' version: '2.045' - class: Dist::Zilla::Plugin::RewriteVersion config: Dist::Zilla::Plugin::RewriteVersion: add_tarball_name: 0 finders: - ':ExecFiles' - ':InstallModules' global: 0 skip_version_provider: 0 name: '@Author::DBOOK/RewriteVersion' version: '0.018' - class: Dist::Zilla::Plugin::NextRelease name: '@Author::DBOOK/NextRelease' version: '6.012' - class: Dist::Zilla::Plugin::CopyFilesFromRelease config: Dist::Zilla::Plugin::CopyFilesFromRelease: filename: - CONTRIBUTING.md - INSTALL - LICENSE - META.json - Makefile.PL match: [] name: '@Author::DBOOK/CopyFilesFromRelease' version: '0.006' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: - / commit_msg: '%v%n%n%c' Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - CONTRIBUTING.md - Changes - INSTALL - LICENSE - META.json - Makefile.PL - README.pod - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.20.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Author::DBOOK/Git::Commit' version: '2.045' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: '1.000' tag_format: '%v' tag_message: '%v' Dist::Zilla::Role::Git::Repo: git_version: 2.20.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Author::DBOOK/Git::Tag' version: '2.045' - class: Dist::Zilla::Plugin::BumpVersionAfterRelease config: Dist::Zilla::Plugin::BumpVersionAfterRelease: finders: - ':ExecFiles' - ':InstallModules' global: 0 munge_makefile_pl: 0 name: '@Author::DBOOK/BumpVersionAfterRelease' version: '0.018' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: 'Bump version' Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: - (?^:^) changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.20.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Author::DBOOK/Commit_Version_Bump' version: '2.045' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - origin remotes_must_exist: 1 Dist::Zilla::Role::Git::Repo: git_version: 2.20.1 repo_root: . name: '@Author::DBOOK/Git::Push' version: '2.045' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@Author::DBOOK/PodSyntaxTests' version: '6.012' - class: Dist::Zilla::Plugin::Test::ReportPrereqs name: '@Author::DBOOK/Test::ReportPrereqs' version: '0.027' - class: Dist::Zilla::Plugin::Git::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: - Build.PL - CONTRIBUTING.md - INSTALL - LICENSE - META.json - Makefile.PL - Makefile.PL exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . Dist::Zilla::Plugin::Git::GatherDir: include_untracked: 0 name: '@Author::DBOOK/Git::GatherDir' version: '2.045' - class: Dist::Zilla::Plugin::Regenerate::AfterReleasers config: Dist::Zilla::Plugin::Regenerate::AfterReleasers: plugins: - '@Author::DBOOK/Readme_Github' - '@Author::DBOOK/CopyFilesFromRelease' Dist::Zilla::Role::Regenerator: $Dist::Zilla::Role::Regenerator::VERSION: '0.001001' name: '@Author::DBOOK/Regenerate::AfterReleasers' version: '0.001001' - class: Dist::Zilla::Plugin::PruneCruft name: '@Author::DBOOK/PruneCruft' version: '6.012' - class: Dist::Zilla::Plugin::ManifestSkip name: '@Author::DBOOK/ManifestSkip' version: '6.012' - class: Dist::Zilla::Plugin::MetaYAML name: '@Author::DBOOK/MetaYAML' version: '6.012' - class: Dist::Zilla::Plugin::MetaJSON name: '@Author::DBOOK/MetaJSON' version: '6.012' - class: Dist::Zilla::Plugin::License name: '@Author::DBOOK/License' version: '6.012' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: '@Author::DBOOK/ReadmeAnyFromPod' version: '0.163250' - class: Dist::Zilla::Plugin::ExecDir name: '@Author::DBOOK/ExecDir' version: '6.012' - class: Dist::Zilla::Plugin::ShareDir name: '@Author::DBOOK/ShareDir' version: '6.012' - class: Dist::Zilla::Plugin::ExecDir name: '@Author::DBOOK/ScriptDir' version: '6.012' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Author::DBOOK/MakeMaker' version: '6.012' - class: Dist::Zilla::Plugin::RunExtraTests config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Author::DBOOK/RunExtraTests' version: '0.029' - class: Dist::Zilla::Plugin::InstallGuide name: '@Author::DBOOK/InstallGuide' version: '1.200012' - class: Dist::Zilla::Plugin::Manifest name: '@Author::DBOOK/Manifest' version: '6.012' - class: Dist::Zilla::Plugin::TestRelease name: '@Author::DBOOK/TestRelease' version: '6.012' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Author::DBOOK/ConfirmRelease' version: '6.012' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Author::DBOOK/UploadToCPAN' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: '@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.012' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '6.012' x_contributors: - 'Dan Book ' x_generated_by_perl: v5.28.1 x_serialization_backend: 'YAML::Tiny version 1.73' MANIFEST100644001750001750 61613444010620 15261 0ustar00grinnzgrinnz000000000000lib-relative-1.000# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.012. CONTRIBUTING.md Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README cpanfile dist.ini lib/lib/relative.pm t/00-report-prereqs.dd t/00-report-prereqs.t t/lib_relative.t t/testlib/MyTestModule.pm t/testlib/MyTestModule2.pm t/testlib/MyTestModule3.pm t/testlib/load_relative.pl xt/author/pod-syntax.t META.json100644001750001750 4266313444010620 15621 0ustar00grinnzgrinnz000000000000lib-relative-1.000{ "abstract" : "Add paths relative to the current file to @INC", "author" : [ "Dan Book " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010", "license" : [ "artistic_2" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "lib-relative", "no_index" : { "directory" : [ "eg", "examples", "inc", "share", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Cwd" : "0", "File::Basename" : "0", "File::Spec" : "0", "lib" : "0", "perl" : "5.006001" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "File::Temp" : "0.19", "Test::More" : "0.88" } } }, "provides" : { "lib::relative" : { "file" : "lib/lib/relative.pm", "version" : "1.000" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/Grinnz/lib-relative/issues" }, "homepage" : "https://github.com/Grinnz/lib-relative", "repository" : { "type" : "git", "url" : "https://github.com/Grinnz/lib-relative.git", "web" : "https://github.com/Grinnz/lib-relative" } }, "version" : "1.000", "x_Dist_Zilla" : { "perl" : { "version" : "5.028001" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "@Author::DBOOK/GithubMeta", "version" : "0.58" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "@Author::DBOOK/Readme_Github", "version" : "0.163250" }, { "class" : "Dist::Zilla::Plugin::GenerateFile", "name" : "@Author::DBOOK/Generate_Contrib", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@Author::DBOOK/MetaConfig", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaProvides::Package", "config" : { "Dist::Zilla::Plugin::MetaProvides::Package" : { "finder_objects" : [ { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.012" } ], "include_underscores" : 0 }, "Dist::Zilla::Role::MetaProvider::Provider" : { "$Dist::Zilla::Role::MetaProvider::Provider::VERSION" : "2.002004", "inherit_missing" : 1, "inherit_version" : 1, "meta_noindex" : 1 }, "Dist::Zilla::Role::ModuleMetadata" : { "Module::Metadata" : "1.000033", "version" : "0.006" } }, "name" : "@Author::DBOOK/MetaProvides::Package", "version" : "2.004003" }, { "class" : "Dist::Zilla::Plugin::Prereqs::FromCPANfile", "name" : "@Author::DBOOK/Prereqs::FromCPANfile", "version" : "0.08" }, { "class" : "Dist::Zilla::Plugin::Git::Contributors", "config" : { "Dist::Zilla::Plugin::Git::Contributors" : { "git_version" : "2.20.1", "include_authors" : 0, "include_releaser" : 1, "order_by" : "name", "paths" : [] } }, "name" : "@Author::DBOOK/Git::Contributors", "version" : "0.035" }, { "class" : "Dist::Zilla::Plugin::MetaNoIndex", "name" : "@Author::DBOOK/MetaNoIndex", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::CheckChangesHasContent", "name" : "@Author::DBOOK/CheckChangesHasContent", "version" : "0.011" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "README.pod", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.20.1", "repo_root" : "." } }, "name" : "@Author::DBOOK/Git::Check", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::RewriteVersion", "config" : { "Dist::Zilla::Plugin::RewriteVersion" : { "add_tarball_name" : 0, "finders" : [ ":ExecFiles", ":InstallModules" ], "global" : 0, "skip_version_provider" : 0 } }, "name" : "@Author::DBOOK/RewriteVersion", "version" : "0.018" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@Author::DBOOK/NextRelease", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::CopyFilesFromRelease", "config" : { "Dist::Zilla::Plugin::CopyFilesFromRelease" : { "filename" : [ "CONTRIBUTING.md", "INSTALL", "LICENSE", "META.json", "Makefile.PL" ], "match" : [] } }, "name" : "@Author::DBOOK/CopyFilesFromRelease", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [ "/" ], "commit_msg" : "%v%n%n%c" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "CONTRIBUTING.md", "Changes", "INSTALL", "LICENSE", "META.json", "Makefile.PL", "README.pod", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.20.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Author::DBOOK/Git::Commit", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "1.000", "tag_format" : "%v", "tag_message" : "%v" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.20.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Author::DBOOK/Git::Tag", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::BumpVersionAfterRelease", "config" : { "Dist::Zilla::Plugin::BumpVersionAfterRelease" : { "finders" : [ ":ExecFiles", ":InstallModules" ], "global" : 0, "munge_makefile_pl" : 0 } }, "name" : "@Author::DBOOK/BumpVersionAfterRelease", "version" : "0.018" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "Bump version" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [ "(?^:^)" ], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.20.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Author::DBOOK/Commit_Version_Bump", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin" ], "remotes_must_exist" : 1 }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.20.1", "repo_root" : "." } }, "name" : "@Author::DBOOK/Git::Push", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@Author::DBOOK/PodSyntaxTests", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::Test::ReportPrereqs", "name" : "@Author::DBOOK/Test::ReportPrereqs", "version" : "0.027" }, { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [ "Build.PL", "CONTRIBUTING.md", "INSTALL", "LICENSE", "META.json", "Makefile.PL", "Makefile.PL" ], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." }, "Dist::Zilla::Plugin::Git::GatherDir" : { "include_untracked" : 0 } }, "name" : "@Author::DBOOK/Git::GatherDir", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::Regenerate::AfterReleasers", "config" : { "Dist::Zilla::Plugin::Regenerate::AfterReleasers" : { "plugins" : [ "@Author::DBOOK/Readme_Github", "@Author::DBOOK/CopyFilesFromRelease" ] }, "Dist::Zilla::Role::Regenerator" : { "$Dist::Zilla::Role::Regenerator::VERSION" : "0.001001" } }, "name" : "@Author::DBOOK/Regenerate::AfterReleasers", "version" : "0.001001" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Author::DBOOK/PruneCruft", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Author::DBOOK/ManifestSkip", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Author::DBOOK/MetaYAML", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@Author::DBOOK/MetaJSON", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Author::DBOOK/License", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "@Author::DBOOK/ReadmeAnyFromPod", "version" : "0.163250" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::DBOOK/ExecDir", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Author::DBOOK/ShareDir", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::DBOOK/ScriptDir", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Author::DBOOK/MakeMaker", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::RunExtraTests", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Author::DBOOK/RunExtraTests", "version" : "0.029" }, { "class" : "Dist::Zilla::Plugin::InstallGuide", "name" : "@Author::DBOOK/InstallGuide", "version" : "1.200012" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Author::DBOOK/Manifest", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@Author::DBOOK/TestRelease", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Author::DBOOK/ConfirmRelease", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Author::DBOOK/UploadToCPAN", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.012" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.012" } }, "x_contributors" : [ "Dan Book " ], "x_generated_by_perl" : "v5.28.1", "x_serialization_backend" : "Cpanel::JSON::XS version 4.09" } Makefile.PL100644001750001750 244313444010620 16122 0ustar00grinnzgrinnz000000000000lib-relative-1.000# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.012. use strict; use warnings; use 5.006001; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Add paths relative to the current file to \@INC", "AUTHOR" => "Dan Book ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "lib-relative", "LICENSE" => "artistic_2", "MIN_PERL_VERSION" => "5.006001", "NAME" => "lib::relative", "PREREQ_PM" => { "Cwd" => 0, "File::Basename" => 0, "File::Spec" => 0, "lib" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "File::Temp" => "0.19", "Test::More" => "0.88" }, "VERSION" => "1.000", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Cwd" => 0, "ExtUtils::MakeMaker" => 0, "File::Basename" => 0, "File::Spec" => 0, "File::Temp" => "0.19", "Test::More" => "0.88", "lib" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); CONTRIBUTING.md100644001750001750 1051613444010620 16421 0ustar00grinnzgrinnz000000000000lib-relative-1.000# HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla). This means that many of the usual files you might expect are not in the repository, but are generated at release time. Some generated files are kept in the repository as a convenience (e.g. Build.PL/Makefile.PL and META.json). Generally, **you do not need Dist::Zilla to contribute patches**. You may need Dist::Zilla to create a tarball. See below for guidance. ## Getting dependencies If you have App::cpanminus 1.6 or later installed, you can use [cpanm](https://metacpan.org/pod/cpanm) to satisfy dependencies like this: $ cpanm --installdeps --with-develop . You can also run this command (or any other cpanm command) without installing App::cpanminus first, using the fatpacked `cpanm` script via curl or wget: $ curl -L https://cpanmin.us | perl - --installdeps --with-develop . $ wget -qO - https://cpanmin.us | perl - --installdeps --with-develop . Otherwise, look for either a `cpanfile` or `META.json` file for a list of dependencies to satisfy. ## Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most of my distributions, `prove` is entirely sufficient for you to test any patches you have. I use `prove` for 99% of my testing during development. ## Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. ## Installing and using Dist::Zilla [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla) is a very powerful authoring tool, optimized for maintaining a large number of distributions with a high degree of automation, but it has a large dependency chain, a bit of a learning curve and requires a number of author-specific plugins. To install it from CPAN, I recommend one of the following approaches for the quickest installation: # using CPAN.pm, but bypassing non-functional pod tests $ cpan TAP::Harness::Restricted $ PERL_MM_USE_DEFAULT=1 HARNESS_CLASS=TAP::Harness::Restricted cpan Dist::Zilla # using cpanm, bypassing *all* tests $ cpanm -n Dist::Zilla In either case, it's probably going to take about 10 minutes. Go for a walk, go get a cup of your favorite beverage, take a bathroom break, or whatever. When you get back, Dist::Zilla should be ready for you. Then you need to install any plugins specific to this distribution: $ dzil authordeps --missing | cpanm You can use Dist::Zilla to install the distribution's dependencies if you haven't already installed them with cpanm: $ dzil listdeps --missing --develop | cpanm You can instead combine these two steps into one command by installing Dist::Zilla::App::Command::installdeps then running: $ dzil installdeps Once everything is installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil regenerate You can learn more about Dist::Zilla at http://dzil.org/ ## Other notes This distribution maintains the generated `META.json` and either `Makefile.PL` or `Build.PL` in the repository. This allows two things: [Travis CI](https://travis-ci.org/) can build and test the distribution without requiring Dist::Zilla, and the distribution can be installed directly from Github or a local git repository using `cpanm` for testing (again, not requiring Dist::Zilla). $ cpanm git://github.com/Author/Distribution-Name.git $ cd Distribution-Name; cpanm . Contributions are preferred in the form of a Github pull request. See [Using pull requests](https://help.github.com/articles/using-pull-requests/) for further information. You can use the Github issue tracker to report issues without an accompanying patch. # CREDITS This file was adapted from an initial `CONTRIBUTING.mkdn` file from David Golden under the terms of the [CC0](https://creativecommons.org/share-your-work/public-domain/cc0/), with inspiration from the contributing documents from [Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING](https://metacpan.org/pod/Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING) and [Dist::Zilla::PluginBundle::Author::ETHER](https://metacpan.org/pod/Dist::Zilla::PluginBundle::Author::ETHER). t000755001750001750 013444010620 14250 5ustar00grinnzgrinnz000000000000lib-relative-1.000lib_relative.t100644001750001750 335713444010620 17246 0ustar00grinnzgrinnz000000000000lib-relative-1.000/tuse strict; use warnings; use Test::More; use Cwd (); use File::Basename (); use File::Spec (); use File::Temp (); use lib::relative (); # Relative path absolutized { local @INC = @INC; lib::relative->import('testlib'); ok((grep { m!\btestlib\b! and File::Spec->file_name_is_absolute($_) } @INC), 'absolute path to testlib in @INC'); ok((eval { require MyTestModule; 1 }), 'loaded MyTestModule from testlib') or diag $@; is MyTestModule::foo(), 'bar', 'correct function results'; } # Absolute path passed through { local @INC = @INC; my $path = File::Spec->catdir(File::Basename::dirname(Cwd::abs_path __FILE__), 'testlib'); lib::relative->import($path); ok((grep { $_ eq $path } @INC), 'absolute path to testlib in @INC'); ok((eval { require MyTestModule2; 1 }), 'loaded MyTestModule2 from testlib') or diag $@; is MyTestModule2::foo(), 'baz', 'correct function results'; } # Symlinked __FILE__ SKIP: { local @INC = @INC; my $dir = File::Temp->newdir; skip 4, 'tempdir in @INC' if grep { m!^\Q$dir\E! } @INC; my $path = File::Spec->catfile(File::Basename::dirname(Cwd::abs_path __FILE__), 'testlib', 'load_relative.pl'); my $link = File::Spec->catfile($dir, 'load_relative.pl'); my $rc; eval { $rc = symlink $path, $link; 1 } or skip 4, 'symlinks not supported'; die "symlink failed: $!" unless $rc; do $link or die "failed to run $path: $!"; ok((grep { m!\btestlib\b! and File::Spec->file_name_is_absolute($_) } @INC), 'absolute path to testlib in @INC'); ok(!(grep { m!^\Q$dir\E! } @INC), 'tempdir not in @INC'); ok((eval { require MyTestModule3; 1 }), 'loaded MyTestModule3 from testlib') or diag $@; is MyTestModule3::foo(), 'buzz', 'correct function results'; } done_testing; lib000755001750001750 013444010620 15321 5ustar00grinnzgrinnz000000000000lib-relative-1.000/librelative.pm100644001750001750 615613444010620 17642 0ustar00grinnzgrinnz000000000000lib-relative-1.000/lib/libpackage lib::relative; use strict; use warnings; use Cwd (); use File::Basename (); use File::Spec (); use lib (); our $VERSION = '1.000'; sub import { my ($class, @paths) = @_; my $file = (caller)[1]; my $dir = -e $file ? File::Basename::dirname(Cwd::abs_path $file) : Cwd::getcwd; lib->import(map { File::Spec->file_name_is_absolute($_) ? $_ : File::Spec->catdir($dir, $_) } @paths); } 1; =head1 NAME lib::relative - Add paths relative to the current file to @INC =head1 SYNOPSIS # Path is relative to this file, not current working directory use lib::relative 'path/to/lib'; use lib::relative '../../lib'; # Add two lib paths, as in lib.pm use lib::relative 'foo', 'bar'; # Absolute paths are passed through unchanged use lib::relative 'foo/baz', '/path/to/lib'; # Equivalent code using core modules use Cwd (); use File::Basename (); use File::Spec (); use lib File::Spec->catdir(File::Basename::dirname(Cwd::abs_path __FILE__), 'path/to/lib'); =head1 DESCRIPTION Adding a path to L<@INC|perlvar/"@INC"> to load modules from a local directory may seem simple, but has a few common pitfalls to be aware of. Directly adding a relative path to C<@INC> means that any later code that changes the current working directory will change where modules are loaded from. This applies to the C<.> path that used to be in C<@INC> by default until perl 5.26.0, or a relative path added in code like C, and may be a vulnerability if such a location is not supposed to be writable. Additionally, the commonly used L module relies on interpreter state and the path to the original script invoked by the perl interpreter, sometimes requiring workarounds in uncommon cases like generated or embedded code. This module proposes a more straightforward method: take a path relative to the L, absolutize it, and add it to C<@INC>. If this module is already available to be loaded, it can be used as with L.pm, passing relative paths, which will be absolutized relative to the current file then passed on to L. Multiple arguments will be separately absolutized, and absolute paths will be passed on unchanged. For cases where this module cannot be loaded beforehand, the last section of the L can be copy-pasted into a file to perform the same task. =head1 CAVEATS Due to C<__FILE__> possibly being a path relative to the current working directory, be sure to use C or the equivalent code from L as early as possible in the file. If a C occurs before this code, it will add the incorrect directory path. All file paths are expected to be in a format appropriate to the current operating system, e.g. C<..\\foo\\bar> on Windows. L can be used to form directory paths portably. =head1 BUGS Report any issues on the public bugtracker. =head1 AUTHOR Dan Book =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2017 by Dan Book. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) =head1 SEE ALSO L, L, L 00-report-prereqs.t100644001750001750 1342613444010620 20032 0ustar00grinnzgrinnz000000000000lib-relative-1.000/t#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.027 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: author000755001750001750 013444010620 15742 5ustar00grinnzgrinnz000000000000lib-relative-1.000/xtpod-syntax.t100644001750001750 25213444010620 20354 0ustar00grinnzgrinnz000000000000lib-relative-1.000/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); 00-report-prereqs.dd100644001750001750 242513444010620 20133 0ustar00grinnzgrinnz000000000000lib-relative-1.000/tdo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0' } }, 'develop' => { 'requires' => { 'Test::Pod' => '1.41' } }, 'runtime' => { 'requires' => { 'Cwd' => '0', 'File::Basename' => '0', 'File::Spec' => '0', 'lib' => '0', 'perl' => '5.006001' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'File::Temp' => '0.19', 'Test::More' => '0.88' } } }; $x; }testlib000755001750001750 013444010620 15716 5ustar00grinnzgrinnz000000000000lib-relative-1.000/tMyTestModule.pm100644001750001750 11013444010620 20757 0ustar00grinnzgrinnz000000000000lib-relative-1.000/t/testlibpackage MyTestModule; use strict; use warnings; sub foo { 'bar' } 1; MyTestModule2.pm100644001750001750 11113444010620 21042 0ustar00grinnzgrinnz000000000000lib-relative-1.000/t/testlibpackage MyTestModule2; use strict; use warnings; sub foo { 'baz' } 1; MyTestModule3.pm100644001750001750 11113444010620 21043 0ustar00grinnzgrinnz000000000000lib-relative-1.000/t/testlibpackage MyTestModule3; use strict; use warnings; sub foo { 'buzz' } 1; load_relative.pl100644001750001750 6413444010620 21165 0ustar00grinnzgrinnz000000000000lib-relative-1.000/t/testlibuse strict; use warnings; use lib::relative '.'; 1;