| 1 | package Dist::Zilla::Plugin::MetaYAML 6.040; | ||||||||||
| 2 | # ABSTRACT: produce a META.yml | ||||||||||
| 3 | |||||||||||
| 4 | 11 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 11 | with 'Dist::Zilla::Role::FileGatherer'; | |||||||||
| 6 | |||||||||||
| 7 | 11 | ▶ | use Dist::Zilla::Pragmas; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 11 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 11 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 11 | has filename => ( | |||||||||
| 26 | is => 'ro', | ||||||||||
| 27 | isa => 'Str', | ||||||||||
| 28 | default => 'META.yml', | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | 11 | ▶ | sub gather_files { | ||||||||
|
Subroutine
gather_files: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||
| 32 | 11 | my ($self, $arg) = @_; | |||||||||
| 33 | |||||||||||
| 34 | 11 | require Dist::Zilla::File::FromCode; | |||||||||
| 35 | 11 | require YAML::Tiny; | |||||||||
| 36 | 11 | require CPAN::Meta::Converter; | |||||||||
| 37 | 11 | CPAN::Meta::Converter->VERSION(2.101550); # improved downconversion | |||||||||
| 38 | 11 | require CPAN::Meta::Validator; | |||||||||
| 39 | 11 | CPAN::Meta::Validator->VERSION(2.101550); # improved downconversion | |||||||||
| 40 | |||||||||||
| 41 | 11 | my $zilla = $self->zilla; | |||||||||
| 42 | |||||||||||
| 43 | my $file = Dist::Zilla::File::FromCode->new({ | ||||||||||
| 44 | name => $self->filename, | ||||||||||
| 45 | code_return_type => 'text', | ||||||||||
| 46 | 11 | ▶ | code => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||
| 47 | 11 | my $distmeta = $zilla->distmeta; | |||||||||
| 48 | |||||||||||
| 49 | 11 | my $validator = CPAN::Meta::Validator->new($distmeta); | |||||||||
| 50 | |||||||||||
| 51 | 11 | ▶ | unless ($validator->is_valid) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | my $msg = "Invalid META structure. Errors found:\n"; | |||||||||
| 53 | 0 | $msg .= join( "\n", $validator->errors ); | |||||||||
| 54 | 0 | $self->log_fatal($msg); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 11 | my $converter = CPAN::Meta::Converter->new($distmeta); | |||||||||
| 58 | 11 | my $output = $converter->convert(version => '1.4'); | |||||||||
| 59 | 11 | $output->{x_serialization_backend} = sprintf '%s version %s', | |||||||||
| 60 | 'YAML::Tiny', YAML::Tiny->VERSION; | ||||||||||
| 61 | |||||||||||
| 62 | 11 | ▶ | my $yaml = try { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 63 | 11 | YAML::Tiny->new($output)->write_string; # text! | |||||||||
| 64 | } | ||||||||||
| 65 | 0 | ▶ | catch { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 66 | 0 | $self->log_fatal("Could not create YAML string: " . YAML::Tiny->errstr) | |||||||||
| 67 | 11 | }; | |||||||||
| 68 | 11 | return $yaml; | |||||||||
| 69 | }, | ||||||||||
| 70 | 11 | }); | |||||||||
| 71 | |||||||||||
| 72 | 11 | $self->add_file($file); | |||||||||
| 73 | 11 | return; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 11 | __PACKAGE__->meta->make_immutable; | |||||||||
| 77 | 11 | 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__ | ||||||||||