| 1 | package Zed::Config::Space; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use base Zed::Config; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base Exporter; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Zed::Range::Parser; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | Zed::Config::Space - Control operation target space. | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | use Zed::Config::Space; | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | space 'foo' => ['localhost']; #add target to space 'foo' | ||||||||||||||||||||||||||||||||
| 17 | usespace 'foo'; #switch target space to 'foo' | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | my %one_target = space 'foo'; #return target in space 'foo' | ||||||||||||||||||||||||||||||||
| 20 | my %all_target = space; #return all target in space | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 1 | our @EXPORT = qw(targets space space_clean usespace ); | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use Zed::Output; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | 1 | our $NAME = "Space"; | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 1 | my $use; | |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | sub usespace | ||||||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $key = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
usespace: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $use = $key =~ /^(none|undef)$/ ? undef : $key if $key; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 35 | 0 | $use | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | sub load | ||||||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
load: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 41 | 0 | $this->SUPER::load(); | |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 0 | my $config = $this->config; | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 0 | debug("config:", $config); | |||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | while(my($k, $v) = each %$config) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||||||
| 48 | 0 | debug("key $k:", $v); | |||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | next unless ref $v eq 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | 0 | my @host = map{ Zed::Range::Parser->parse($_)->dump }@$v; | |||||||||||||||||||||||||||||||
| 51 | 0 | debug("parse:", \@host); | |||||||||||||||||||||||||||||||
| 52 | 0 | $config->{$k} = \@host; | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | 0 | debug("config:", $config); | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | sub dump | ||||||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 0 | my $config = __PACKAGE__->config; | |||||||||||||||||||||||||||||||
| 61 | 0 | for(keys %$config) | |||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | delete $config->{$_} if $_ =~ /\.(group\d+|suc|fail)$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | 0 | $this->SUPER::dump(); | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | sub space_clean | ||||||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $pat = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
space_clean: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 70 | 0 | my $config = __PACKAGE__->config; | |||||||||||||||||||||||||||||||
| 71 | 0 | $pat = qr/^$pat\d+/; | |||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | map{ delete $config->{$_} if $_ =~ $pat }keys %$config; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | sub targets | ||||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | error("use no space!") and return unless $use; | ||||||||||||||||||||||||||||||
|
Subroutine
targets: not called CC=3 SCAR=24.8
Pod
undocumented
Branch: 1 branch
Condition0%0/5
$use || error('use no space!') && (return)
error("use no space!") and return
MC/DC0%0/2
$use || error('use no space!') && (return)
$use
error("use no space!")
Truth table0%0/3
A || B
A= $useB= error("use no space!")
| |||||||||||||||||||||||||||||||||
| 78 | 0 | space($use); | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | sub space | ||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my ($key, $value) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
space: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 84 | 0 | my $config = __PACKAGE__->config; | |||||||||||||||||||||||||||||||
| 85 | 0 | debug("config", $config); | |||||||||||||||||||||||||||||||
| 86 | 0 | debug("key:|$key| host:", $value); | |||||||||||||||||||||||||||||||
| 87 | $key ? $value ? $config->{$key} = $value | ||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | : wantarray ? @{ $config->{$key} } : \@{ $config->{$key} } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | : wantarray ? %$config : \%{$config}; | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | 1 | 1; | |||||||||||||||||||||||||||||||