Skip to content

mymeta-cpanfile should convert optional features #55

@CyberShadow

Description

@CyberShadow

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions