How to populate 'provides' field in META files using ExtUtils::MakeMaker

104 Views Asked by At

One of my modules is failing the CPANTS policy meta_yml_has_provides

The documentation states:

Add all modules contained in this distribution to the META.yml field 'provides'. Module::Build or Dist::Zilla::Plugin::MetaProvides do this automatically for you.

How can I to apply this to my CPAN module while using ExtUtils::MakeMaker?

2

There are 2 best solutions below

1
Leon Timmermans On BEST ANSWER

You could do something like this:

use ExtUtils::MakeMaker;
use Module::Metadata;
WriteMakefile(
    ...
    META_ADD => {
        provides => Module::Metadata->provides(version => '1.4', dir => 'lib'),
    },
    ...
);

But then your end users also need to depend on Module::Metadata. You may want to add some author only logic to that for production use. YMMV.

I'm not sure it's really worth it in that regard. Possibly MakeMaker should have built-in support for this instead.

0
roland kapl On

as ExtUtils::MakeMaker still doesn't provide this automatically and you need a MakeMaker solution: You can also add a "provides" sub-hash to your META_MERGE information in Makefile.PL as follows:

    META_MERGE => {
        "meta-spec" => { version => 2 },
        provides => {
            'Your::Module1' => {file => 'lib/Your/Module1.pm', version => x.y},
            'Your::Module2' => {file => 'lib/Your/Module2.pm', version => x.y},
        },

the version tag is optional, if that is too tedious to maintain.