File Coverage

blib/lib/Dist/Zilla/Plugin/MetaYAML/Minimal.pm
Criterion Covered Total %
statement 20 46 43.4
branch 0 4 0.0
condition n/a
subroutine 7 9 77.7
pod 0 1 0.0
total 27 60 45.0


line stmt bran cond sub pod time code
1 1     1   496 use 5.006; # our
  1         2  
2 1     1   4 use strict;
  1         1  
  1         21  
3 1     1   11 use warnings;
  1         1  
  1         81  
4              
5             package Dist::Zilla::Plugin::MetaYAML::Minimal;
6              
7             our $VERSION = '0.001001';
8              
9             # ABSTRACT: Generate a reductionist YAML META file for compatibility only
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 1     1   569 use Moose qw( has with around );
  1         318270  
  1         7  
14 1     1   4615 use Try::Tiny qw( try catch );
  1         3  
  1         84  
15 1     1   738 use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
  1         1064  
  1         6  
16              
17             with 'Dist::Zilla::Role::FileGatherer';
18              
19             has filename => (
20             is => 'ro',
21             isa => 'Str',
22             default => 'META.yml',
23             );
24              
25             has version => (
26             is => 'ro',
27             isa => 'Num',
28             default => '1.4',
29             );
30              
31             around dump_config => config_dumper( __PACKAGE__, qw( filename version ) );
32              
33             __PACKAGE__->meta->make_immutable;
34 1     1   118 no Moose;
  1         2  
  1         7  
35              
36              
37              
38              
39              
40             sub gather_files {
41 0     0 0   my ($self,) = @_;
42              
43 0           require Dist::Zilla::File::FromCode;
44 0           require YAML::Tiny;
45 0           require CPAN::Meta::Converter;
46 0           CPAN::Meta::Converter->VERSION(2.101550); # improved downconversion
47 0           require CPAN::Meta::Validator;
48 0           CPAN::Meta::Validator->VERSION(2.101550); # improved downconversion
49              
50 0           my $zilla = $self->zilla;
51              
52             my $file = Dist::Zilla::File::FromCode->new({
53             name => $self->filename,
54             code_return_type => 'text',
55             code => sub {
56 0     0     my $distmeta = $zilla->distmeta;
57              
58 0           my $validator = CPAN::Meta::Validator->new($distmeta);
59              
60 0 0         if ( not $validator->is_valid ) {
61 0           my $msg = "Invalid META structure. Errors found:\n";
62 0           $msg .= join "\n", $validator->errors;
63 0           $self->log_fatal($msg);
64             }
65              
66 0           my $converter = CPAN::Meta::Converter->new($distmeta);
67 0           my $output = $converter->convert( version => $self->version );
68              
69 0           for my $key ( keys %{$output} ) {
  0            
70 0 0         delete $output->{$key} if $key =~ /\Ax_/sx;
71             }
72              
73             my $yaml = try {
74 0           YAML::Tiny->new($output)->write_string; # text!
75             }
76             catch {
77 0           $self->log_fatal('Could not create YAML string: ' . YAML::Tiny->errstr);
78 0           };
79 0           return $yaml;
80             },
81 0           });
82              
83 0           $self->add_file($file);
84 0           return;
85             }
86              
87             1;
88              
89             __END__
90              
91             =pod
92              
93             =encoding UTF-8
94              
95             =head1 NAME
96              
97             Dist::Zilla::Plugin::MetaYAML::Minimal - Generate a reductionist YAML META file for compatibility only
98              
99             =head1 VERSION
100              
101             version 0.001001
102              
103             =head1 SYNOPSIS
104              
105             [MetaYAML::Minimal]
106             filename = META.yml ; default
107             version = 1.4 ; default
108              
109             =head1 DESCRIPTION
110              
111             Generally, if you're creating both C<META.json> and C<META.yml>, then you're doing so purely for compatibility reasons.
112              
113             In such circumstances, using the same meta-data for both leads to a lot of cruft in C<META.yml>
114              
115             This L<C<Dist::Zilla>|Dist::Zilla> extension is for such circumstances.
116              
117             However, if you are I<only> shipping C<META.yml> and B<NOT> C<META.json>, then using this extension
118             would be harmful and cause loss of information.
119              
120             Presently, this extension is a I<PROTOTYPE>, and just culls fields leading with C<x_> passed by C<Dist::Zilla>.
121              
122             The final behavior may require enhancements to C<CPAN::Meta::Converter> and might be possibly superseded
123             by patches to C<MetaYAML> itself.
124              
125             =for Pod::Coverage gather_files
126              
127             =head1 AUTHOR
128              
129             Kent Fredric <kentnl@cpan.org>
130              
131             =head1 COPYRIGHT AND LICENSE
132              
133             This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
134              
135             This is free software; you can redistribute it and/or modify it under
136             the same terms as the Perl 5 programming language system itself.
137              
138             =cut