• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/H26-Apr-2018-967599

script/H26-Apr-2018-24881

t/H26-Apr-2018-474381

ChangesH A D26-Apr-20184.4 KiB14198

LICENSEH A D26-Apr-201817.9 KiB380292

MANIFESTH A D26-Apr-2018519 2928

META.jsonH A D26-Apr-20182.4 KiB9189

META.ymlH A D26-Apr-20181.5 KiB5352

Makefile.PLH A D26-Apr-20181.2 KiB5745

READMEH A D26-Apr-20184.1 KiB13687

cpanfileH A D26-Apr-2018200 118

dist.iniH A D26-Apr-201855 53

README

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