File Coverage

lib/Dist/Zilla/Plugin/MetaConfig/Deep.pm
Criterion Covered Total %
statement 14 47 29.7
branch 0 14 0.0
condition n/a
subroutine 5 11 45.4
pod 0 1 0.0
total 19 73 26.0


line stmt bran cond sub pod time code
1 1     1   884 use 5.006; # our
  1         3  
2 1     1   5 use strict;
  1         1  
  1         21  
3 1     1   4 use warnings;
  1         8  
  1         68  
4              
5             package Dist::Zilla::Plugin::MetaConfig::Deep;
6              
7             our $VERSION = '0.001000';
8              
9             # ABSTRACT: Experimental enhancements to MetaConfig
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 1     1   1073 use Moose qw( with );
  1         481120  
  1         8  
14              
15             with 'Dist::Zilla::Role::MetaProvider';
16              
17 0     0     sub _metadata_perl { return { version => $] } }
18              
19             sub _metadata_zilla {
20 0     0     my ($self) = @_;
21              
22 0           my $config = $self->zilla->dump_config;
23 0           my $composed = $self->_metadata_class_composes( $self->zilla );
24              
25             return {
26             class => $self->zilla->meta->name,
27             version => $self->zilla->VERSION,
28 0           ( keys %{$config} ? ( config => $config ) : () ),
29 0 0         ( keys %{$composed} ? ( x_composes => $composed ) : () ),
  0 0          
30             };
31             }
32              
33             sub _metadata_plugins {
34 0     0     my ($self) = @_;
35 0           return [ map { $self->_metadata_plugin($_) } @{ $self->zilla->plugins } ];
  0            
  0            
36             }
37              
38             sub _metadata_class_composes {
39 0     0     my ( undef, $plugin ) = @_;
40              
41 0           my $composed = {};
42 0           for my $component ( $plugin->meta->calculate_all_roles_with_inheritance ) {
43 0 0         next if $component->name =~ /[|]|_ANON_/sx; # skip unions and anon classes
44 0           $composed->{ $component->name } = $component->name->VERSION;
45             }
46 0           for my $component ( $plugin->meta->linearized_isa ) {
47 0 0         next if $component->meta->name =~ /[|]|_ANON_/sx; # skip unions.
48 0 0         next if $component->meta->name eq $plugin->meta->name; # skip self
49 0           $composed->{ $component->meta->name } = $component->meta->name->VERSION;
50             }
51              
52 0           return $composed;
53             }
54              
55             sub _metadata_plugin {
56 0     0     my ( $self, $plugin ) = @_;
57 0           my $config = $plugin->dump_config;
58 0           my $composed = $self->_metadata_class_composes($plugin);
59             return {
60             class => $plugin->meta->name,
61             name => $plugin->plugin_name,
62             version => $plugin->VERSION,
63 0           ( keys %{$config} ? ( config => $config ) : () ),
64 0 0         ( keys %{$composed} ? ( x_composes => $composed ) : () ),
  0 0          
65             };
66             }
67              
68              
69              
70              
71              
72             sub metadata {
73 0     0 0   my ($self) = @_;
74              
75 0           my $dump = {};
76              
77 0           $dump->{zilla} = $self->_metadata_zilla;
78 0           $dump->{perl} = $self->_metadata_perl;
79 0           $dump->{plugins} = $self->_metadata_plugins;
80              
81 0           return { x_Dist_Zilla => $dump };
82             }
83              
84             __PACKAGE__->meta->make_immutable;
85 1     1   6259 no Moose;
  1         3  
  1         5  
86              
87             1;
88              
89             __END__
90              
91             =pod
92              
93             =encoding UTF-8
94              
95             =head1 NAME
96              
97             Dist::Zilla::Plugin::MetaConfig::Deep - Experimental enhancements to MetaConfig
98              
99             =head1 VERSION
100              
101             version 0.001000
102              
103             =head1 DESCRIPTION
104              
105             This module serves as an experimental space for features I think the core MetaConfig I<should>
106             provide, but in a state of uncertainty about how they should be implemented.
107              
108             The objective is to extract more metadata about plugins without plugins having to percolate
109             hand-written adjustments system-wide to get a useful interface.
110              
111             =head2 Composition Data
112              
113             This exposes data about the roles and parent classes, and their respective versions in play
114             on a given plugin, to give greater depth for problem diagnosis.
115              
116             {
117             "class" : "Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING",
118             "config" : {...},
119             "name" : "@Author::KENTNL/Author::KENTNL::CONTRIBUTING",
120             "version" : "0.001005",
121             "x_composes" : {
122             "Dist::Zilla::Plugin::GenerateFile::FromShareDir" : "0.009",
123             "Dist::Zilla::Role::AfterBuild" : "5.041",
124             "Dist::Zilla::Role::AfterRelease" : "5.041",
125             "Dist::Zilla::Role::ConfigDumper" : "5.041",
126             "Dist::Zilla::Role::FileGatherer" : "5.041",
127             "Dist::Zilla::Role::FileInjector" : "5.041",
128             "Dist::Zilla::Role::FileMunger" : "5.041",
129             "Dist::Zilla::Role::Plugin" : "5.041",
130             "Dist::Zilla::Role::RepoFileInjector" : "0.005",
131             "Dist::Zilla::Role::TextTemplate" : "5.041",
132             "Moose::Object" : "2.1604",
133             "MooseX::SlurpyConstructor::Role::Object" : "1.2"
134             }
135             }
136              
137             C<@ETHER> has already made excellent inroads into making this sort of metadata exposed
138             via exporting C<version> in all C<metaconfig> plugin's she has access to, and this is an attempt
139             at providing the same level of insight without requiring so much explicit buy-in from plugin authors.
140              
141             This also has the neat side effect of showing what phases a plug-in is subscribed to.
142              
143             =for Pod::Coverage metadata
144              
145             =head1 AUTHOR
146              
147             Kent Fredric <kentnl@cpan.org>
148              
149             =head1 COPYRIGHT AND LICENSE
150              
151             This software is copyright (c) 2015 by Kent Fredric <kentfredric@gmail.com>.
152              
153             This is free software; you can redistribute it and/or modify it under
154             the same terms as the Perl 5 programming language system itself.
155              
156             =cut