blib/lib/Zed/Config/Space.pm

filter: Statementstmt 31.3% 16 / 51 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 6 totaltotal 20.8% 20 / 96 CC 14 SCAR 26.0
CC
14
Cov
21%
space
30.0
usespace
12.0
load
12.0
CRAP 13.5
« blib/lib/Zed/SSHPool.pm ↑ Summary blib/lib/Zed/Config/Env.pm »
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
BranchTrueFalseTotal
if $key 0 0 0
$key =~ /^(none|undef)$/ ? : 0 0 0
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
BranchTrueFalseTotal
if (() = each %$config) 0 0 0
47 {
48 0 debug("key $k:", $v);
49 0 ▶ next unless ref $v eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "ARRAY" 0 0 0
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
BranchTrueFalseTotal
if $_ =~ /\.(group\d+|suc|fail)$/ 0 0 0
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
BranchTrueFalseTotal
if $_ =~ /$pat/ 0 0 0
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
BranchTrueFalseTotal
unless $use 0 0 0
Condition0%0/5
$use || error('use no space!') && (return)
l!l&&r!l&&!r
000
error("use no space!") and return
!ll
00
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!")
ABresult
1X1
011
000
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
BranchTrueFalseTotal
wantarray ? : 0 0 0
89 0 ▶ : wantarray ? %$config : \%{$config};
Branch: 3 branches
BranchTrueFalseTotal
$key ? : 0 0 0
$value ? : 0 0 0
wantarray ? : 0 0 0
90 }
91 1 1;
« blib/lib/Zed/SSHPool.pm ↑ Summary blib/lib/Zed/Config/Env.pm »