Perl module - dist.ini and platform requirements

How to add conditional prereqs to dist.ini for each platform (Windows / Non windows) I want the module to support?

For example, in Perl code, which I could do:

 if ( $^0 eq 'MSWin32' ){ require Win32::Foo; }else{ require Bar::Baz; } 

How can I serve every system / platform like this in dist.ini so that the corresponding prereqs are installed via cpan / cpanm?

+6
source share
2 answers

You cannot do this in dist.ini , since the ini file has no way to make conditional logic. But one way could be to create your own Dist :: Zilla plugin, something like this:

 package Dist::Zilla::Plugin::MyPrereqs; # pick a better name use Moose; with 'Dist::Zilla::Role::PrereqSource'; sub register_prereqs { my $self = shift; my %prereqs; if ( $^0 eq 'MSWin32' ) { $prereqs{'Win32::Foo'} = '0.12'; # min. version } else { $prereqs{'Bar::Baz'} = '1.43'; } $self->zilla->register_prereqs( %prereqs ); } 

If you generalize this to take some platform-specific prereqs lists within dist.ini , this will make a good CPAN release.

+4
source

Use Dist :: Zilla :: Plugin :: OSPrereqs . For your example, it will look like this:

 [OSPrereqs / MSWin32] Win32::Foo = 0.12 [OSPrereqs / !MSWin32] Bar::Baz = 1.43 
+3
source

Source: https://habr.com/ru/post/971128/


All Articles