Skip to content

Commit

Permalink
Implement dynamic prerequisites
Browse files Browse the repository at this point in the history
  • Loading branch information
Leont committed Apr 25, 2024
1 parent a8704bf commit 38d9fd9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ check_dual_life_versions = 0
skip = ExtUtils::Config
skip = ExtUtils::Helpers
skip = ExtUtils::InstallPaths
skip = CPAN::Requirements::Dynamic
13 changes: 11 additions & 2 deletions lib/Module/Build/Tiny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ sub Build_PL {
make_executable('Build');
my @env = defined $ENV{PERL_MB_OPT} ? split_like_shell($ENV{PERL_MB_OPT}) : ();
write_file('_build_params', encode_json([ \@env, \@ARGV ]));
if (-e 'dynamic-prereqs.json') {
my %meta = (%{ $meta->as_struct }, dynamic_config => 0);
my %opt = get_arguments(\@env, \@ARGV);
require CPAN::Requirements::Dynamic;
my $dynamic_parser = CPAN::Requirements::Dynamic->new(%opt);
my $prereq = $dynamic_parser->evaluate_file('dynamic-prereqs.json');
$meta{prereqs} = $meta->effective_prereqs->with_merged_prereqs($prereq)->as_string_hash;
$meta = CPAN::Meta->new(\%meta);
}
$meta->save(@$_) for ['MYMETA.json'], [ 'MYMETA.yml' => { version => 1.4 } ];
}

Expand Down Expand Up @@ -228,14 +237,14 @@ than 200, yet supports the features needed by most distributions.
=item * Module sharedirs
=item * Dynamic prerequisites
=back
=head2 Not Supported
=over 4
=item * Dynamic prerequisites
=item * HTML documentation generation
=item * Extending Module::Build::Tiny
Expand Down
14 changes: 14 additions & 0 deletions t/simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ if ($has_compiler) {
---
}

$dist->add_file('dynamic-prereqs.json', undent(<<" ---"));
{
"version": 1,
"expressions": [ { "condition": [ "has_perl", "$]"], "prereqs": { "Bar": 1 } } ]
}
---

$dist->regen;

my $interpreter = ($Config{startperl} eq $^X )
Expand Down Expand Up @@ -136,6 +143,13 @@ sub _slurp { do { local (@ARGV,$/)=$_[0]; <> } }
ok( -d catdir(qw/blib lib auto share module Foo-Bar/), 'moduole sharedir has been made');
ok( -f catfile(qw/blib lib auto share module Foo-Bar file.txt/), 'module sharedir file has been made');

require CPAN::Meta;
my $meta = CPAN::Meta->load_file("MYMETA.json");
my $req = $meta->effective_prereqs->requirements_for('runtime', 'requires');
my $dynamic_dependency = join ',', sort $req->required_modules;

is($dynamic_dependency, 'Bar,perl', 'Dependency on Foo has been inserted');

if ($has_compiler) {
XSLoader::load('Foo::Bar');
is(Foo::Bar::foo(), "Hello World!\n", 'Can run XSub Foo::Bar::foo');
Expand Down

0 comments on commit 38d9fd9

Please sign in to comment.