Home > Mobile >  Using Dist::Zilla dist.ini how can I have files that I only use for testing?
Using Dist::Zilla dist.ini how can I have files that I only use for testing?

Time:09-05

In a Dist::Zilla-based distribution I would like to have some files that are only used for testing, but do not get installed. These are mockup libs that aren't needed for runtime.

How do I do that?

CodePudding user response:

CPAN distributions never install the t and xt directories. You can put your tests and your mock libs into t.

As an example, take my module MooseX::LocalAttribute. In the dist, there is a t/, a t/lib and an xt/.

If you install this using cpanm -l into a local lib dir, you will see there are no tests installed. This happens automatically. It's just how CPAN works.

$ cpanm -l mylib MooseX::LocalAttribute
--> Working on MooseX::LocalAttribute
Fetching http://www.cpan.org/authors/id/S/SI/SIMBABQUE/MooseX-LocalAttribute-0.05.tar.gz ... OK
Configuring MooseX-LocalAttribute-0.05 ... OK
Building and testing MooseX-LocalAttribute-0.05 ... OK
Successfully installed MooseX-LocalAttribute-0.05
1 distribution installed

$ tree mylib
mylib
├── lib
│   └── perl5
│       ├── MooseX
│       │   └── LocalAttribute.pm
│       └── x86_64-linux
│           ├── auto
│           │   └── MooseX
│           │       └── LocalAttribute
│           └── perllocal.pod
└── man
    └── man3
        └── MooseX::LocalAttribute.3

9 directories, 3 files

Note that as long as stuff is in t/lib (or anywhere under t/, really), you do not have to hide the package names from the PAUSE indexer. It's smart enough to not find it.

CodePudding user response:

I misunderstood the question. This answer is for the following question:

How do I exclude files from a Dist::Zilla based distribution so they don't get shipped at all?

You are probably using either the GatherDir or Git::GatherDir plugin to build your bundle. Both of them have an option exclude_filename that you can set in your dist.ini to not include a file in a bundle.

A common pattern is to exclude auto-generated files such as LICENSE or META.json, and then add them later with another plugin. But you don't have to do that, you can just exclude files completely.

A good example is the URI distribution. On metacpan, it does not include any text files in the bundle. But if you look at the repository on github, you can see there are various .txt files such as rfc2396.txt. The dist.ini contains the following lines.

[Git::GatherDir]
exclude_filename = LICENSE
exclude_filename = README.md
exclude_filename = draft-duerst-iri-bis.txt
exclude_filename = rfc2396.txt
exclude_filename = rfc3986.txt
exclude_filename = rfc3987.txt

As mentioned before, the LICENSE and README.md files will still appear in the final bundle, because they get added later via @Git::VersionManager.

  • Related