blib/lib/Dist/Zilla/Plugin/MetaYAML.pm

filter: Statementstmt 90.0% 36 / 40 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 86.2% 44 / 51 CC 2 SCAR 3.1
CC
2
Cov
88%
__ANON__
2.1
__ANON__
2.0
gather_files
1.0
CRAP 1.4
« blib/lib/Dist/Zilla/Types.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/MetaJSON.pm »
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
BranchTrueFalseTotal
unless ($validator->is_valid) 0 11 11
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__
« blib/lib/Dist/Zilla/Types.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/MetaJSON.pm »