| 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.002005'; | |||||||||
| 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 | 1 | ▶ | sub bundledeps_defaults { | ||||||||
|
Subroutine
bundledeps_defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 49 | return { | ||||||||||
| 50 | 1 | -phase => 'develop', | |||||||||
| 51 | -relationship => 'requires', | ||||||||||
| 52 | }; | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 1 | ▶ | around bundle_config => sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||
| 56 | 1 | my ( $orig, $self, $section, ) = @_; | |||||||||
| 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 | 1 | ▶ | sub _bundle_alias { | ||||||||
|
Subroutine
_bundle_alias: called CC=2 SCAR=7.4
| |||||||||||
| 71 | 1 | my ($self) = @_; | |||||||||
| 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 | 1 | ▶ | sub _extract_plugin_prereqs { | ||||||||
|
Subroutine
_extract_plugin_prereqs: called CC=3 SCAR=11.0
| |||||||||||
| 80 | 1 | my ( undef, @config ) = @_; | |||||||||
| 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 | 1 | ▶ | sub _create_prereq_plugin { | ||||||||
|
Subroutine
_create_prereq_plugin: called CC=1 SCAR=0.0
| |||||||||||
| 93 | 1 | my ( $self, $reqs, $config ) = @_; | |||||||||
| 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__ | ||||||||||