File Coverage

blib/lib/Dist/Zilla/Plugin/MetaMergeFile.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 34 36 94.4


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::MetaMergeFile;
2             $Dist::Zilla::Plugin::MetaMergeFile::VERSION = '0.003';
3 1     1   3426198 use Moose;
  1         3  
  1         9  
4 1     1   6890 use namespace::autoclean;
  1         3  
  1         9  
5              
6             with qw/Dist::Zilla::Role::MetaProvider Dist::Zilla::Role::PrereqSource/;
7              
8 1     1   582 use MooseX::Types::Stringlike 'Stringlike';
  1         45305  
  1         9  
9 1     1   2265 use Parse::CPAN::Meta;
  1         1758  
  1         362  
10              
11             my @defaults = qw/metamerge.json metamerge.yml/;
12              
13             has filename => (
14             is => 'ro',
15             isa => Stringlike,
16             default => sub {
17             return (grep { -f } @defaults)[0];
18             },
19             );
20              
21             has _rawdata => (
22             is => 'ro',
23             lazy => 1,
24             builder => '_build_rawdata',
25             );
26              
27             sub _build_rawdata {
28 1     1   3 my $self = shift;
29 1         47 return Parse::CPAN::Meta->load_file($self->filename);
30             }
31              
32             sub metadata {
33 1     1 0 5952 my $self = shift;
34 1         3 my %data = %{ $self->_rawdata };
  1         43  
35 1         4 delete $data{prereqs};
36 1         5 return \%data;
37             }
38              
39             sub register_prereqs {
40 1     1 0 427410 my $self = shift;
41 1         39 my $prereqs = $self->_rawdata->{prereqs};
42 1         2 for my $phase (keys %{ $prereqs }) {
  1         6  
43 1         2 for my $type (keys %{ $prereqs->{$phase} }) {
  1         6  
44             $self->zilla->register_prereqs(
45             { phase => $phase, type => $type },
46 1         33 %{ $prereqs->{$phase}{$type} }
  1         18  
47             );
48             }
49             }
50             }
51              
52             __PACKAGE__->meta->make_immutable;
53              
54             1;
55              
56             #ABSTRACT: Add arbitrary metadata using a mergefile
57              
58             __END__
59              
60             =pod
61              
62             =encoding UTF-8
63              
64             =head1 NAME
65              
66             Dist::Zilla::Plugin::MetaMergeFile - Add arbitrary metadata using a mergefile
67              
68             =head1 VERSION
69              
70             version 0.003
71              
72             =head1 SYNOPSIS
73              
74             =head3 dist.ini:
75              
76             [MetaMergeFile]
77              
78             =head3 metamerge.yml
79              
80             prereqs:
81             runtime:
82             recommends:
83             Foo: 0.023
84             suggests:
85             Bar: 0
86             resources
87             homepage: http://www.example.com/MyModule/
88             x_twitter: http://twitter.com/cpan_linked/
89              
90             =head1 DESCRIPTION
91              
92             This plugin implements metamerge files. These allow you to easily add arbitrary information to your metafiles.
93              
94             =head2 Why metamerge files?
95              
96             Metamerge files are somewhat similar to cpanfiles, but with a few important differences. Firstly, they're not limited to prereqs but allow any valid type of metadata. Secondly, they don't involve evaluating code to produce data, data should be data.
97              
98             =head2 Names and formats
99              
100             This file reads either a JSON formatted F<metamerge.json>, or a YAML formatted F<metamerge.yml> (or another file if passed with the C<filename> parameter). Regardless of the format, it will parse them as L<META 2.0|CPAN::Meta::Spec> unless their C<meta-spec> field claims otherwise.
101              
102             =head1 AUTHOR
103              
104             Leon Timmermans <leont@cpan.org>
105              
106             =head1 COPYRIGHT AND LICENSE
107              
108             This software is copyright (c) 2017 by Leon Timmermans.
109              
110             This is free software; you can redistribute it and/or modify it under
111             the same terms as the Perl 5 programming language system itself.
112              
113             =cut