blib/lib/Cisco/Reconfig.pm

filter: Statementstmt 91.8% 418 / 455 Branchbran 68.9% 218 / 316 Conditioncond 58.2% 67 / 115 MC/DCmcdc 28.5% 18 / 63 Subroutinesub 93.3% 42 / 45 Podpod 41.6% 15 / 36 totaltotal 75.5% 778 / 1030 CC 204 SCAR 33.7
CC
204
Cov
79%
rc1
66.3
set
52.9
display
42.0
CRAP 29.1
↑ Summary
1  
2 package Cisco::Reconfig;
3  
4 9 @ISA = qw(Exporter);
5 9 @EXPORT = qw(readconfig);
6 9 @EXPORT_OK = qw(readconfig stringconfig $minus_one_indent_rx);
7  
8 9 $VERSION = '0.912';
9  
10 9 require Exporter;
11 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Text::Tabs;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use Carp qw(verbose confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 9 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 my $iostrings;
18 9 our $allow_minus_one_indent = qr/class /;
19 9 our $allow_plus_one_indent = qr/service-policy |quit$/;
20 9 our $bad_indent_policy = 'DIE';
21  
22  
23 9 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=8.4
24 0 ▶ eval " use IO::String ";
Subroutine BEGIN: called CC=1 SCAR=1.2
25 9 ▶ $iostrings = $@ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 9 0 9
26 }
27  
28  
29 9 my $debug_get = 0;
30 9 my $debug_mget = 0;
31 9 my $debug_set = 0;
32 9 my $debug_context = 0;
33 9 my $debug_text = 0;
34 9 ▶my $ddata = $debug_get
Condition35%5/14
$debug_get || $debug_mget || $debug_set || $debug_context || $debug_text || 0
l!l
09
$debug_get or $debug_mget or $debug_set or $debug_context or $debug_text
l!l&&r!l&&!r
009
$debug_get or $debug_mget or $debug_set or $debug_context
l!l&&r!l&&!r
009
$debug_get or $debug_mget or $debug_set
l!l&&r!l&&!r
009
$debug_get or $debug_mget
l!l&&r!l&&!r
009
MC/DC0%0/5
$debug_get || $debug_mget || $debug_set || $debug_context || $debug_text || 0
$debug_get $debug_mget $debug_set $debug_context $debug_text
Truth table16%1/6
A or B or C or D or E
A= $debug_getB= $debug_mgetC= $debug_setD= $debug_contextE= $debug_text
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
35 || $debug_mget
36 || $debug_set
37 || $debug_context
38 || $debug_text
39 || 0; # add debugging data to data structures
40  
41 9 my $spec = qr{^ };
42 9 my $text = " text";
43 9 my $subs = " subs";
44 9 my $next = " next";
45 9 my $cntx = " cntx";
46 9 my $word = " word";
47 9 my $seqn = " seqn";
48 9 my $dupl = " dupl";
49 9 my $debg = " debg";
50 9 my $bloc = " bloc";
51 9 my $UNDEFDESC = "! undefined\n";
52 9 my $undef = bless { $debg => $UNDEFDESC, $text => '' }, __PACKAGE__;
53 9 my $dseq = "O0000000";
54 9 our $nonext;
55  
56 9 my $line;
57 my $fh;
58  
59 use overload
60 9 ▶ 'bool' => \&defined,
Subroutine BEGIN: called CC=1 SCAR=0.0
61 '""' => \&text,
62 9 'fallback' => 1;
63  
64 sub stringconfig
65 1 ▶{
Subroutine stringconfig: called CC=2 SCAR=9.2
Pod undocumented
66 1 ▶ Carp::croak 'IO::Strings need to be installed to use "stringconfig"'
Branch: 1 branch
BranchTrueFalseTotal
unless $iostrings 1 0 1
67 . ' install it or use "readconfig" instead.' unless $iostrings;
68 0 readconfig(IO::String->new(join("\n",@_)));
69 }
70  
71 sub readconfig
72 8 ▶{
Subroutine readconfig: called CC=2 SCAR=7.0
Pod undocumented
73 8 my ($file) = @_;
74  
75 8 ▶ $fh = ref($file) ? $file : IO::File->new($file, "r");
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 8 0 8
76  
77 8 $line = <$fh>;
78 8 return rc1(0, 'aaaa', $undef, "! whole enchalada\n");
79 }
80  
81 sub rc1
82 92 ▶{
Subroutine rc1: called CC=49 SCAR=41.9
Pod undocumented
83 92 my ($indent, $seq, $parent, $dcon) = @_;
84 92 my $last;
85 92 my $config = bless { $bloc => 1 }, __PACKAGE__;
86  
87 92 ▶ $config->{$debg} = "BLOCK:$dseq:$dcon" if $ddata;
Branch: 1 branch
BranchTrueFalseTotal
if $ddata 0 92 92
88  
89 92 $config->{$cntx} = $parent;
90 92 weaken $config->{$cntx};
91  
92 92 $dseq++;
93 92 my $prev;
94 my $ciscobug;
95 92 ▶ for(;$line;$prev = $line, $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line) 805 9 814
96 888 $_ = $line;
97 888 s/^( *)//;
98 888 my $in = length($1);
99 888 s/^(no +)//;
100 888 my $no = $1;
101 888 ▶ if ($in > $indent) {
Branch: 2 branches
BranchTrueFalseTotal
if ($in > $indent) { } 81 807 888
elsif ($in < $indent) { } 90 717 807
102 81 ▶ if ($last) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last) { } 79 2 81
103 79 $last->{$subs} = rc1($in, "$last->{$seqn}aaa", $last, $line);
104 79 undef $last;
105 79 ▶ redo if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 78 1 79
106 } else {
107 # This really shouldn't happen. But it does. It's a violation of
108 # the usual indentation rules.
109 #
110 # An exclamation marks a reset of the indentation to zero.
111 #
112 2 ▶ if ($indent + 1 == $in && $allow_plus_one_indent && $line =~ /^\s*$allow_plus_one_indent/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indent + 1 == $in and $Cisco::Reconfig::allow_plus_one_indent and $line =~ /^\s*$Cisco::Reconfig::allow_plus_one_indent/) 0 2 2
Condition33%2/6
$indent + 1 == $in and $Cisco::Reconfig::allow_plus_one_indent and $line =~ /^\s*$Cisco::Reconfig::allow_plus_one_indent/
!ll&&!rl&&r
020
$indent + 1 == $in and $Cisco::Reconfig::allow_plus_one_indent
!ll&&!rl&&r
002
MC/DC0%0/3
$indent + 1 == $in and $Cisco::Reconfig::allow_plus_one_indent and $line =~ /^\s*$Cisco::Reconfig::allow_plus_one_indent/
$indent + 1 == $in $Cisco::Reconfig::allow_plus_one_indent $line =~ /^\s*$Cisco::Reconfig::allow_plus_one_indent/
Truth table25%1/4
A and B and C
A= $indent + 1 == $inB= $Cisco::Reconfig::allow_plus_one_indentC= $line =~ /^\s*$Cisco::Reconfig::allow_plus_one_indent/
ABCresult
0XX0
10X0
1100
1111
113 0 $indent = $indent + 1;
114 0 redo;
115 }
116 2 ▶ if ($indent != 0 || ($prev ne "!\n" && $prev !~ /^!.*<removed>$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indent != 0 or $prev ne "!\n" and not $prev =~ /^!.*<removed>$/) 0 2 2
Condition33%2/6
$indent != 0 or $prev ne "!\n" and not $prev =~ /^!.*<removed>$/
l!l&&r!l&&!r
002
$prev ne "!\n" and not $prev =~ /^!.*<removed>$/
!ll&&!rl&&r
200
MC/DC0%0/3
$indent != 0 or $prev ne "!\n" and not $prev =~ /^!.*<removed>$/
$indent != 0 $prev ne "!\n" not $prev =~ /^!.*<removed>$/
Truth table25%1/4
A or B and not(C)
A= $indent != 0B= $prev ne "!\n"C= not $prev =~ /^!.*<removed>$/
ABCresult
1XX1
0111
00X0
0100
117 0 ▶ if ($bad_indent_policy eq 'IGNORE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Cisco::Reconfig::bad_indent_policy eq 'IGNORE') { } 0 0 0
elsif ($Cisco::Reconfig::bad_indent_policy eq 'WARN') { } 0 0 0
118 # okay then
119 } elsif ($bad_indent_policy eq 'WARN') {
120 0 warn "Unexpected indentation change <$.:$_>";
121 } else {
122 0 confess "Unexpected indentation change <$.:$_>";
123 }
124 }
125 2 $ciscobug = 1;
126 2 $indent = $in;
127 }
128 } elsif ($in < $indent) {
129 90 ▶ if ($ciscobug && $in == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ciscobug and $in == 0) { } 2 88 90
elsif ($last and $indent - 1 == $in and $Cisco::Reconfig::allow_minus_one_indent and $line =~ /^\s*$Cisco::Reconfig::allow_minus_one_indent/) { } 5 83 88
Condition66%2/3
$ciscobug and $in == 0
!ll&&!rl&&r
8802
MC/DC50%1/2
$ciscobug and $in == 0
$ciscobug $in == 0
Truth table66%2/3
A and B
A= $ciscobugB= $in == 0
ABresult
0X0
100
111
130 2 $indent = 0;
131 ▶ } elsif ($last && $indent - 1 == $in && $allow_minus_one_indent && $line =~ /^\s*$allow_minus_one_indent/) {
Condition88%8/9
$last and $indent - 1 == $in and $Cisco::Reconfig::allow_minus_one_indent and $line =~ /^\s*$Cisco::Reconfig::allow_minus_one_indent/
!ll&&!rl&&r
24595
$last and $indent - 1 == $in and $Cisco::Reconfig::allow_minus_one_indent
!ll&&!rl&&r
24064
$last and $indent - 1 == $in
!ll&&!rl&&r
16864
MC/DC75%3/4
$last and $indent - 1 == $in and $Cisco::Reconfig::allow_minus_one_indent and $line =~ /^\s*$Cisco::Reconfig::allow_minus_one_indent/
$last $indent - 1 == $in $Cisco::Reconfig::allow_minus_one_indent $line =~ /^\s*$Cisco::Reconfig::allow_minus_one_indent/
Truth table80%4/5
A and B and C and D
A= $lastB= $indent - 1 == $inC= $Cisco::Reconfig::allow_minus_one_indentD= $line =~ /^\s*$Cisco::Reconfig::allow_minus_one_indent/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
132 5 ▶ confess unless $last->{$seqn};
Branch: 1 branch
BranchTrueFalseTotal
unless $last->{$seqn} 0 5 5
133 5 $last->{$subs} = rc1($in, "$last->{$seqn}aaa", $last, $line);
134 5 undef $last;
135 5 ▶ redo if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 5 0 5
136 } else {
137 83 return $config;
138 }
139 }
140 722 ▶ next if /^$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$/ 6 716 722
141 716 ▶ next if /^\s*!/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*!/ 165 551 716
142 551 my $context = $config;
143 551 my (@x) = split;
144 551 my $owords = @x;
145 551 ▶ while (@x && ref $context->{$x[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@x and ref $$context{$x[0]}) 432 551 983
Condition100%3/3
@x and ref $$context{$x[0]}
!ll&&!rl&&r
15536432
MC/DC100%2/2
@x and ref $$context{$x[0]}
@x ref $$context{$x[0]}
Truth table100%3/3
A and B
A= @xB= ref $$context{$x[0]}
ABresult
0X0
100
111
146 432 $context = $context->{$x[0]};
147 432 shift @x;
148 }
149 551 ▶ if (! @x) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @x) { } 15 536 551
elsif (defined $$context{$x[0]}) { } 0 536 536
150 # A duplicate line. Not fun.
151 # As far as we know this can only occur as a remark inside
152 # filter list.
153 # Q: what's the point of keeping track of these? Need to be
154 # able to accurately dump filter list definitions
155 #
156 $context->{$dupl} = []
157 15 ▶ unless $context->{$dupl};
Branch: 1 branch
BranchTrueFalseTotal
unless $context->{$dupl} 8 7 15
158 my $n = bless {
159 $ddata
160 ? ( $debg => "$dseq:DUP:$line",
161 15 ▶ $word => $context->{$word}, )
Branch: 1 branch
BranchTrueFalseTotal
$ddata ? : 0 15 15
162 : (),
163 }, __PACKAGE__;
164 15 $dseq++;
165  
166 15 push(@{$context->{$dupl}}, $n);
167 15 $context = $n;
168 } elsif (defined $context->{$x[0]}) {
169 0 confess "already $.: '$x[0]' $line";
170 }
171 551 ▶ while (@x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@x) 1468 551 2019
172 1468 my $x = shift @x;
173 1468 ▶ confess unless defined $x;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x 0 1468 1468
174 1468 ▶ confess unless defined $dseq;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dseq 0 1468 1468
175 1468 ▶ $line = "" unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 1 1467 1468
176 1468 ▶ $context = $context->{$x} = bless {
Branch: 1 branch
BranchTrueFalseTotal
$ddata ? : 0 1468 1468
177 $ddata
178 ? ( $debg => "$dseq:$x:$line",
179 $word => $x, )
180 : (),
181 }, __PACKAGE__;
182 1468 $dseq++;
183 }
184 551 $context->{$seqn} = $seq++;
185 551 $context->{$text} = $line;
186 551 ▶ confess if $context->{$cntx};
Branch: 1 branch
BranchTrueFalseTotal
if $context->{$cntx} 0 551 551
187  
188 551 $context->{$cntx} = $config;
189 551 weaken $context->{$cntx};
190  
191 551 ▶ unless ($nonext) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Cisco::Reconfig::nonext) 551 0 551
192 551 ▶ if ($last) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last) { } 392 159 551
193 392 $last->{$next} = $context;
194 392 weaken $last->{$next};
195 } else {
196 159 $config->{$next} = $context;
197 159 weaken $config->{$next};
198 }
199 }
200  
201 551 $last = $context;
202  
203 551 ▶ if ($line &&
Branch: 1 branch
BranchTrueFalseTotal
if ($line and ($line =~ /(\^C)/ and not $line =~ /\^C.*\^C/) or $line =~ /banner [a-z\-]+ ((?!\^C).+)/) 8 543 551
Condition88%8/9
$line and ($line =~ /(\^C)/ and not $line =~ /\^C.*\^C/) or $line =~ /banner [a-z\-]+ ((?!\^C).+)/
l!l&&r!l&&!r
80543
$line and ($line =~ /(\^C)/ and not $line =~ /\^C.*\^C/)
!ll&&!rl&&r
15428
$line =~ /(\^C)/ and not $line =~ /\^C.*\^C/
!ll&&!rl&&r
54028
MC/DC75%3/4
$line and ($line =~ /(\^C)/ and not $line =~ /\^C.*\^C/) or $line =~ /banner [a-z\-]+ ((?!\^C).+)/
$line $line =~ /(\^C)/ not $line =~ /\^C.*\^C/ $line =~ /banner [a-z\-]+ ((?!\^C).+)/
Truth table57%4/7
A and B and not(C) or D
A= $lineB= $line =~ /(\^C)/C= not $line =~ /\^C.*\^C/D= $line =~ /banner [a-z\-]+ ((?!\^C).+)/
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
204 ($line =~ /(\^C)/ && $line !~ /\^C.*\^C/)
205 ||
206 ($line =~ /banner [a-z\-]+ ((?!\^C).+)/))
207 {
208 #
209 # big special case for banners 'cause they don't follow
210 # normal indenting rules
211 #
212 8 ▶ die unless defined $1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $1 0 8 8
213 8 my $sep = qr/\Q$1\E/;
214 8 my $sub = $last->{$subs} = bless { $bloc => 1 }, __PACKAGE__;
215 8 $sub->{$cntx} = $last;
216 8 weaken $sub->{$cntx};
217 8 my $subnull = $sub->{''} = bless { $bloc => 1, $dupl => [] }, __PACKAGE__;
218 8 $subnull->{$cntx} = $sub;
219 8 weaken $subnull->{$cntx};
220 8 for(;;) {
221 48 $line = <$fh>;
222 48 ▶ last unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 48 48
223 48 ▶ my $l = bless {
Branch: 1 branch
BranchTrueFalseTotal
$ddata ? : 0 48 48
224 $ddata ? ( $debg => "$dseq:DUP:$line" ) : (),
225 }, __PACKAGE__;
226 48 $dseq++;
227 48 $l->{$seqn} = $seq++;
228 48 $l->{$text} = $line;
229 48 $l->{$cntx} = $subnull;
230 48 weaken($l->{$cntx});
231 48 push(@{$subnull->{$dupl}}, $l);
232 48 ▶ last if $line =~ /$sep[\r]?$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /${sep}[\r]?$/ 8 40 48
233 }
234 8 ▶ warn "parse probably failed"
Branch: 1 branch
BranchTrueFalseTotal
unless $line and $line =~ /${sep}[\r]?$/ 0 8 8
Condition33%1/3
$line and $line =~ /${sep}[\r]?$/
!ll&&!rl&&r
008
MC/DC0%0/2
$line and $line =~ /${sep}[\r]?$/
$line $line =~ /${sep}[\r]?$/
Truth table33%1/3
A and B
A= $lineB= $line =~ /${sep}[\r]?$/
ABresult
0X0
100
111
235 unless $line && $line =~ /$sep[\r]?$/;
236 }
237 }
238 9 return $config;
239 }
240  
241 #sub word { $_[0]->{$word} };
242 79 ▶sub block { $_[0]->{$bloc} }
Subroutine block: called CC=1 SCAR=0.0
Pod documented
243 13143 ▶sub seqn { $_[0]->{$seqn} || $_[0]->endpt->{$seqn} || confess };
Subroutine seqn: called CC=3 SCAR=12.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{$seqn} or $_[0]->endpt->{$seqn} or confess() 13143 0 13143
Condition66%2/3
$_[0]{$seqn} or $_[0]->endpt->{$seqn}
l!l&&r!l&&!r
1890112530
MC/DC0%0/2
$_[0]{$seqn} or $_[0]->endpt->{$seqn}
$_[0]{$seqn} $_[0]->endpt->{$seqn}
Truth table66%2/3
A or B
A= $_[0]{$seqn}B= $_[0]->endpt->{$seqn}
ABresult
1X1
011
000
244 225 ▶sub subs { $_[0]->{$subs} || $_[0]->zoom->{$subs} || $undef };
Subroutine subs: called CC=3 SCAR=11.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{$subs} or $_[0]->zoom->{$subs} or $undef 145 80 225
Condition66%2/3
$_[0]{$subs} or $_[0]->zoom->{$subs}
l!l&&r!l&&!r
1170108
MC/DC50%1/2
$_[0]{$subs} or $_[0]->zoom->{$subs}
$_[0]{$subs} $_[0]->zoom->{$subs}
Truth table66%2/3
A or B
A= $_[0]{$subs}B= $_[0]->zoom->{$subs}
ABresult
1X1
011
000
245 28 ▶sub next { $_[0]->{$next} || $_[0]->zoom->{$next} || $undef };
Subroutine next: called CC=3 SCAR=11.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{$next} or $_[0]->zoom->{$next} or $undef 23 5 28
Condition66%2/3
$_[0]{$next} or $_[0]->zoom->{$next}
l!l&&r!l&&!r
2305
MC/DC50%1/2
$_[0]{$next} or $_[0]->zoom->{$next}
$_[0]{$next} $_[0]->zoom->{$next}
Truth table66%2/3
A or B
A= $_[0]{$next}B= $_[0]->zoom->{$next}
ABresult
1X1
011
000
246 #sub undefined { $_[0] eq $undef }
247 #sub defined { $_[0] ne $undef }
248 41506 ▶sub defined { $_[0]->{$debg} ? $_[0]->{$debg} ne $UNDEFDESC : 1 }
Subroutine defined: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{$debg} ? : 135 41371 41506
249  
250 sub destroy
251 0 ▶{
Subroutine destroy: not called CC=1 SCAR=6.9
Pod undocumented
252 0 warn "Cisco::Reconfig::destroy is deprecated";
253 }
254  
255 sub single
256 42 ▶{
Subroutine single: called CC=5 SCAR=16.5
Pod documented
257 42 my ($self) = @_;
258 42 ▶ return $self if defined $self->{$text};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$text} 25 17 42
259 17 my (@p) = grep(! /$spec/o, keys %$self);
260 17 ▶ return undef if @p > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @p > 1 1 16 17
261 16 ▶ return $self unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 16 16
262 16 ▶ return $self->{$p[0]}->single || $self;
Condition33%1/3
$$self{$p[0]}->single || $self
l!l&&r!l&&!r
1600
MC/DC0%0/2
$$self{$p[0]}->single || $self
$$self{$p[0]}->single $self
Truth table33%1/3
A || B
A= $$self{$p[0]}->singleB= $self
ABresult
1X1
011
000
263 }
264  
265 sub kids
266 15 ▶{
Subroutine kids: called CC=3 SCAR=11.0
Pod documented
267 15 my ($self) = @_;
268 15 ▶ return $self if ! $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 15 15
269 15 my (@p) = $self->sortit(grep(! /$spec/o, keys %$self));
270 15 ▶ return $self if ! @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 12 3 15
271 3 return (map { $self->{$_} } @p);
272 }
273  
274 sub zoom
275 400 ▶{
Subroutine zoom: called CC=4 SCAR=13.9
Pod documented
276 400 my ($self) = @_;
277 400 ▶ return $self if defined $self->{$text};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$text} 165 235 400
278 235 my (@p) = $self->sortit(grep(! /$spec/o, keys %$self));
279 235 ▶ return $self if @p > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @p > 1 164 71 235
280 71 ▶ return $self unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 71 71
281 71 return $self->{$p[0]}->zoom;
282 }
283  
284 sub endpt
285 39558 ▶{
Subroutine endpt: called CC=5 SCAR=16.2
Pod documented
286 39558 my ($self) = @_;
287 39558 ▶ return $self if ! $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 39558 39558
288 39558 my (@p) = grep(! /$spec/o, keys %$self);
289 39558 ▶ return $self if defined($self->{$text}) && ! @p;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$text} and not @p 11265 28293 39558
Condition100%3/3
defined $self->{$text} and not @p
!ll&&!rl&&r
28291211265
MC/DC100%2/2
defined $self->{$text} and not @p
defined $self->{$text} not @p
Truth table100%3/3
A and not(B)
A= defined $self->{$text}B= not @p
ABresult
0X0
100
111
290 28293 ▶ confess unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 28293 28293
291 28293 return $self->{$p[0]}->endpt;
292 }
293  
294  
295 sub text
296 429 ▶{
Subroutine text: called CC=8 SCAR=21.1
Pod documented
297 429 my ($self) = @_;
298 429 ▶ return '' unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 11 418 429
299 418 ▶ if (defined $self->{$text}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{$text}) 133 285 418
300 return $debug_text
301 ? $self->{$word} . " " . $self->{$text}
302 133 ▶ : $self->{$text};
Branch: 1 branch
BranchTrueFalseTotal
$debug_text ? : 0 133 133
303 }
304 285 my (@p) = $self->sortit(grep(! /$spec/o, keys %$self));
305 285 ▶ if (@p > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@p > 1) { } 9 276 285
elsif ($self->{$dupl}) { } 6 270 276
306 #
307 # This is nasty because the lines may not be ordered
308 # in the tree-hiearchy used by Cisco::Reconfig
309 #
310 9 my %temp = map { $self->{$_}->sequenced_text(0) } @p;
311 9 return join('', map { $temp{$_} } sort keys %temp);
312 } elsif ($self->{$dupl}) {
313 0 ▶ return join('', map { $_->{$word} . " " . $_->{$text} } @{$self->{$dupl}})
Branch: 1 branch
BranchTrueFalseTotal
if $debug_text 0 6 6
314 if $debug_text;
315 6 return join('', map { $_->{$text} } @{$self->{$dupl}});
316 }
317 270 ▶ confess unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 270 270
318 270 return $self->{$p[0]}->text;
319 }
320  
321 sub sequenced_text
322 282 ▶{
Subroutine sequenced_text: called CC=10 SCAR=24.8
Pod undocumented
323 282 my ($self, $all) = @_;
324 282 my @t = ();
325 282 ▶ if (defined $self->{$text}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{$text}) 98 184 282
326 push(@t, $debug_text
327 ? ($self->seqn => $self->{$word} . " " . $self->{$text})
328 98 ▶ : ($self->seqn => $self->{$text}));
Branch: 1 branch
BranchTrueFalseTotal
$debug_text ? : 0 98 98
329 }
330 282 ▶ if (exists $self->{$dupl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$dupl}) 1 281 282
331 push (@t, $debug_text
332 0 ? map { $_->seqn => $_->{$word} . " " . $_->{$text} } @{$self->{$dupl}}
333 1 ▶ : map { $_->seqn => $_->{$text} } @{$self->{$dupl}});
Branch: 1 branch
BranchTrueFalseTotal
$debug_text ? : 0 1 1
334 }
335 282 my (@p) = $self->sortit(grep(! /$spec/o, keys %$self));
336 282 ▶ if (@p) {
Branch: 1 branch
BranchTrueFalseTotal
if (@p) 190 92 282
337 #
338 # This is nasty because the lines may not be ordered
339 # in the tree-hiearchy used by Cisco::Reconfig
340 #
341 190 return (@t, map { $self->{$_}->sequenced_text($all) } @p);
342 }
343 push(@t, $self->{$subs}->sequenced_text($all))
344 92 ▶ if $all && $self->{$subs};
Branch: 1 branch
BranchTrueFalseTotal
if $all and $self->{$subs} 16 76 92
Condition66%2/3
$all and $self->{$subs}
!ll&&!rl&&r
43490
MC/DC0%0/2
$all and $self->{$subs}
$all $self->{$subs}
Truth table66%2/3
A and B
A= $allB= $self->{$subs}
ABresult
0X0
100
111
345 92 ▶ return @t if @t;
Branch: 1 branch
BranchTrueFalseTotal
if @t 92 0 92
346 0 ▶ confess unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 0 0
347 0 return $self->{$p[0]}->sequenced_text($all);
348 }
349  
350 sub alltext
351 6 ▶{
Subroutine alltext: called CC=2 SCAR=6.9
Pod documented
352 6 my ($self) = @_;
353 6 ▶ return '' unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 1 5 6
354 5 my %temp = $self->sequenced_text(1);
355 5 return join('', map { $temp{$_} } sort keys %temp);
356 }
357  
358 sub chomptext
359 0 ▶{
Subroutine chomptext: not called CC=1 SCAR=6.9
Pod undocumented
360 0 my ($self) = @_;
361 0 my $t = $self->text;
362 0 chomp($t);
363 0 return $t;
364 }
365  
366 sub returns
367 16 ▶{
Subroutine returns: called CC=5 SCAR=17.8
Pod undocumented
368 16 my (@o) = @_;
369 16 for my $o (@o) {
370 55 ▶ $o .= "\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $o and not $o =~ /\n$/ 55 0 55
Condition33%1/3
defined $o and not $o =~ /\n$/
!ll&&!rl&&r
0055
MC/DC0%0/2
defined $o and not $o =~ /\n$/
defined $o not $o =~ /\n$/
Truth table33%1/3
A and not(B)
A= defined $oB= not $o =~ /\n$/
ABresult
0X0
100
111
371 if defined($o) && $o !~ /\n$/;
372 }
373 16 ▶ return $o[0] unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 16 16
374 16 return @o;
375 }
376  
377 sub openangle
378 9 ▶{
Subroutine openangle: called CC=4 SCAR=14.6
Pod undocumented
379 9 ▶ my (@l) = grep(defined && /\S/, @_);
Condition33%1/3
defined $_ && /\S/
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $_ && /\S/
defined $_ /\S/
Truth table33%1/3
A && B
A= defined $_B= /\S/
ABresult
0X0
100
111
380 9 my $x = 0;
381 9 for my $l (@l) {
382 12 substr($l, 0, 0) = (' ' x $x++);
383 }
384 9 ▶ return $l[0] unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 9 9
385 9 return @l;
386 }
387  
388 sub closeangle
389 11 ▶{
Subroutine closeangle: called CC=4 SCAR=14.6
Pod undocumented
390 11 ▶ my (@l) = grep(defined && /\S/, @_);
Condition33%1/3
defined $_ && /\S/
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $_ && /\S/
defined $_ /\S/
Truth table33%1/3
A && B
A= defined $_B= /\S/
ABresult
0X0
100
111
391 11 my $x = $#l;
392 11 for my $l (@l) {
393 14 substr($l, 0, 0) = (' ' x $x--);
394 }
395 11 ▶ return $l[0] unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 11 11
396 11 return @l;
397 }
398  
399 sub context
400 127 ▶{
Subroutine context: called CC=4 SCAR=17.9
Pod documented
401 defined($_[0]->{$cntx})
402 ? $_[0]->{$cntx}
403 127 ▶ : $_[0]->endpt->{$cntx}
Branch: 2 branches
BranchTrueFalseTotal
defined $_[0]{$cntx} ? : 115 12 127
$_[0] ? : 0 0 0
Condition33%1/3
$_[0]->endpt->{$cntx} or $_[0] ? confess("$_[0]") : $undef
l!l&&r!l&&!r
1200
MC/DC0%0/2
$_[0]->endpt->{$cntx} or $_[0] ? confess("$_[0]") : $undef
$_[0]->endpt->{$cntx} $_[0] ? confess("$_[0]") : $undef
Truth table33%1/3
A or B
A= $_[0]->endpt->{$cntx}B= $_[0] ? confess("$_[0]") : $undef
ABresult
1X1
011
000
404 || ($_[0] ? confess "$_[0]" : $undef)
405 };
406  
407 #
408 # interface Loopback7
409 # ip address x y
410 #
411  
412 sub setcontext
413 74 ▶{
Subroutine setcontext: called CC=6 SCAR=18.2
Pod documented
414 74 my ($self, @extras) = @_;
415 74 ▶ print STDERR "\nSETCONTEXT\n" if $debug_context;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_context 0 74 74
416 74 ▶ unless ($self->block) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->block) 10 64 74
417 10 ▶ print STDERR "\nNOT_A_BLOCK $self->{$debg}\n" if $debug_context;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_context 0 10 10
418 10 $self = $self->context;
419 }
420 printf STDERR "\nSELF %sCONTEXT %sCCONTEXT %sEXTRAS$#extras @extras\n",
421 $self->{$debg}, $self->context->{$debg},
422 74 ▶ $self->context->context->{$debg}
Branch: 1 branch
BranchTrueFalseTotal
if $debug_context 0 74 74
423 if $debug_context;
424 74 my $x = $self->context;
425 return (grep defined,
426 $x->context->setcontext,
427 74 ▶ trim($x->zoom->{$text}),
Branch: 1 branch
BranchTrueFalseTotal
if $x 36 38 74
428 @extras)
429 if $x;
430 38 return @extras;
431 }
432
433 sub contextcount
434 27 ▶{
Subroutine contextcount: called CC=3 SCAR=11.8
Pod undocumented
435 27 my $self = shift;
436 27 my (@a) = $self->setcontext(@_);
437 27 ▶ printf STDERR "CONTEXTCOUNT = %d\n", scalar(@a) if $debug_context;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_context 0 27 27
438 0 ▶ print STDERR map { "CC: $_\n" } @a if $debug_context;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_context 0 27 27
439 27 return scalar(@a);
440 }
441  
442 sub unsetcontext
443 11 ▶{
Subroutine unsetcontext: called CC=1 SCAR=0.0
Pod documented
444 11 my $self = shift;
445 11 return (("exit") x $self->contextcount(@_));
446 }
447  
448 sub teql
449 27 ▶{
Subroutine teql: called CC=1 SCAR=0.0
Pod undocumented
450 27 my ($self, $b) = @_;
451 27 my $a = $self->text;
452 27 $a =~ s/^\s+/ /g;
453 27 $a =~ s/^ //;
454 27 $a =~ s/ $//;
455 27 chomp($a);
456 27 $b =~ s/^\s+/ /g;
457 27 $b =~ s/^ //;
458 27 $b =~ s/ $//;
459 27 chomp($b);
460 27 return $a eq $b;
461 }
462  
463 sub set
464 16 ▶{
Subroutine set: called CC=48 SCAR=39.7
Pod documented
465 16 my $self = shift;
466 16 my $new = pop;
467 16 my (@designators) = @_;
468 #my ($self, $designator, $new) = @_;
469 16 ▶ print STDERR "\nSET\n" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 16 16
470 16 ▶ return undef unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 16 16
471 16 my $old;
472 #my @designators;
473 16 ▶ print STDERR "\nSELF $self->{$debg}" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 16 16
474 # move into the block if possible
475 16 ▶ $self = $self->subs
Branch: 1 branch
BranchTrueFalseTotal
if $self->subs 7 9 16
476 if $self->subs;
477 16 ▶ print STDERR "\nSELF $self->{$debg}" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 16 16
478 #if (ref $designator eq 'ARRAY') {
479 # @designators = @$designator;
480 # $old = $self->get(@designators);
481 # $designator = pop(@designators);
482 #} elsif ($designator) {
483 # $old = $self->get($designator);
484 #} else {
485 # $old = $self;
486 #}
487 16 my $designator;
488 16 ▶ if (@designators) {
Branch: 1 branch
BranchTrueFalseTotal
if (@designators) { } 10 6 16
489 10 $old = $self->get(@designators);
490 10 $designator = pop(@designators);
491 } else {
492 6 $old = $self;
493 }
494 16 ▶ print STDERR "\nOLD $old->{$debg}" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 16 16
495 16 my (@lines) = expand(grep(/./, split(/\n/, $new)));
496 16 ▶ if ($lines[0] =~ /^(\s+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines[0] =~ /^(\s+)/) 11 5 16
497 11 my $ls = $1;
498 11 my $m = 1;
499 11 ▶ map { substr($_, 0, length($ls)) eq $ls or $m = 0 } @lines;
Condition50%1/2
substr($_, 0, length $ls) eq $ls || ($m = 0)
l!l
510
MC/DC0%0/1
substr($_, 0, length $ls) eq $ls || ($m = 0)
substr($_, 0, length $ls) eq $ls
Truth table50%1/2
A
A= substr($_, 0, length $ls) eq $ls
Aresult
11
00
500 11 ▶ map { substr($_, 0, length($ls)) = '' } @lines
Branch: 1 branch
BranchTrueFalseTotal
if $m 11 0 11
501 if $m;
502 }
503 16 my $indent = (' ' x $self->contextcount(@designators));
504 16 for $_ (@lines) {
505 56 s/(\S)\s+/$1 /g;
506 56 s/\s+$//;
507 56 ▶ $_ = 'exit' if /^\s*!\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*!\s*$/ 4 52 56
508 56 $_ = "$indent$_";
509 }
510 16 ▶ print STDERR "SET TO {\n@lines\n}\n" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 16 16
511 16 my $desig = shift(@lines);
512 16 my @o;
513 16 ▶ undef $old
Branch: 1 branch
BranchTrueFalseTotal
unless $old 1 15 16
514 if ! $old;
515 16 ▶ if (! $old) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $old) { } 1 15 16
elsif (not $designator || looks_like_a_block($desig, @lines)) { } 5 10 15
elsif ($old->teql($desig)) { } 4 6 10
516 1 ▶ print STDERR "NO OLD\n" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 1 1
517 1 push(@o, openangle($self->setcontext(@designators)));
518 1 push(@o, $desig);
519 ▶ } elsif (! $designator && ! looks_like_a_block($desig,@lines)) {
Condition100%3/3
$designator || looks_like_a_block($desig, @lines)
l!l&&r!l&&!r
915
MC/DC100%2/2
$designator || looks_like_a_block($desig, @lines)
$designator looks_like_a_block($desig, @lines)
Truth table100%3/3
A || B
A= $designatorB= looks_like_a_block($desig, @lines)
ABresult
1X1
011
000
520 5 ▶ if ($self->block && $self->context) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->block and $self->context) { } 2 3 5
Condition66%2/3
$self->block and $self->context
!ll&&!rl&&r
320
MC/DC0%0/2
$self->block and $self->context
$self->block $self->context
Truth table33%1/3
A and B
A= $self->blockB= $self->context
ABresult
0X0
100
111
521 2 unshift(@lines, $desig);
522 2 $old = $self->context;
523 2 undef $desig;
524 } else {
525 3 unshift(@lines, $desig);
526 3 ▶ print STDERR "IN NASTY BIT\n" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 3 3
527 #
528 # this is a messy situation: we've got a random
529 # block of stuff to set inside a random block.
530 # In theorey we could avoid the die, I'll leave
531 # that as an exercise for the reader.
532 #
533 3 ▶ confess "You cannot set nested configurations with set(undef, \$config) -- use a designator on the set method"
Branch: 1 branch
BranchTrueFalseTotal
if grep /^$indent\s/, @lines 0 3 3
534 if grep(/^$indent\s/, @lines);
535 3 my (@t) = split(/\n/, $self->text);
536 3 my (%t);
537 3 @t{strim(@t)} = @t;
538 3 ▶ while (@lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 23 3 26
539 23 my $l = strim(shift(@lines));
540 23 ▶ if ($t{$l}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t{$l}) { } 22 1 23
541 22 delete $t{$l};
542 } else {
543 1 push(@o, "$indent$l");
544 }
545 }
546 3 for my $k (keys %t) {
547 2 unshift(@o, iinvert($indent, $k));
548 }
549 3 ▶ unshift(@o, $self->setcontext)
Branch: 1 branch
BranchTrueFalseTotal
if @o 2 1 3
550 if @o;
551 }
552 } elsif ($old->teql($desig)) {
553 4 ▶ print STDERR "DESIGNATOR EQUAL\n" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 4 4
554 # okay
555 } else {
556 6 ▶ print STDERR "DESIGNATOR DIFERENT\n" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 6 6
557 6 push(@o, openangle($self->setcontext(@designators)));
558 6 ▶ if (defined $designator) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $designator) { } 5 1 6
559 5 push(@o, iinvert($indent, $designator));
560 } else {
561 1 push(@o, iinvert($indent, split(/\n/, $self->text)));
562 }
563 6 push(@o, $desig);
564 }
565 16 ▶ if (@lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 6 10 16
566 6 ▶ if ($old && ! @o && $old->subs && $old->subs->next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old and not @o and $old->subs and $old->subs->next) 5 1 6
Condition66%6/9
$old and not @o and $old->subs and $old->subs->next
!ll&&!rl&&r
150
$old and not @o and $old->subs
!ll&&!rl&&r
150
$old and not @o
!ll&&!rl&&r
105
MC/DC0%0/4
$old and not @o and $old->subs and $old->subs->next
$old not @o $old->subs $old->subs->next
Truth table20%1/5
A and not(B) and C and D
A= $oldB= not @oC= $old->subsD= $old->subs->next
ABCDresult
0XXX0
10XX0
110X0
11100
11111
567 5 ▶ print STDERR "OLD= $old->{$debg}" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 5 5
568 5 my $ok = 1;
569 5 my $f = $old->subs->next;
570 5 ▶ print STDERR "F= $f->{$debg}" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 5 5
571 5 for my $l (@lines) {
572 19 ▶ next if $l =~ /^\s*exit\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /^\s*exit\s*$/ 2 17 19
573 17 ▶ next if $f->teql($l);
Branch: 1 branch
BranchTrueFalseTotal
if $f->teql($l) 15 2 17
574 2 ▶ print STDERR "LINE DIFF ON $l\n" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 2 2
575 2 $ok = 0;
576 2 last;
577 } continue {
578 17 $f = $f->next;
579 17 ▶ print STDERR "F= $f->{$debg}" if $debug_set;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_set 0 17 17
580 }
581 5 ▶ if (! $ok || $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok or $f) 2 3 5
Condition100%3/3
not $ok or $f
l!l&&r!l&&!r
221
MC/DC0%0/2
not $ok or $f
not $ok $f
Truth table33%1/3
not(A) or B
A= not $okB= $f
ABresult
1X1
011
000
582 2 push(@o, openangle($self->setcontext(@designators)));
583 2 push(@o, iinvert($indent, $designator));
584 2 push(@o, $desig);
585 }
586 }
587 6 ▶ push(@o, @lines) if @o;
Branch: 1 branch
BranchTrueFalseTotal
if @o 3 3 6
588 }
589 16 @o = grep(defined, @o);
590 16 ▶ push(@o, closeangle($self->unsetcontext(@designators)))
Branch: 1 branch
BranchTrueFalseTotal
if @o 11 5 16
591 if @o;
592 16 ▶ return join('', returns(@o)) unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 16 0 16
593 0 return returns(@o);
594 }
595  
596 sub looks_like_a_block
597 6 ▶{
Subroutine looks_like_a_block: called CC=5 SCAR=18.9
Pod undocumented
598 6 my ($first, @l) = @_;
599 6 my $last = pop(@l);
600 6 ▶ return 1 if ! defined $last;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $last 1 5 6
601 5 ▶ return 0 if grep(/^\S/, @l);
Branch: 1 branch
BranchTrueFalseTotal
if grep /^\S/, @l 0 5 5
602 5 ▶ return 0 if $first =~ /^\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $first =~ /^\s/ 5 0 5
603 0 ▶ return 0 if $last =~ /^\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $last =~ /^\s/ 0 0 0
604 0 return 1;
605 }
606  
607 sub iinvert
608 10 ▶{
Subroutine iinvert: called CC=6 SCAR=18.4
Pod undocumented
609 10 my ($indent,@l) = @_;
610 10 ▶ confess unless @l;
Branch: 1 branch
BranchTrueFalseTotal
unless @l 0 10 10
611 10 for $_ (@l) {
612 10 ▶ next unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 1 9 10
613 9 ▶ s/^\s*no /$indent/ or s/^\s*(\S)/${indent}no $1/
Branch: 1 branch
BranchTrueFalseTotal
s/^\s*no /$indent/ or s/^\s*(\S)/${indent}no $1/ 0 9 9
614 }
615 10 ▶ return $l[0] unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 10 10
616 10 return @l;
617 }
618  
619 sub all
620 9 ▶{
Subroutine all: called CC=3 SCAR=11.0
Pod documented
621 9 my ($self, $regex) = @_;
622 9 $self = $self->zoom;
623 9 ▶ return (map { $self->{$_} } $self->sortit(grep(/$regex/ && ! /$spec/o, keys %$self)))
Branch: 1 branch
BranchTrueFalseTotal
if $regex 3 6 9
Condition66%2/3
/$regex/ && !/$spec/o
!ll&&!rl&&r
31011
MC/DC50%1/2
/$regex/ && !/$spec/o
/$regex/ !/$spec/o
Truth table66%2/3
A && not(B)
A= /$regex/B= !/$spec/o
ABresult
0X0
100
111
624 if $regex;
625 6 return (map { $self->{$_} } $self->sortit(grep(! /$spec/o, keys %$self)));
626 }
627  
628 sub get
629 153 ▶{
Subroutine get: called CC=20 SCAR=32.6
Pod documented
630 153 my ($self, @designators) = @_;
631 153 ▶ return $self->mget(@designators)
Branch: 1 branch
BranchTrueFalseTotal
if wantarray and @designators > 1 1 152 153
Condition100%3/3
wantarray and @designators > 1
!ll&&!rl&&r
135171
MC/DC100%2/2
wantarray and @designators > 1
wantarray @designators > 1
Truth table100%3/3
A and B
A= wantarrayB= @designators > 1
ABresult
0X0
100
111
632 if wantarray && @designators > 1;
633  
634 152 ▶ print STDERR "\nGET <@designators> $self->{$debg}" if $debug_get;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_get 0 152 152
635  
636  
637 152 ▶ return $self unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 152 152
638 152 my $zoom = $self->zoom->subs;
639 152 ▶ $self = $zoom if $zoom;
Branch: 1 branch
BranchTrueFalseTotal
if $zoom 81 71 152
640  
641 152 ▶ print STDERR "\nZOOMSUB $self->{$debg}" if $debug_get;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_get 0 152 152
642  
643 152 ▶ while (@designators) {
Branch: 1 branch
BranchTrueFalseTotal
if (@designators) 175 0 175
644 175 my $designator = shift(@designators);
645 # $self = $self->zoom;
646 # $self = $self->single || $self;
647 175 ▶ print STDERR "\nDESIGNATOR: $designator. ZOOMED: $self->{$debg}\n"
Branch: 1 branch
BranchTrueFalseTotal
if $debug_get 0 175 175
648 if $debug_get;
649 175 for my $d (split(' ',$designator)) {
650 272 ▶ print STDERR "\nDO WE HAVE A: $d?\n" if $debug_get;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_get 0 272 272
651 272 ▶ return $undef unless $self->{$d};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{$d} 14 258 272
652 258 $self = $self->{$d};
653 258 ▶ print STDERR "\nWE DO: $self->{$debg}\n" if $debug_get;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_get 0 258 258
654 }
655 161 ▶ last unless @designators;
Branch: 1 branch
BranchTrueFalseTotal
unless @designators 138 23 161
656 23 ▶ if ($self->single) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->single) { } 23 0 23
657 23 $self = $self->subs;
658 23 ▶ print STDERR "\nSINGLETON: $self->{$debg}\n" if $debug_get;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_get 0 23 23
659 } else {
660 0 ▶ print STDERR "\nNOT SINGLE\n" if $debug_get;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_get 0 0 0
661 0 return $undef;
662 }
663 }
664 138 ▶ print STDERR "\nDONE\n" if $debug_get;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_get 0 138 138
665 138 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 15 123 138
666 15 $self = $self->zoom;
667 15 my (@k) = $self->kids;
668 15 ▶ return @k if @k;
Branch: 1 branch
BranchTrueFalseTotal
if @k 15 0 15
669 0 return $self;
670 }
671 123 return $self;
672 }
673  
674 sub strim
675 26 ▶{
Subroutine strim: called CC=3 SCAR=11.0
Pod undocumented
676 26 my (@l) = @_;
677 26 for $_ (@l) {
678 47 s/^\s+//;
679 47 s/\s+$//;
680 47 s/\n$//;
681 }
682 26 ▶ return $l[0] unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 23 3 26
683 3 return @l;
684 }
685  
686 sub trim
687 36 ▶{
Subroutine trim: called CC=3 SCAR=11.0
Pod undocumented
688 36 my (@l) = @_;
689 36 for $_ (@l) {
690 36 s/^\s+//;
691 36 s/\s+$//;
692 }
693 36 ▶ return $l[0] unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 36 36
694 36 return @l;
695 }
696  
697 sub display
698 0 ▶{
Subroutine display: not called CC=6 SCAR=37.4
Pod undocumented
699 0 my ($self) = @_;
700 0 my @o;
701 0 push(@o, $self->setcontext);
702 push(@o, trim($self->single->{$text}))
703 0 ▶ if $self->single && $self->single->{$text}
Branch: 1 branch
BranchTrueFalseTotal
if $self->single and $self->single->{$text} and $self->subs->undefined 0 0 0
Condition0%0/6
$self->single and $self->single->{$text} and $self->subs->undefined
!ll&&!rl&&r
000
$self->single and $self->single->{$text}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->single and $self->single->{$text} and $self->subs->undefined
$self->single $self->single->{$text} $self->subs->undefined
Truth table0%0/4
A and B and C
A= $self->singleB= $self->single->{$text}C= $self->subs->undefined
ABCresult
0XX0
10X0
1100
1111
704 && $self->subs->undefined;
705 0 ▶ push(@o, "! the whole enchalada")
Branch: 1 branch
BranchTrueFalseTotal
if $self->context->undefined 0 0 0
706 if $self->context->undefined;
707 0 my (@r) = returns(openangle(@o));
708 0 ▶ return @r if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
709 0 return join('', @r);
710 }
711  
712 sub callerlevels
713 15 ▶{
Subroutine callerlevels: called CC=2 SCAR=6.9
Pod undocumented
714 15 my $n = 1;
715 15 ▶ 1 while caller($n++);
Branch: 1 branch
BranchTrueFalseTotal
caller $n++ and do { '???' } 44 15 59
716 15 return $n;
717 }
718  
719 sub mget
720 15 ▶{
Subroutine mget: called CC=9 SCAR=23.3
Pod undocumented
721 15 my ($self, @designators) = @_;
722  
723 15 my $cl = callerlevels;
724 15 my @newset;
725 15 ▶ if (@designators > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@designators > 1) { } 1 14 15
726  
727 1 ▶ print STDERR "\nGET$cl $designators[0]----------\n" if $debug_mget;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_mget 0 1 1
728  
729 1 my (@set) = $self->get(shift @designators);
730 1 for my $item (@set) {
731  
732 14 ▶ print STDERR "\nMGET$cl $item ----------\n" if $debug_mget;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_mget 0 14 14
733 14 ▶ print STDERR "\nMGET$cl $item->{$debg}\n" if $debug_mget;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_mget 0 14 14
734  
735 14 my (@got) = $item->mget(@designators);
736  
737 0 ▶ print STDERR map { "\nRESULTS$cl: $_->{$debg}\n" } @got
Branch: 1 branch
BranchTrueFalseTotal
if $debug_mget 0 14 14
738 if $debug_mget;
739  
740 14 push(@newset, @got);
741 }
742 } else {
743  
744 14 ▶ print STDERR "\nxGET$cl $designators[0] -------\n" if $debug_mget;
Branch: 1 branch
BranchTrueFalseTotal
if $debug_mget 0 14 14
745  
746 14 (@newset) = $self->get(shift @designators);
747  
748 0 ▶ print STDERR map { "\nxRESULTS$cl: $_->{$debg}\n" } @newset
Branch: 1 branch
BranchTrueFalseTotal
if $debug_mget 0 14 14
749 if $debug_mget;
750  
751 }
752 15 return @newset;
753 }
754  
755 sub sortit
756 826 ▶{
Subroutine sortit: called CC=1 SCAR=0.0
Pod undocumented
757 826 my $self = shift;
758 826 return sort { $self->{$a}->seqn cmp $self->{$b}->seqn } @_;
759 }
760  
761 9 1;
762  
↑ Summary