.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.48) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "Module::CPANfile 3" .TH Module::CPANfile 3 2026-10-26 "perl v5.44.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Module::CPANfile \- Parse cpanfile .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& 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(\*(AqMYMETA.json\*(Aq); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Module::CPANfile is a tool to handle cpanfile format to load application specific dependencies, not just for CPAN distributions. .SH METHODS .IX Header "METHODS" .IP load 4 .IX Item "load" .Vb 2 \& $file = Module::CPANfile\->load; \& $file = Module::CPANfile\->load(\*(Aqcpanfile\*(Aq); .Ve .Sp Load and parse a cpanfile. By default it tries to load \f(CW\*(C`cpanfile\*(C'\fR in the current directory, unless you pass the path to its argument. .IP from_prereqs 4 .IX Item "from_prereqs" .Vb 3 \& $file = Module::CPANfile\->from_prereqs({ \& runtime => { requires => { DBI => \*(Aq1.000\*(Aq } }, \& }); .Ve .Sp Creates a new Module::CPANfile object from prereqs hash you can get via CPAN::Meta\*(Aqs \f(CW\*(C`prereqs\*(C'\fR, or CPAN::Meta::Prereqs\*(Aq \&\f(CW\*(C`as_string_hash\*(C'\fR. .Sp .Vb 3 \& # read MYMETA, then feed the prereqs to create Module::CPANfile \& my $meta = CPAN::Meta\->load_file(\*(AqMYMETA.json\*(Aq); \& my $file = Module::CPANfile\->from_prereqs($meta\->prereqs); \& \& # load cpanfile, then recreate it with round\-trip \& my $file = Module::CPANfile\->load(\*(Aqcpanfile\*(Aq); \& $file = Module::CPANfile\->from_prereqs($file\->prereq_specs); \& # or $file\->prereqs\->as_string_hash .Ve .IP prereqs 4 .IX Item "prereqs" Returns CPAN::Meta::Prereqs object out of the parsed cpanfile. .IP prereq_specs 4 .IX Item "prereq_specs" Returns a hash reference that should be passed to \f(CW\*(C`CPAN::Meta::Prereqs\->new\*(C'\fR. .IP features 4 .IX Item "features" Returns a list of features available in the cpanfile as CPAN::Meta::Feature. .IP "prereqs_with(@identifiers), effective_prereqs(\e@identifiers)" 4 .IX Item "prereqs_with(@identifiers), effective_prereqs(@identifiers)" Returns CPAN::Meta::Prereqs object, with merged prereqs for features identified with the \f(CW@identifiers\fR. .IP to_string($include_empty) 4 .IX Item "to_string($include_empty)" .Vb 2 \& $file\->to_string; \& $file\->to_string(1); .Ve .Sp Returns a canonical string (code) representation for cpanfile. Useful if you want to convert CPAN::Meta::Prereqs to a new cpanfile. .Sp .Vb 4 \& # read MYMETA\*(Aqs prereqs and print cpanfile representation of it \& my $meta = CPAN::Meta\->load_file(\*(AqMYMETA.json\*(Aq); \& my $file = Module::CPANfile\->from_prereqs($meta\->prereqs); \& print $file\->to_string; .Ve .Sp By default, it omits the phase where there\*(Aqre no modules registered. If you pass the argument of a true value, it will print them as well. .IP save 4 .IX Item "save" .Vb 1 \& $file\->save(\*(Aqcpanfile\*(Aq); .Ve .Sp Saves the currently loaded prereqs as a new \f(CW\*(C`cpanfile\*(C'\fR by calling \&\f(CW\*(C`to_string\*(C'\fR. Beware \fBthis method will overwrite the existing cpanfile without any warning or backup\fR. Taking a backup or giving warnings to users is a caller\*(Aqs responsibility. .Sp .Vb 4 \& # Read MYMETA.json and creates a new cpanfile \& my $meta = CPAN::Meta\->load_file(\*(AqMYMETA.json\*(Aq); \& my $file = Module::CPANfile\->from_prereqs($meta\->prereqs); \& $file\->save(\*(Aqcpanfile\*(Aq); .Ve .IP merge_meta 4 .IX Item "merge_meta" .Vb 2 \& $file\->merge_meta(\*(AqMETA.yml\*(Aq); \& $file\->merge_meta(\*(AqMYMETA.json\*(Aq, \*(Aq2.0\*(Aq); .Ve .Sp Merge the effective prereqs with Meta specification loaded from the given META file, using CPAN::Meta. You can specify the META spec version in the second argument, which defaults to 1.4 in case the given file is YAML, and 2 if it is JSON. .IP options_for_module 4 .IX Item "options_for_module" .Vb 1 \& my $options = $file\->options_for_module($module); .Ve .Sp Returns the extra options specified for a given module as a hash reference. Returns \f(CW\*(C`undef\*(C'\fR when the given module is not specified in the \f(CW\*(C`cpanfile\*(C'\fR. .Sp For example, .Sp .Vb 3 \& # cpanfile \& requires \*(AqPlack\*(Aq, \*(Aq1.000\*(Aq, \& dist => "MIYAGAWA/Plack\-1.000.tar.gz"; \& \& # ... \& my $file = Module::CPANfile\->load; \& my $options = $file\->options_for_module(\*(AqPlack\*(Aq); \& # => { dist => "MIYAGAWA/Plack\-1.000.tar.gz" } .Ve .SH AUTHOR .IX Header "AUTHOR" Tatsuhiko Miyagawa .SH "SEE ALSO" .IX Header "SEE ALSO" cpanfile, CPAN::Meta, CPAN::Meta::Spec