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