| 1 | 2 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Dist::Zilla::Role::BundleDeps; | ||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '0.002004'; | |||||||||
| 8 | |||||||||||
| 9 | # ABSTRACT: Automatically add all plugins in a bundle as dependencies | ||||||||||
| 10 | |||||||||||
| 11 | 2 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | 2 | ▶ | use Moose::Role qw( around ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | sub bundledeps_defaults { | ||||||||||
| 49 | return { | ||||||||||
| 50 | 1 | ▶ | -phase => 'develop', | ||||||||
|
Subroutine
bundledeps_defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 51 | -relationship => 'requires', | ||||||||||
| 52 | }; | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | around bundle_config => sub { | ||||||||||
| 56 | 1 | ▶ | my ( $orig, $self, $section, ) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||
| 57 | 1 | my $myconf = $self->bundledeps_defaults; | |||||||||
| 58 | 1 | for my $param (qw( phase relationship )) { | |||||||||
| 59 | 2 | my $field = 'bundledeps_' . $param; | |||||||||
| 60 | 2 | ▶ | next unless exists $section->{payload}->{$field}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | $myconf->{ q[-] . $param } = delete $section->{payload}->{$field}; | |||||||||
| 62 | } | ||||||||||
| 63 | 1 | my (@config) = $self->$orig($section); | |||||||||
| 64 | 1 | my $reqs = $self->_extract_plugin_prereqs(@config); | |||||||||
| 65 | 1 | return ( @config, $self->_create_prereq_plugin( $reqs => $myconf ) ); | |||||||||
| 66 | 2 | }; | |||||||||
| 67 | |||||||||||
| 68 | 2 | ▶ | no Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 69 | |||||||||||
| 70 | sub _bundle_alias { | ||||||||||
| 71 | 1 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_bundle_alias: called CC=2 SCAR=7.4
| |||||||||||
| 72 | 1 | my $ns = $self->meta->name; | |||||||||
| 73 | 1 | ▶ | if ( $ns =~ /\ADist::Zilla::PluginBundle::(.*\z)/msx ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 0 | return q[@] . $1; | |||||||||
| 75 | } | ||||||||||
| 76 | 1 | return $ns; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | sub _extract_plugin_prereqs { | ||||||||||
| 80 | 1 | ▶ | my ( undef, @config ) = @_; | ||||||||
|
Subroutine
_extract_plugin_prereqs: called CC=3 SCAR=11.0
| |||||||||||
| 81 | 1 | require CPAN::Meta::Requirements; | |||||||||
| 82 | 1 | my $reqs = CPAN::Meta::Requirements->new(); | |||||||||
| 83 | 1 | for my $item (@config) { | |||||||||
| 84 | 2 | my ( undef, $module, $conf ) = @{$item}; | |||||||||
| 85 | 2 | my $version = 0; | |||||||||
| 86 | 2 | ▶ | $version = $conf->{':version'} if exists $conf->{':version'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 2 | $reqs->add_string_requirement( $module, $version ); | |||||||||
| 88 | } | ||||||||||
| 89 | 1 | return $reqs; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | sub _create_prereq_plugin { | ||||||||||
| 93 | 1 | ▶ | my ( $self, $reqs, $config ) = @_; | ||||||||
|
Subroutine
_create_prereq_plugin: called CC=1 SCAR=0.0
| |||||||||||
| 94 | 1 | my $plugin_conf = { %{$config}, %{ $reqs->as_string_hash } }; | |||||||||
| 95 | 1 | my $prereq = []; | |||||||||
| 96 | 1 | push @{$prereq}, $self->_bundle_alias . '/::Role::BundleDeps'; | |||||||||
| 97 | 1 | push @{$prereq}, 'Dist::Zilla::Plugin::Prereqs'; | |||||||||
| 98 | 1 | push @{$prereq}, $plugin_conf; | |||||||||
| 99 | 1 | return $prereq; | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 2 | 1; | |||||||||
| 103 | |||||||||||
| 104 | __END__ | ||||||||||
| 105 | |||||||||||
| 106 | =pod | ||||||||||
| 107 | |||||||||||
| 108 | =encoding UTF-8 | ||||||||||
| 109 | |||||||||||
| 110 | =head1 NAME | ||||||||||
| 111 | |||||||||||
| 112 | Dist::Zilla::Role::BundleDeps - Automatically add all plugins in a bundle as dependencies | ||||||||||
| 113 | |||||||||||
| 114 | =head1 VERSION | ||||||||||
| 115 | |||||||||||
| 116 | version 0.002004 | ||||||||||
| 117 | |||||||||||
| 118 | =head1 SYNOPSIS | ||||||||||
| 119 | |||||||||||
| 120 | package blahblahblah; | ||||||||||
| 121 | use Moose; | ||||||||||
| 122 | ... | ||||||||||
| 123 | with 'Dist::Zilla::Role::PluginBundle'; | ||||||||||
| 124 | with 'Dist::Zilla::Role::BundleDeps'; | ||||||||||
| 125 | |||||||||||
| 126 | Dependencies appear now for all plugins returned. | ||||||||||
| 127 | |||||||||||
| 128 | =head1 DESCRIPTION | ||||||||||
| 129 | |||||||||||
| 130 | This role attempts to solve the problem of communicating dependencies to META.* from bundles | ||||||||||
| 131 | in a different way. | ||||||||||
| 132 | |||||||||||
| 133 | My first attempt was L<< C<[Prereqs::Plugins]>|Dist::Zilla::Plugins::Prereqs::Plugins >>, which added | ||||||||||
| 134 | all values that are seen in the C<dist.ini> to dependencies. | ||||||||||
| 135 | |||||||||||
| 136 | However, that was inherently limited, as the C<:version> specifier | ||||||||||
| 137 | is lost before the plugins appear on C<< $zilla->plugins >> | ||||||||||
| 138 | |||||||||||
| 139 | This Role however, can see any declarations of C<:version> your bundle advertises, | ||||||||||
| 140 | by standing between your C<bundle_config> method and C<Dist::Zilla> | ||||||||||
| 141 | |||||||||||
| 142 | =head1 METHODS | ||||||||||
| 143 | |||||||||||
| 144 | =head2 C<bundledeps_defaults> | ||||||||||
| 145 | |||||||||||
| 146 | This method provides the C<HashRef> of defaults to use for the generated C<Prereqs> section. | ||||||||||
| 147 | |||||||||||
| 148 | Because this role is intended to advertise Plugin Bundle dependencies, and because those | ||||||||||
| 149 | dependencies will be "develop" dependencies everywhere other than the bundle itself, | ||||||||||
| 150 | our defaults are: | ||||||||||
| 151 | |||||||||||
| 152 | { | ||||||||||
| 153 | -phase => develop, | ||||||||||
| 154 | -relationship => requires, | ||||||||||
| 155 | } | ||||||||||
| 156 | |||||||||||
| 157 | These can be overridden when consuming a bundle in C<dist.ini> | ||||||||||
| 158 | |||||||||||
| 159 | [@Author::MyBundle] | ||||||||||
| 160 | ; authordep Dist::Zilla::Role::BundleDeps | ||||||||||
| 161 | bundledeps_phase = runtime | ||||||||||
| 162 | bundledeps_relationship = requires | ||||||||||
| 163 | |||||||||||
| 164 | =begin MetaPOD::JSON v1.1.0 | ||||||||||
| 165 | |||||||||||
| 166 | { | ||||||||||
| 167 | "namespace":"Dist::Zilla::Role::BundleDeps", | ||||||||||
| 168 | "interface":"role" | ||||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | |||||||||||
| 172 | =end MetaPOD::JSON | ||||||||||
| 173 | |||||||||||
| 174 | =head1 LIMITATIONS | ||||||||||
| 175 | |||||||||||
| 176 | =head2 Self References in develop_requires | ||||||||||
| 177 | |||||||||||
| 178 | If you bundle plugins with your bundle, and use those plugins in the bundle, | ||||||||||
| 179 | you'll risk a self-reference problem, which may be solved in a future release of Dist::Zilla. | ||||||||||
| 180 | |||||||||||
| 181 | Until then, you'll need to possibly use L<< C<[RemovePrereqs]>|Dist::Zilla::Plugin::RemovePrereqs >> | ||||||||||
| 182 | to trim self-references. | ||||||||||
| 183 | |||||||||||
| 184 | =head2 Bootstrap problems on Bundles | ||||||||||
| 185 | |||||||||||
| 186 | When using your bundle to ship itself, the use of this role can imply some confusion if the role is not installed, | ||||||||||
| 187 | as C<dzil listdeps> will require this role present to work. | ||||||||||
| 188 | |||||||||||
| 189 | It is subsequently recommended to state an explicit C<AuthorDep> in C<dist.ini> to avoid this. | ||||||||||
| 190 | |||||||||||
| 191 | [Bootstrap::lib] | ||||||||||
| 192 | |||||||||||
| 193 | [@Author::MyBundle] | ||||||||||
| 194 | ; authordep Dist::Zilla::Role::BundleDeps | ||||||||||
| 195 | bundledeps_phase = runtime | ||||||||||
| 196 | bundledeps_relationship = requires | ||||||||||
| 197 | |||||||||||
| 198 | =head1 SEE ALSO | ||||||||||
| 199 | |||||||||||
| 200 | L<< C<[BundleInspector]>|Dist::Zilla::Plugin::BundleInspector >> | ||||||||||
| 201 | |||||||||||
| 202 | =head1 AUTHOR | ||||||||||
| 203 | |||||||||||
| 204 | Kent Fredric <kentnl@cpan.org> | ||||||||||
| 205 | |||||||||||
| 206 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 207 | |||||||||||
| 208 | This software is copyright (c) 2016 by Kent Fredric <kentfredric@gmail.com>. | ||||||||||
| 209 | |||||||||||
| 210 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 211 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 212 | |||||||||||
| 213 | =cut | ||||||||||