File Coverage

blib/lib/Brickyard/PluginBundle/Filter.pm
Criterion Covered Total %
statement 33 34 97.0
branch 6 10 60.0
condition n/a
subroutine 8 8 100.0
pod 2 2 100.0
total 49 54 90.7


line stmt bran cond sub pod time code
1 2     2   971 use 5.010;
  2         13  
  2         89  
2 2     2   12 use warnings;
  2         4  
  2         75  
3 2     2   11 use strict;
  2         4  
  2         110  
4              
5             package Brickyard::PluginBundle::Filter;
6             BEGIN {
7 2     2   63 $Brickyard::PluginBundle::Filter::VERSION = '1.111750';
8             }
9              
10             # ABSTRACT: Plugin bundle to filter another plugin bundle
11 2     2   12 use Brickyard::Accessor rw => [qw(bundle remove)];
  2         4  
  2         19  
12 2     2   1056 use Role::Basic 'with';
  2         3530  
  2         16  
13             with 'Brickyard::Role::PluginBundle';
14              
15             sub bundle_config {
16 1     1 1 2 my $self = shift;
17 1         4 my $package = $self->_exp($self->bundle);
18 1         63 eval "require $package";
19 1 50       5 die "Cannot require $package: $@" if $@;
20              
21             # config keys given to this plugin bundle whose name starts with a dash
22             # are intended for the plugin bundle that's being filtered.
23 1         2 my %args;
24 1         6 while (my ($key, $value) = each %$self) {
25 3 50       14 next unless $key =~ s/^-//;
26 0         0 $args{$key} = $value;
27             }
28 1         4 my $bundle_config =
29             $package->new(brickyard => $self->brickyard, %args)->bundle_config;
30 1 50       13 if (my $remove = $self->remove) {
31 1 50       4 $remove = [$remove] unless ref $remove eq 'ARRAY';
32 1         4 $self->remove_from_config($bundle_config, $remove);
33             }
34 1         6 $bundle_config;
35             }
36              
37             sub remove_from_config {
38 3     3 1 1112 my ($self, $bundle_config, $remove) = @_;
39 3         10 for my $i (reverse 0 .. $#$bundle_config) {
40 7 100       11 next unless grep { $bundle_config->[$i][1] eq $_ } @$remove;
  7         39  
41 2         13 splice @$bundle_config, $i, 1;
42             }
43             }
44             1;
45              
46              
47             __END__