Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mymeta-cpanfile should convert optional features #55

Open
CyberShadow opened this issue Dec 11, 2021 · 0 comments
Open

mymeta-cpanfile should convert optional features #55

CyberShadow opened this issue Dec 11, 2021 · 0 comments

Comments

@CyberShadow
Copy link

If MYMETA.yml / .json have an optional_features section, it should probably be also converted and saved in the produced cpanfile.

I wrote the following hacky code which seems to work so far:

my $meta = CPAN::Meta->load_file('MYMETA.json');
my $file = Module::CPANfile->from_prereqs($meta->prereqs);

for my $feature ($meta->features) {
  $file->{_prereqs}->add_feature($feature->identifier, $feature->description);
  my $prereqs = [];
  while (my ($phase, $types) = each %{$feature->{prereqs}->{prereqs}}) {
    while (my ($type, $requirements) = each %$types) {
      my $req_spec = $requirements->as_string_hash;
      while (my ($module, $version) = each %{$req_spec}) {
        push @{$prereqs},
            Module::CPANfile::Prereq->new(
              feature => $feature->identifier,
              phase   => $phase,
              type    => $type,
              module  => $module,
              requirement => Module::CPANfile::Requirement->new(
                name    => $module,
                version => $version,
              ),
            );
      }
    }
  }
  $file->{_prereqs}->{prereqs}{$feature->identifier} = $prereqs;
}

$file->save('cpanfile');

Related: #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant