7

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

For example in perl code I could do:

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

How do I cater to each system/platform like this in dist.ini so that the proper prereqs are installed via cpan/cpanm?

G. Cito
  • 6,210
  • 3
  • 29
  • 42
Dr.Avalanche
  • 1,944
  • 2
  • 28
  • 37

2 Answers2

4

You can't do it in dist.ini, since an ini file doesn't really have any way to do conditional logic. But one way might be to write 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-dependent lists of prereqs within dist.ini, it would make a good CPAN release.

friedo
  • 65,762
  • 16
  • 114
  • 184
  • I'll check this out, I found [Dist::Zilla::Plugin::OSPrereqs](https://metacpan.org/pod/Dist::Zilla::Plugin::OSPrereqs), but I'd have to add in each OS, rather than just windows/non windows. I'll test this and get back to you. Thanks. – Dr.Avalanche Jun 21 '14 at 19:10
4

Use Dist::Zilla::Plugin::OSPrereqs. For your example it would look like:

[OSPrereqs / MSWin32]
Win32::Foo = 0.12

[OSPrereqs / !MSWin32]
Bar::Baz = 1.43
oalders
  • 5,239
  • 2
  • 23
  • 34
MichielB
  • 4,181
  • 1
  • 30
  • 39