1Module::CPANfile(3)   User Contributed Perl Documentation  Module::CPANfile(3)
2
3
4

NAME

6       Module::CPANfile - Parse cpanfile
7

SYNOPSIS

9         use Module::CPANfile;
10
11         my $file = Module::CPANfile->load("cpanfile");
12         my $prereqs = $file->prereqs; # CPAN::Meta::Prereqs object
13
14         my @features = $file->features; # CPAN::Meta::Feature objects
15         my $merged_prereqs = $file->prereqs_with(@identifiers); # CPAN::Meta::Prereqs
16
17         $file->merge_meta('MYMETA.json');
18

DESCRIPTION

20       Module::CPANfile is a tool to handle cpanfile format to load
21       application specific dependencies, not just for CPAN distributions.
22

METHODS

24       load
25             $file = Module::CPANfile->load;
26             $file = Module::CPANfile->load('cpanfile');
27
28           Load and parse a cpanfile. By default it tries to load "cpanfile"
29           in the current directory, unless you pass the path to its argument.
30
31       from_prereqs
32             $file = Module::CPANfile->from_prereqs({
33               runtime => { requires => { DBI => '1.000' } },
34             });
35
36           Creates a new Module::CPANfile object from prereqs hash you can get
37           via CPAN::Meta's "prereqs", or CPAN::Meta::Prereqs'
38           "as_string_hash".
39
40             # read MYMETA, then feed the prereqs to create Module::CPANfile
41             my $meta = CPAN::Meta->load_file('MYMETA.json');
42             my $file = Module::CPANfile->from_prereqs($meta->prereqs);
43
44             # load cpanfile, then recreate it with round-trip
45             my $file = Module::CPANfile->load('cpanfile');
46             $file = Module::CPANfile->from_prereqs($file->prereq_specs);
47                                               # or $file->prereqs->as_string_hash
48
49       prereqs
50           Returns CPAN::Meta::Prereqs object out of the parsed cpanfile.
51
52       prereq_specs
53           Returns a hash reference that should be passed to
54           "CPAN::Meta::Prereqs->new".
55
56       features
57           Returns a list of features available in the cpanfile as
58           CPAN::Meta::Feature.
59
60       prereqs_with(@identifiers), effective_prereqs(\@identifiers)
61           Returns CPAN::Meta::Prereqs object, with merged prereqs for
62           features identified with the @identifiers.
63
64       to_string($include_empty)
65             $file->to_string;
66             $file->to_string(1);
67
68           Returns a canonical string (code) representation for cpanfile.
69           Useful if you want to convert CPAN::Meta::Prereqs to a new
70           cpanfile.
71
72             # read MYMETA's prereqs and print cpanfile representation of it
73             my $meta = CPAN::Meta->load_file('MYMETA.json');
74             my $file = Module::CPANfile->from_prereqs($meta->prereqs);
75             print $file->to_string;
76
77           By default, it omits the phase where there're no modules
78           registered. If you pass the argument of a true value, it will print
79           them as well.
80
81       save
82             $file->save('cpanfile');
83
84           Saves the currently loaded prereqs as a new "cpanfile" by calling
85           "to_string". Beware this method will overwrite the existing
86           cpanfile without any warning or backup. Taking a backup or giving
87           warnings to users is a caller's responsibility.
88
89             # Read MYMETA.json and creates a new cpanfile
90             my $meta = CPAN::Meta->load_file('MYMETA.json');
91             my $file = Module::CPANfile->from_prereqs($meta->prereqs);
92             $file->save('cpanfile');
93
94       merge_meta
95             $file->merge_meta('META.yml');
96             $file->merge_meta('MYMETA.json', '2.0');
97
98           Merge the effective prereqs with Meta specification loaded from the
99           given META file, using CPAN::Meta. You can specify the META spec
100           version in the second argument, which defaults to 1.4 in case the
101           given file is YAML, and 2 if it is JSON.
102
103       options_for_module
104             my $options = $file->options_for_module($module);
105
106           Returns the extra options specified for a given module as a hash
107           reference. Returns "undef" when the given module is not specified
108           in the "cpanfile".
109
110           For example,
111
112             # cpanfile
113             requires 'Plack', '1.000',
114               dist => "MIYAGAWA/Plack-1.000.tar.gz";
115
116             # ...
117             my $file = Module::CPANfile->load;
118             my $options = $file->options_for_module('Plack');
119             # => { dist => "MIYAGAWA/Plack-1.000.tar.gz" }
120

AUTHOR

122       Tatsuhiko Miyagawa
123

SEE ALSO

125       cpanfile, CPAN::Meta, CPAN::Meta::Spec
126
127
128
129perl v5.28.0                      2018-04-26               Module::CPANfile(3)
Impressum