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 1d40677 commit 1e4e571
Show file tree
Hide file tree
Showing 3 changed files with 23 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 (my $dynamic = $meta->custom('x_dynamic_prereqs')) {
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->parse($dynamic);
$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
11 changes: 11 additions & 0 deletions t/simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ if ($has_compiler) {
"meta-spec": {
"url": "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version": 2
},
"x_dynamic_prereqs": {
"version": 1,
"expressions": [ { "condition": [ "has_perl", "$]"] , "prereqs": { "runtime": { "requires": { "Bar": 1 } } } } ]
}
}
----
Expand Down Expand Up @@ -167,6 +171,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 1e4e571

Please sign in to comment.