blib/lib/Dist/Zilla/PluginBundle/Filter.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 57.1% 8 / 14 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 77.9% 67 / 86 CC 13 SCAR 22.8
CC
13
Cov
83%
bundle_config
15.8
BEGIN
1.0
BEGIN
1.0
CRAP 9.8
« blib/lib/Dist/Zilla/App.pm ↑ Summary blib/lib/Dist/Zilla/MVP/Reader/Perl.pm »
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
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$has_filter_args && !($key =~ /^-/u) ? : 0 4 4
Condition33%1/3
$has_filter_args and not $key =~ /^-/u
!ll&&!rl&&r
400
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
ABresult
0X0
100
111
60 ? 'bundle'
61 : 'filter';
62 4 ▶ $key =~ s/^-// if $target eq 'filter';
Branch: 1 branch
BranchTrueFalseTotal
if $target eq "filter" 4 0 4
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
BranchTrueFalseTotal
unless my $bundle = $config->{"filter"}{"bundle"} 0 2 2
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
BranchTrueFalseTotal
unless (eval { do { &use_module($pkg, $version ? $version : ()); 1 } }) 0 2 2
$version ? : 0 2 2
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'} || {}
l!l
02
MC/DC0%0/1
$config->{'bundle'} || {}
$config->{'bundle'}
Truth table50%1/2
A
A= $config->{'bundle'}
Aresult
11
00
83  
84 2 ▶ return @plugins unless my $remove = $config->{filter}->{remove};
Branch: 1 branch
BranchTrueFalseTotal
unless my $remove = $config->{"filter"}{"remove"} 0 2 2
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
BranchTrueFalseTotal
if &any(sub { $plugins[$i][1] eq "Dist::Zilla::Util"->expand_config_package_name($_); } , @$remove) 3 31 34
90 }
91  
92 2 return @plugins;
93 }
94  
95 3 __PACKAGE__->meta->make_immutable;
96 3 1;
97  
98 __END__
« blib/lib/Dist/Zilla/App.pm ↑ Summary blib/lib/Dist/Zilla/MVP/Reader/Perl.pm »