File Coverage

blib/lib/Dist/Zilla/Plugin/MetaYAML.pm
Criterion Covered Total %
statement 32 36 88.8
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 39 45 86.6


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::MetaYAML 6.037;
2             # ABSTRACT: produce a META.yml
3              
4 11     11   8827 use Moose;
  11         28  
  11         103  
5             with 'Dist::Zilla::Role::FileGatherer';
6              
7 11     11   77609 use Dist::Zilla::Pragmas;
  11         22  
  11         99  
8              
9 11     11   87 use Try::Tiny;
  11         25  
  11         1024  
10 11     11   96 use namespace::autoclean;
  11         24  
  11         121  
11              
12             #pod =head1 DESCRIPTION
13             #pod
14             #pod This plugin will add a F<META.yml> file to the distribution.
15             #pod
16             #pod For more information on this file, see L<Module::Build::API> and L<CPAN::Meta>.
17             #pod
18             #pod =attr filename
19             #pod
20             #pod If given, parameter allows you to specify an alternate name for the generated
21             #pod file. It defaults, of course, to F<META.yml>.
22             #pod
23             #pod =cut
24              
25             has filename => (
26             is => 'ro',
27             isa => 'Str',
28             default => 'META.yml',
29             );
30              
31             sub gather_files {
32 11     11 0 43 my ($self, $arg) = @_;
33              
34 11         541 require Dist::Zilla::File::FromCode;
35 11         70 require YAML::Tiny;
36 11         49 require CPAN::Meta::Converter;
37 11         327 CPAN::Meta::Converter->VERSION(2.101550); # improved downconversion
38 11         80 require CPAN::Meta::Validator;
39 11         189 CPAN::Meta::Validator->VERSION(2.101550); # improved downconversion
40              
41 11         475 my $zilla = $self->zilla;
42              
43             my $file = Dist::Zilla::File::FromCode->new({
44             name => $self->filename,
45             code_return_type => 'text',
46             code => sub {
47 11     11   389 my $distmeta = $zilla->distmeta;
48              
49 11         149 my $validator = CPAN::Meta::Validator->new($distmeta);
50              
51 11 50       227 unless ($validator->is_valid) {
52 0         0 my $msg = "Invalid META structure. Errors found:\n";
53 0         0 $msg .= join( "\n", $validator->errors );
54 0         0 $self->log_fatal($msg);
55             }
56              
57 11         7542 my $converter = CPAN::Meta::Converter->new($distmeta);
58 11         579 my $output = $converter->convert(version => '1.4');
59 11         17829 $output->{x_serialization_backend} = sprintf '%s version %s',
60             'YAML::Tiny', YAML::Tiny->VERSION;
61              
62             my $yaml = try {
63 11         742 YAML::Tiny->new($output)->write_string; # text!
64             }
65             catch {
66 0         0 $self->log_fatal("Could not create YAML string: " . YAML::Tiny->errstr)
67 11         156 };
68 11         16191 return $yaml;
69             },
70 11         374 });
71              
72 11         78 $self->add_file($file);
73 11         91 return;
74             }
75              
76             __PACKAGE__->meta->make_immutable;
77             1;
78              
79             #pod =head1 SEE ALSO
80             #pod
81             #pod Core Dist::Zilla plugins:
82             #pod L<@Basic|Dist::Zilla::PluginBundle::Basic>,
83             #pod L<Manifest|Dist::Zilla::Plugin::Manifest>.
84             #pod
85             #pod Dist::Zilla roles:
86             #pod L<FileGatherer|Dist::Zilla::Role::FileGatherer>.
87             #pod
88             #pod Other modules:
89             #pod L<CPAN::Meta>,
90             #pod L<CPAN::Meta::Spec>, L<YAML>.
91             #pod
92             #pod =cut
93              
94             __END__
95              
96             =pod
97              
98             =encoding UTF-8
99              
100             =head1 NAME
101              
102             Dist::Zilla::Plugin::MetaYAML - produce a META.yml
103              
104             =head1 VERSION
105              
106             version 6.037
107              
108             =head1 DESCRIPTION
109              
110             This plugin will add a F<META.yml> file to the distribution.
111              
112             For more information on this file, see L<Module::Build::API> and L<CPAN::Meta>.
113              
114             =head1 PERL VERSION
115              
116             This module should work on any version of perl still receiving updates from
117             the Perl 5 Porters. This means it should work on any version of perl
118             released in the last two to three years. (That is, if the most recently
119             released version is v5.40, then this module should work on both v5.40 and
120             v5.38.)
121              
122             Although it may work on older versions of perl, no guarantee is made that the
123             minimum required version will not be increased. The version may be increased
124             for any reason, and there is no promise that patches will be accepted to
125             lower the minimum required perl.
126              
127             =head1 ATTRIBUTES
128              
129             =head2 filename
130              
131             If given, parameter allows you to specify an alternate name for the generated
132             file. It defaults, of course, to F<META.yml>.
133              
134             =head1 SEE ALSO
135              
136             Core Dist::Zilla plugins:
137             L<@Basic|Dist::Zilla::PluginBundle::Basic>,
138             L<Manifest|Dist::Zilla::Plugin::Manifest>.
139              
140             Dist::Zilla roles:
141             L<FileGatherer|Dist::Zilla::Role::FileGatherer>.
142              
143             Other modules:
144             L<CPAN::Meta>,
145             L<CPAN::Meta::Spec>, L<YAML>.
146              
147             =head1 AUTHOR
148              
149             Ricardo SIGNES 😏 <cpan@semiotic.systems>
150              
151             =head1 COPYRIGHT AND LICENSE
152              
153             This software is copyright (c) 2026 by Ricardo SIGNES.
154              
155             This is free software; you can redistribute it and/or modify it under
156             the same terms as the Perl 5 programming language system itself.
157              
158             =cut