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

filter: Statementstmt 90.4% 38 / 42 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 86.7% 46 / 53 CC 2 SCAR 3.1
CC
2
Cov
89%
__ANON__
2.1
__ANON__
2.0
gather_files
1.0
CRAP 1.4
« blib/lib/Dist/Zilla/Plugin/MetaYAML.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/GenerateFile.pm »
1 package Dist::Zilla::Plugin::MetaJSON 6.040;
2 # ABSTRACT: produce a META.json
3  
4 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 with 'Dist::Zilla::Role::FileGatherer';
6 8 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 ▶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.json> file to the distribution.
15 #pod
16 #pod This file is meant to replace the old-style F<META.yml>. For more information
17 #pod on this file, see L<Module::Build::API> and L<CPAN::Meta>.
18 #pod
19 #pod =attr filename
20 #pod
21 #pod If given, parameter allows you to specify an alternate name for the generated
22 #pod file. It defaults, of course, to F<META.json>.
23 #pod
24 #pod =cut
25  
26 8 has filename => (
27 is => 'ro',
28 isa => 'Str',
29 default => 'META.json',
30 );
31  
32 #pod =attr version
33 #pod
34 #pod This parameter lets you pick what version of the spec to use when generating
35 #pod the output. It defaults to 2 at present, but may be updated to new specs as
36 #pod they are released and adopted.
37 #pod
38 #pod If you want a fixed version, specify it.
39 #pod
40 #pod =cut
41  
42 my $version_type = subtype(
43 as 'Num',
44 9 ▶ where { $_ >= 2 },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 0 ▶ message { "MetaJSON version must be 2 or greater" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 8 );
47  
48 8 has version => (
49 is => 'ro',
50 isa => $version_type,
51 default => '2',
52 );
53  
54 9 ▶sub gather_files {
Subroutine gather_files: called CC=1 SCAR=0.0
Pod undocumented
55 9 my ($self, $arg) = @_;
56  
57 9 my $zilla = $self->zilla;
58  
59 9 require JSON::MaybeXS;
60 9 require Dist::Zilla::File::FromCode;
61 9 require CPAN::Meta::Converter;
62 9 CPAN::Meta::Converter->VERSION(2.101550); # improved downconversion
63 9 require CPAN::Meta::Validator;
64 9 CPAN::Meta::Validator->VERSION(2.101550); # improved downconversion
65  
66 my $file = Dist::Zilla::File::FromCode->new({
67 name => $self->filename,
68 encoding => 'ascii',
69 code_return_type => 'text',
70 9 ▶ code => sub {
Subroutine __ANON__: called CC=2 SCAR=7.5
71 9 my $distmeta = $zilla->distmeta;
72  
73 9 my $validator = CPAN::Meta::Validator->new($distmeta);
74  
75 9 ▶ unless ($validator->is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($validator->is_valid) 0 9 9
76 0 my $msg = "Invalid META structure. Errors found:\n";
77 0 $msg .= join( "\n", $validator->errors );
78 0 $self->log_fatal($msg);
79 }
80  
81 9 my $converter = CPAN::Meta::Converter->new($distmeta);
82 9 my $output = $converter->convert(version => $self->version);
83  
84 9 my $backend = JSON::MaybeXS::JSON();
85 9 $output->{x_serialization_backend} = sprintf '%s version %s',
86 $backend, $backend->VERSION;
87  
88 9 JSON::MaybeXS->new(canonical => 1, pretty => 1, ascii => 1)->encode($output)
89 . "\n";
90 },
91 9 });
92  
93 9 $self->add_file($file);
94 9 return;
95 }
96  
97 8 __PACKAGE__->meta->make_immutable;
98 8 1;
99  
100 #pod =head1 SEE ALSO
101 #pod
102 #pod Core Dist::Zilla plugins:
103 #pod L<@Basic|Dist::Zilla::PluginBundle::Basic>,
104 #pod L<Manifest|Dist::Zilla::Plugin::Manifest>.
105 #pod
106 #pod Dist::Zilla roles:
107 #pod L<FileGatherer|Dist::Zilla::Role::FileGatherer>.
108 #pod
109 #pod Other modules:
110 #pod L<CPAN::Meta>,
111 #pod L<CPAN::Meta::Spec>, L<JSON::MaybeXS>.
112 #pod
113 #pod =cut
114  
115 __END__
« blib/lib/Dist/Zilla/Plugin/MetaYAML.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/GenerateFile.pm »