How to parse cpanfile? Module::CPANfile makes it possible.
use Module::CPANfile;
my $file = Module::CPANfile->load("cpanfile");
my $prereqs = $file->prereqs; # CPAN::Meta::Prereqs object
my @features = $file->features; # CPAN::Meta::Feature objects
my $merged_prereqs = $file->prereqs_with(@identifiers); # CPAN::Meta::Prereqs
$file->merge_meta('MYMETA.json');
Top comments (5)
If all you want to do is process data from your own cpanfile then a useful simple option might be to just
do
orrequire
it. All you need to do is define a few subs likerequires
andrecommends
first, which will be called a bunch of times by the cpanfile and given the dependency data. So the subs should collect it somewhere, and then you can do something with it afterwards.If you do this you are running the cpanfile as code so you need to be able to trust it, obviously.
And you donβt want to use this as a general parsing approach because the full set of subs you need to define (all the
configure_requires
,configure_recommends
,build_requires
,build_recommends
, etc variations) is probably excessive.But if all you are doing is processing your own cpanfile then trust is not an issue and you almost certainly only use a few of the keywords, so this is a nice option.
This seems to be good way. I didn't know cpanfile is pure Perl codes until now.
Thank you for information.
Yes.
You could add
perl
after the triple back-tick to have color highlighting:Gabor
Thanks. I haven't known this.
I will try this syntax.