| 1 | package Dist::Zilla::PluginBundle::Filter 6.040; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: use another bundle, with some plugins removed | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | with 'Dist::Zilla::Role::PluginBundle'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Dist::Zilla::Pragmas; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use List::Util 1.33 qw(any); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Module::Runtime qw(use_module); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Dist::Zilla::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | #pod =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||||||||||
| 17 | #pod In your F<dist.ini>: | ||||||||||||||||||||||||||||
| 18 | #pod | ||||||||||||||||||||||||||||
| 19 | #pod [@Filter] | ||||||||||||||||||||||||||||
| 20 | #pod -bundle = @Basic | ||||||||||||||||||||||||||||
| 21 | #pod -version = 5.031 | ||||||||||||||||||||||||||||
| 22 | #pod -remove = ShareDir | ||||||||||||||||||||||||||||
| 23 | #pod -remove = UploadToCPAN | ||||||||||||||||||||||||||||
| 24 | #pod option = for_basic | ||||||||||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||||||||||
| 26 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 27 | #pod | ||||||||||||||||||||||||||||
| 28 | #pod This plugin bundle actually wraps and modifies another plugin bundle. It | ||||||||||||||||||||||||||||
| 29 | #pod includes all the configuration for the bundle named in the C<-bundle> attribute, | ||||||||||||||||||||||||||||
| 30 | #pod but removes all the entries whose package is given in the C<-remove> attributes. | ||||||||||||||||||||||||||||
| 31 | #pod | ||||||||||||||||||||||||||||
| 32 | #pod A minimum required version of the bundle can be specified with the C<-version> | ||||||||||||||||||||||||||||
| 33 | #pod attribute. | ||||||||||||||||||||||||||||
| 34 | #pod | ||||||||||||||||||||||||||||
| 35 | #pod Options not prefixed with C<-> will be passed to the bundle to be filtered. | ||||||||||||||||||||||||||||
| 36 | #pod | ||||||||||||||||||||||||||||
| 37 | #pod B<NOTE:> When you filter a bundle you B<SHOULD NOT> include it directly in | ||||||||||||||||||||||||||||
| 38 | #pod your C<dist.ini> file. This plugin will take care of including it for you. | ||||||||||||||||||||||||||||
| 39 | #pod | ||||||||||||||||||||||||||||
| 40 | #pod =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 41 | #pod | ||||||||||||||||||||||||||||
| 42 | #pod Core Dist::Zilla plugins: L<@Basic|Dist::Zilla::PluginBundle::Basic>. | ||||||||||||||||||||||||||||
| 43 | #pod | ||||||||||||||||||||||||||||
| 44 | #pod Dist::Zilla roles: L<PluginBundle|Dist::Zilla::Role::PluginBundle>. | ||||||||||||||||||||||||||||
| 45 | #pod | ||||||||||||||||||||||||||||
| 46 | #pod =cut | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub mvp_multivalue_args { qw(remove -remove) } | ||||||||||||||||||||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | sub bundle_config { | ||||||||||||||||||||||||||
|
Subroutine
bundle_config: called CC=13 SCAR=27.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 2 | my ($self, $section) = @_; | |||||||||||||||||||||||||||
| 52 | 2 | ▶ | my $class = (ref $self) || $self; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | my $config = {}; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | ▶ | my $has_filter_args = any { /^-/ } keys %{ $section->{payload} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 2 | for my $key (keys %{ $section->{payload} }) { | |||||||||||||||||||||||||||
| 58 | 4 | my $val = $section->{payload}->{$key}; | |||||||||||||||||||||||||||
| 59 | 4 | ▶ | my $target = $has_filter_args && ($key !~ /^-/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$has_filter_args and not $key =~ /^-/u
MC/DC0%0/2
$has_filter_args and not $key =~ /^-/u
$has_filter_args
not $key =~ /^-/u
Truth table33%1/3
A and not(B)
A= $has_filter_argsB= not $key =~ /^-/u
| |||||||||||||||||||||||||||||
| 60 | ? 'bundle' | ||||||||||||||||||||||||||||
| 61 | : 'filter'; | ||||||||||||||||||||||||||||
| 62 | 4 | ▶ | $key =~ s/^-// if $target eq 'filter'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 4 | $config->{$target}->{$key} = $val; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | Carp::croak("no bundle given for bundle filter") | ||||||||||||||||||||||||||||
| 67 | 2 | ▶ | unless my $bundle = $config->{filter}->{bundle}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | my $pkg = Dist::Zilla::Util->expand_config_package_name($bundle); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 2 | my $version = $config->{filter}->{version}; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 2 | ▶ | unless (eval { &use_module($pkg, $version ? $version : ()); 1 }) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 74 | # XXX Naughty! -- rjbs, 2013-07-23 | ||||||||||||||||||||||||||||
| 75 | 0 | Config::MVP::Section->missing_package($pkg, $bundle); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | my @plugins = $pkg->bundle_config({ | ||||||||||||||||||||||||||||
| 79 | name => $section->{name}, # not 100% sure about this -- rjbs, 2010-03-06 | ||||||||||||||||||||||||||||
| 80 | package => $pkg, | ||||||||||||||||||||||||||||
| 81 | payload => $config->{bundle} || {}, | ||||||||||||||||||||||||||||
| 82 | 2 | ▶ | }); | ||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'bundle'} || {}
MC/DC0%0/1
$config->{'bundle'} || {}
$config->{'bundle'}
Truth table50%1/2
A
A= $config->{'bundle'}
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | ▶ | return @plugins unless my $remove = $config->{filter}->{remove}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | for my $i (reverse 0 .. $#plugins) { | |||||||||||||||||||||||||||
| 87 | 50 | ▶ | splice @plugins, $i, 1 if any(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | 50 | $plugins[$i][1] eq Dist::Zilla::Util->expand_config_package_name($_) | |||||||||||||||||||||||||||
| 89 | 34 | ▶ | }, @$remove); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | return @plugins; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 96 | 3 | 1; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||