blib/lib/BigIP/LTM/ParseConfig.pm

filter: Statementstmt 2.9% 8 / 275 Branchbran 0.0% 0 / 146 Conditioncond 0.0% 0 / 68 MC/DCmcdc 0.0% 0 / 39 Subroutinesub 4.6% 2 / 43 Podpod 54.0% 20 / 37 totaltotal 4.9% 30 / 608 CC 110 SCAR 75.3
CC
110
Cov
2%
_parse
4290.0
write
210.0
_order
110.0
CRAP 1868.4
↑ Summary
1 package BigIP::LTM::ParseConfig;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #no warnings qw 'uninitialized';
6 1 our $VERSION = '0.8.4';
7  
8 # CURRENTLY UNDER DEVELOMENT BY WENWU YAN <careline@126.com>
9 #----------------------------------------------------------------------------
10 # The contents of this file are subject to the iControl Public License
11 # Version 4.5 (the "License"); you may not use this file except in
12 # compliance with the License. You may obtain a copy of the License at
13 # http://www.f5.com/.
14 #
15 # Software distributed under the License is distributed on an "AS IS"
16 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 # the License for the specific language governing rights and limitations
18 # under the License.
19 #
20 # The Original Code is iControl Code and related documentation
21 # distributed by F5.
22 #
23 # The Initial Developer of the Original Code is F5 Networks,
24 # Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2020 F5 Networks,
25 # Inc. All Rights Reserved. iControl (TM) is a registered trademark of F5 Networks, Inc.
26 #
27 # Alternatively, the contents of this file may be used under the terms
28 # of the GNU General Public License (the "GPL"), in which case the
29 # provisions of GPL are applicable instead of those above. If you wish
30 # to allow use of your version of this file only under the terms of the
31 # GPL and not to allow others to use your version of this file under the
32 # License, indicate your decision by deleting the provisions above and
33 # replace them with the notice and other provisions required by the GPL.
34 # If you do not delete the provisions above, a recipient may use your
35 # version of this file under either the License or the GPL.
36 #----------------------------------------------------------------------------
37  
38 #----------------------------------------------------------------------------
39 # Initialize the module
40 #----------------------------------------------------------------------------
41 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
42 0 my $class = shift;
43  
44 0 my $self = {};
45 0 bless $self, $class;
46  
47 0 $self->{'ConfigFile'} = shift;
48  
49 0 return $self;
50 }
51  
52 #----------------------------------------------------------------------------
53 # Return a list of objects for ltm
54 #----------------------------------------------------------------------------
55 0 ▶sub virtuals { return shift->_objectlist('ltm virtual')}
Subroutine virtuals: not called CC=1 SCAR=6.9
Pod documented
56 0 ▶sub pools { return shift->_objectlist('ltm pool') }
Subroutine pools: not called CC=1 SCAR=6.9
Pod documented
57 0 ▶sub rules { return shift->_objectlist('ltm rule') }
Subroutine rules: not called CC=1 SCAR=6.9
Pod documented
58 0 ▶sub nodes { return shift->_objectlist('ltm node') }
Subroutine nodes: not called CC=1 SCAR=6.9
Pod documented
59 0 ▶sub monitors { return shift->_objectlist('ltm monitor') }
Subroutine monitors: not called CC=1 SCAR=6.9
Pod documented
60 0 ▶sub profiles { return shift->_objectlist('ltm profile') }
Subroutine profiles: not called CC=1 SCAR=6.9
Pod documented
61 0 ▶sub persistences { return shift->_objectlist('ltm persistence') }
Subroutine persistences: not called CC=1 SCAR=6.9
Pod undocumented
62  
63 #----------------------------------------------------------------------------
64 # Return a list of objects for net
65 #----------------------------------------------------------------------------
66 0 ▶sub selfs { return shift->_objectlist('net self') }
Subroutine selfs: not called CC=1 SCAR=6.9
Pod undocumented
67 0 ▶sub vlans { return shift->_objectlist('net vlan') }
Subroutine vlans: not called CC=1 SCAR=6.9
Pod undocumented
68 0 ▶sub routes { return shift->_objectlist('net route') }
Subroutine routes: not called CC=1 SCAR=6.9
Pod documented
69 0 ▶sub trunks { return shift->_objectlist('net trunk') }
Subroutine trunks: not called CC=1 SCAR=6.9
Pod undocumented
70 0 ▶sub interfaces { return shift->_objectlist('net interface') }
Subroutine interfaces: not called CC=1 SCAR=6.9
Pod undocumented
71  
72 #----------------------------------------------------------------------------
73 # Return a list of objects for others
74 #----------------------------------------------------------------------------
75 0 ▶sub users { return shift->_objectlist('auth user') }
Subroutine users: not called CC=1 SCAR=6.9
Pod documented
76  
77  
78 #----------------------------------------------------------------------------
79 # Return an object hash for ltm
80 #----------------------------------------------------------------------------
81 0 ▶sub virtual { return shift->_object( 'ltm virtual', shift ) }
Subroutine virtual: not called CC=1 SCAR=6.9
Pod documented
82 0 ▶sub pool { return shift->_object( 'ltm pool', shift ) }
Subroutine pool: not called CC=1 SCAR=6.9
Pod documented
83 0 ▶sub rule { return shift->_object( 'ltm rule', shift ) }
Subroutine rule: not called CC=1 SCAR=6.9
Pod documented
84 0 ▶sub node { return shift->_object( 'ltm node', shift ) }
Subroutine node: not called CC=1 SCAR=6.9
Pod documented
85 0 ▶sub profile { return shift->_object( 'ltm profile', shift ) }
Subroutine profile: not called CC=1 SCAR=6.9
Pod documented
86 0 ▶sub monitor { return shift->_object( 'ltm monitor', shift ) }
Subroutine monitor: not called CC=1 SCAR=6.9
Pod documented
87 0 ▶sub persistence { return shift->_object( 'ltm persistence', shift ) }
Subroutine persistence: not called CC=1 SCAR=6.9
Pod undocumented
88  
89 # Return an object hash for net
90 0 ▶sub self { return shift->_object( "net self", shift ); }
Subroutine self: not called CC=1 SCAR=6.9
Pod undocumented
91 0 ▶sub vlan { return shift->_object( "net vlan", shift ); }
Subroutine vlan: not called CC=1 SCAR=6.9
Pod undocumented
92 0 ▶sub trunk { return shift->_object( "net trunk", shift ); }
Subroutine trunk: not called CC=1 SCAR=6.9
Pod undocumented
93 0 ▶sub interface { return shift->_object( "net interface", shift ); }
Subroutine interface: not called CC=1 SCAR=6.9
Pod undocumented
94 0 ▶sub route { return shift->_object( "net route", shift ); }
Subroutine route: not called CC=1 SCAR=6.9
Pod documented
95  
96 # Return an object hash for sys
97 0 ▶sub ntp { return shift->_object( "sys", "ntp" );}
Subroutine ntp: not called CC=1 SCAR=6.9
Pod undocumented
98 0 ▶sub sshd { return shift->_object( "sys", "sshd" ); }
Subroutine sshd: not called CC=1 SCAR=6.9
Pod undocumented
99 0 ▶sub snmp { return shift->_object( "sys", "snmp" ); }
Subroutine snmp: not called CC=1 SCAR=6.9
Pod undocumented
100 0 ▶sub syslog { return shift->_object( "sys", "syslog" ); }
Subroutine syslog: not called CC=1 SCAR=6.9
Pod undocumented
101 0 ▶sub state_mirror { return shift->_object( "sys", "state-mirroring" ); }
Subroutine state_mirror: not called CC=1 SCAR=6.9
Pod undocumented
102  
103 # Return an object hash for others
104 0 ▶sub user { return shift->_object( 'auth user', shift ); }
Subroutine user: not called CC=1 SCAR=6.9
Pod documented
105  
106 #----------------------------------------------------------------------------
107 # Return a list of pool members
108 #----------------------------------------------------------------------------
109 0 ▶sub members {
Subroutine members: not called CC=4 SCAR=30.0
Pod documented
110 0 my $self = shift;
111 0 my $pool = shift;
112  
113 0 ▶ $self->{'Parsed'} ||= $self->_parse();
Condition0%0/3
$self->{"Parsed"} ||= $self->_parse
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Parsed"} ||= $self->_parse
$self->{"Parsed"} $self->_parse
Truth table0%0/3
A ||= B
A= $self->{"Parsed"}B= $self->_parse
ABresult
1X1
011
000
114  
115 0 ▶ return 0 unless $self->{'Parsed'}->{'ltm pool'}->{$pool}->{'members'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Parsed"}{"ltm pool"}{$pool}{"members"} 0 0 0
116  
117 0 ▶ if ( ref $self->{'Parsed'}->{'ltm pool'}->{$pool}->{'members'} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'Parsed'}{'ltm pool'}{$pool}{'members'} eq 'HASH') { } 0 0 0
118 0 return keys %{$self->{'Parsed'}->{'pool'}->{$pool}->{'members'}};
119 }
120 else {
121 0 return $self->{'Parsed'}->{'ltm pool'}->{$pool}->{'members'};
122 }
123 }
124  
125 #----------------------------------------------------------------------------
126 # Return hashs of virtual servers
127 #----------------------------------------------------------------------------
128 0 ▶sub virtuals_all {
Subroutine virtuals_all: not called CC=6 SCAR=37.4
Pod undocumented
129 0 my $self = shift;
130 0 my @virtuals = $self->virtuals();
131  
132 0 foreach (@virtuals) {
133 0 my $virtual = $self->virtual($_);
134 0 ▶ my $pool = $virtual->{pool} if exists $virtual->{pool};
Branch: 1 branch
BranchTrueFalseTotal
if exists $virtual->{"pool"} 0 0 0
135 0 ▶ my @persist = keys %{$virtual->{persist}} if exists $virtual->{persist} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $virtual->{"persist"} 0 0 0
136 0 ▶ $virtual->{"pool_details"} = $self->pool($pool) if $pool;
Branch: 1 branch
BranchTrueFalseTotal
if $pool 0 0 0
137 0 ▶ $virtual->{"persist_mode"} = $self->persistence($persist[0])->{"mode"} if $persist[0];
Branch: 1 branch
BranchTrueFalseTotal
if $persist[0] 0 0 0
138 }
139  
140 0 return $self->{Parsed}{"ltm virtual"};
141 }
142  
143 #----------------------------------------------------------------------------
144 # Return details of virtual server
145 #----------------------------------------------------------------------------
146 0 ▶sub virtual_detail {
Subroutine virtual_detail: not called CC=6 SCAR=37.4
Pod undocumented
147 0 my $self = shift;
148 0 my $server = shift;
149 0 my @virtuals = $self->virtuals();
150  
151 0 foreach (@virtuals) {
152 0 my $virtual = $self->virtual($_);
153 0 ▶ my $pool = $virtual->{pool} if exists $virtual->{pool};
Branch: 1 branch
BranchTrueFalseTotal
if exists $virtual->{"pool"} 0 0 0
154 0 ▶ my @persist = keys %{$virtual->{persist}} if exists $virtual->{persist};
Branch: 1 branch
BranchTrueFalseTotal
if exists $virtual->{"persist"} 0 0 0
155 0 ▶ $virtual->{"pool_details"} = $self->pool($pool) if $pool;
Branch: 1 branch
BranchTrueFalseTotal
if $pool 0 0 0
156 0 ▶ $virtual->{"persist_mode"} = $self->persistence($persist[0])->{"mode"} if $persist[0];
Branch: 1 branch
BranchTrueFalseTotal
if $persist[0] 0 0 0
157 }
158  
159 0 return $self->{Parsed}{"ltm virtual"}{$server};
160 }
161  
162 # Modify an object
163 0 ▶sub modify {
Subroutine modify: not called CC=7 SCAR=40.3
Pod documented
164 0 my $self = shift;
165 0 my ($arg);
166 0 %{$arg} = @_;
167  
168 0 ▶ return 0 unless $arg->{'type'} && $arg->{'key'};
Branch: 1 branch
BranchTrueFalseTotal
unless $arg->{"type"} and $arg->{"key"} 0 0 0
Condition0%0/3
$arg->{"type"} and $arg->{"key"}
!ll&&!rl&&r
000
MC/DC0%0/2
$arg->{"type"} and $arg->{"key"}
$arg->{"type"} $arg->{"key"}
Truth table0%0/3
A and B
A= $arg->{"type"}B= $arg->{"key"}
ABresult
0X0
100
111
169  
170 0 my $obj = $arg->{'type'};
171 0 my $key = $arg->{'key'};
172 0 delete $arg->{'type'};
173 0 delete $arg->{'key'};
174  
175 0 ▶ $self->{'Parsed'} ||= $self->_parse();
Condition0%0/3
$self->{"Parsed"} ||= $self->_parse
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Parsed"} ||= $self->_parse
$self->{"Parsed"} $self->_parse
Truth table0%0/3
A ||= B
A= $self->{"Parsed"}B= $self->_parse
ABresult
1X1
011
000
176  
177 0 ▶ return 0 unless $self->{'Parsed'}->{$obj}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Parsed"}{$obj}{$key} 0 0 0
178  
179 0 foreach my $attr ( keys %{$arg} ) {
180 0 ▶ next unless $self->{'Parsed'}->{$obj}->{$key}->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Parsed"}{$obj}{$key}{$attr} 0 0 0
181 0 $self->{'Modify'}->{$obj}->{$key}->{$attr} = $arg->{$attr};
182 }
183  
184 0 return 1;
185 }
186  
187 # Write out a new configuration file
188 0 ▶sub write {
Subroutine write: not called CC=14 SCAR=53.5
Pod documented
189 0 my $self = shift;
190 0 ▶ my $file = shift || $self->{'ConfigFile'};
Condition0%0/3
shift() || $self->{'ConfigFile'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'ConfigFile'}
shift() $self->{'ConfigFile'}
Truth table0%0/3
A || B
A= shift()B= $self->{'ConfigFile'}
ABresult
1X1
011
000
191  
192 0 ▶ die "No changes found; no write necessary" unless $self->{'Modify'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Modify"} 0 0 0
193  
194 0 foreach my $obj (
195 qw( self partition route user monitor auth profile node pool rule virtual )
196 )
197 {
198 0 foreach my $key ( sort keys %{ $self->{'Parsed'}->{$obj} } ) {
199 0 ▶ if ( $self->{'Modify'}->{$obj}->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'Modify'}{$obj}{$key}) { } 0 0 0
200 0 $self->{'Output'} .= "$obj $key {\n";
201 0 foreach my $attr ( $self->_order($obj) ) {
202 0 ▶ next unless $self->{'Parsed'}->{$obj}->{$key}->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Parsed"}{$obj}{$key}{$attr} 0 0 0
203 $self->{'Modify'}->{$obj}->{$key}->{$attr}
204 0 ▶ ||= $self->{'Parsed'}->{$obj}->{$key}->{$attr};
Condition0%0/3
$self->{"Modify"}{$obj}{$key}{$attr} ||= $self->{"Parsed"}{$obj}{$key}{$attr}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Modify"}{$obj}{$key}{$attr} ||= $self->{"Parsed"}{$obj}{$key}{$attr}
$self->{"Modify"}{$obj}{$key}{$attr} $self->{"Parsed"}{$obj}{$key}{$attr}
Truth table0%0/3
A ||= B
A= $self->{"Modify"}{$obj}{$key}{$attr}B= $self->{"Parsed"}{$obj}{$key}{$attr}
ABresult
1X1
011
000
205 0 ▶ if (ref $self->{'Modify'}->{$obj}->{$key}->{$attr} eq
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'Modify'}{$obj}{$key}{$attr} eq 'ARRAY') { } 0 0 0
206 'ARRAY' )
207 {
208 0 ▶ if ( @{ $self->{'Modify'}->{$obj}->{$key}->{$attr} }
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'Modify'}{$obj}{$key}{$attr};} > 1) { } 0 0 0
209 > 1 )
210 {
211 0 $self->{'Output'} .= " $attr\n";
212 0 foreach my $val (
213 0 @{ $self->{'Modify'}->{$obj}->{$key}->{$attr}
214 }
215 )
216 {
217 0 $self->{'Output'} .= " $val\n";
218 0 ▶ if ( $self->{'Parsed'}->{$obj}->{$key}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Parsed"}{$obj}{$key}{"_xtra"}{$val}) 0 0 0
219 ->{'_xtra'}->{$val} )
220 {
221 $self->{'Output'}
222 .= ' '
223 . $self->{'Parsed'}->{$obj}->{$key}
224 0 ->{'_xtra'}->{$val} . "\n";
225 }
226 }
227 }
228 else {
229 $self->{'Output'}
230 .= " $attr "
231 . $self->{'Modify'}->{$obj}->{$key}
232 0 ->{$attr}[0] . "\n";
233 }
234 }
235 else {
236 $self->{'Output'}
237 .= " $attr "
238 0 . $self->{'Modify'}->{$obj}->{$key}->{$attr}
239 . "\n";
240 }
241 }
242 0 $self->{'Output'} .= "}\n";
243 }
244 else {
245 0 $self->{'Output'} .= $self->{'Raw'}->{$obj}->{$key};
246 }
247 }
248 }
249  
250 0 ▶ open FILE, ">$file" || return 0;
Condition0%0/2
">$file" || (return 0)
l!l
00
MC/DC0%0/1
">$file" || (return 0)
">$file"
Truth table0%0/2
A
A= ">$file"
Aresult
11
00
251 0 print FILE $self->{'Output'};
252 0 close FILE;
253  
254 0 return 1;
255 }
256  
257 #----------------------------------------------------------------------------
258 # Return an object hash
259 #----------------------------------------------------------------------------
260 0 ▶sub _object {
Subroutine _object: not called CC=3 SCAR=24.8
261 0 my $self = shift;
262 0 my $obj = shift;
263 0 my $var = shift;
264  
265 0 ▶ $self->{'Parsed'} ||= $self->_parse();
Condition0%0/3
$self->{"Parsed"} ||= $self->_parse
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Parsed"} ||= $self->_parse
$self->{"Parsed"} $self->_parse
Truth table0%0/3
A ||= B
A= $self->{"Parsed"}B= $self->_parse
ABresult
1X1
011
000
266  
267 0 ▶ return $self->{'Parsed'}->{$obj}->{$var} || 0;
Condition0%0/2
$self->{'Parsed'}{$obj}{$var} || 0
l!l
00
MC/DC0%0/1
$self->{'Parsed'}{$obj}{$var} || 0
$self->{'Parsed'}{$obj}{$var}
Truth table0%0/2
A
A= $self->{'Parsed'}{$obj}{$var}
Aresult
11
00
268 }
269  
270 #----------------------------------------------------------------------------
271 # Return a list of objects
272 #----------------------------------------------------------------------------
273 0 ▶sub _objectlist {
Subroutine _objectlist: not called CC=3 SCAR=24.8
274 0 my $self = shift;
275 0 my $obj = shift;
276  
277 0 ▶ $self->{'Parsed'} ||= $self->_parse();
Condition0%0/3
$self->{"Parsed"} ||= $self->_parse
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Parsed"} ||= $self->_parse
$self->{"Parsed"} $self->_parse
Truth table0%0/3
A ||= B
A= $self->{"Parsed"}B= $self->_parse
ABresult
1X1
011
000
278  
279 0 ▶ if ( $self->{'Parsed'}->{$obj} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'Parsed'}{$obj}) { } 0 0 0
280 0 return keys %{ $self->{'Parsed'}->{$obj} };
281 }
282 else {
283 0 return 0;
284 }
285 }
286  
287 #----------------------------------------------------------------------------
288 # Define object attribute ordering
289 #----------------------------------------------------------------------------
290 0 ▶sub _order {
Subroutine _order: not called CC=10 SCAR=47.0
291 0 my $self = shift;
292  
293 0 for (shift) {
294 0 ▶ /auth/ && return qw( bind login search servers service ssl user );
Branch: 1 branch
BranchTrueFalseTotal
/auth/ and return "bind", "login", "search", "servers", "service", "ssl", "user" 0 0 0
295 0 ▶ /ltm monitor/
Branch: 1 branch
BranchTrueFalseTotal
/ltm monitor/ and return "default", "base", "debug", "filter", "mandatoryattrs", "password", "security", "username", "interval", "timeout", "manual", "dest", "recv", "send" 0 0 0
296 && return
297 qw( default base debug filter mandatoryattrs password security username interval timeout manual dest recv send );
298 0 ▶ /ltm node/ && return qw( monitor screen );
Branch: 1 branch
BranchTrueFalseTotal
/ltm node/ and return "monitor", "screen" 0 0 0
299 0 ▶ /partition/ && return qw( description );
Branch: 1 branch
BranchTrueFalseTotal
/partition/ and return "description" 0 0 0
300 0 ▶ /ltm pool/ && return qw( lb nat monitor members );
Branch: 1 branch
BranchTrueFalseTotal
/ltm pool/ and return "lb", "nat", "monitor", "members" 0 0 0
301 0 ▶ /net self/ && return qw( netmask unit floating vlan allow );
Branch: 1 branch
BranchTrueFalseTotal
/net self/ and return "netmask", "unit", "floating", "vlan", "allow" 0 0 0
302 0 ▶ /auth user/ && return qw( password description id group home shell role );
Branch: 1 branch
BranchTrueFalseTotal
/auth user/ and return "password", "description", "id", "group", "home", "shell", "role" 0 0 0
303 0 ▶ /ltm virtual/
Branch: 1 branch
BranchTrueFalseTotal
/ltm virtual/ and return "translate", "snat", "pool", "destination", "ip", "rules", "profiles", "persist" 0 0 0
304 && return
305 qw( translate snat pool destination ip rules profiles persist );
306  
307 0 return 0;
308 }
309 }
310  
311 #----------------------------------------------------------------------------
312 # Parse the configuration file
313 #----------------------------------------------------------------------------
314 0 ▶sub _parse {
Subroutine _parse: not called CC=65 SCAR=83.6
315 0 my $self = shift;
316 0 ▶ my $file = shift || $self->{'ConfigFile'};
Condition0%0/3
shift() || $self->{'ConfigFile'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'ConfigFile'}
shift() $self->{'ConfigFile'}
Truth table0%0/3
A || B
A= shift()B= $self->{'ConfigFile'}
ABresult
1X1
011
000
317  
318 die "File not found: $self->{'ConfigFile'}\n"
319 0 ▶ unless -e $self->{'ConfigFile'};
Branch: 1 branch
BranchTrueFalseTotal
unless -e $self->{"ConfigFile"} 0 0 0
320  
321 0 ▶ open FILE, $file || return 0;
Condition0%0/2
$file || (return 0)
l!l
00
MC/DC0%0/1
$file || (return 0)
$file
Truth table0%0/2
A
A= $file
Aresult
11
00
322 0 my @file = <FILE>;
323 0 close FILE;
324  
325 0 my ( $parsed, $obj, $key, $attr1, $attr2, $attr3 );
326  
327 0 ▶ until ( !$file[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (not $file[0]) 0 0 0
328 0 my $ln = shift @file;
329  
330 #user attribute
331 0 ▶ if ( $ln=~ /^(auth user)\s(.*)\s\{(\s\})?$/) {
Branch: 8 branches
BranchTrueFalseTotal
if ($ln =~ /^(auth user)\s(.*)\s\{(\s\})?$/) { } 0 0 0
elsif ($ln =~ /^(ltm virtual|ltm pool|ltm node|ltm rule)\s(.*)\s\{(\s\})?$/) { } 0 0 0
elsif ($ln =~ /^(net self|net route|net interface|net vlan|net trunk)\s(.*)\s\{(\s\})?$/) { } 0 0 0
elsif ($ln =~ /^(sys)\s(sshd|syslog|ntp|snmp|state-mirroring)\s\{(\s\})?$/) { } 0 0 0
elsif ($ln =~ /^((ltm persistence)\s(cookie|source-addr|universal|destination-addr))\s(\S+)\s\{(\s\})?$/) { } 0 0 0
elsif ($ln =~ /^((ltm monitor)\s(http|tcp|udp|icmp))\s(\S+)\s\{(\s\})?$/) { } 0 0 0
elsif ($ln =~ /^((ltm profile)\s(web-acceleration|tcp|udp|request-log))\s(\S+)\s\{(\s\})?$/) { } 0 0 0
elsif ($ln =~ /^\}$/) { } 0 0 0
332 0 ▶ next if $3;
Branch: 1 branch
BranchTrueFalseTotal
if $3 0 0 0
333 0 $obj = $1;
334 0 $key = $2;
335 }
336 #ltm attribute
337 elsif ( $ln =~ /^(ltm virtual|ltm pool|ltm node|ltm rule)\s(.*)\s\{(\s\})?$/ ) {
338 0 ▶ next if $3;
Branch: 1 branch
BranchTrueFalseTotal
if $3 0 0 0
339 0 $obj = $1;
340 0 $key = $2;
341 }
342 #net attribute
343 elsif ( $ln =~ /^(net self|net route|net interface|net vlan|net trunk)\s(.*)\s\{(\s\})?$/ ) {
344 0 ▶ next if $3;
Branch: 1 branch
BranchTrueFalseTotal
if $3 0 0 0
345 0 $obj = $1;
346 0 $key = $2;
347 }
348 #sys attribute
349 elsif ($ln =~ /^(sys)\s(sshd|syslog|ntp|snmp|state-mirroring)\s\{(\s\})?$/) {
350 0 ▶ next if $3;
Branch: 1 branch
BranchTrueFalseTotal
if $3 0 0 0
351 0 $obj = $1;
352 0 $key = $2;
353 }
354 #persistence attribute
355 elsif ($ln =~ /^((ltm persistence)\s(cookie|source-addr|universal|destination-addr))\s(\S+)\s\{(\s\})?$/) {
356 0 ▶ next if $5;
Branch: 1 branch
BranchTrueFalseTotal
if $5 0 0 0
357 0 $obj = $2;
358 0 $key = $4;
359 0 $parsed->{$obj}{$key}{"mode"} = $3;
360 }
361 #monitor attribute
362 elsif ($ln =~ /^((ltm monitor)\s(http|tcp|udp|icmp))\s(\S+)\s\{(\s\})?$/) {
363 0 ▶ next if $5;
Branch: 1 branch
BranchTrueFalseTotal
if $5 0 0 0
364 0 $obj = $2;
365 0 $key = $4;
366 0 $parsed->{$obj}{$key}{"mode"} = $3;
367 }
368 #profile attribute
369 elsif ($ln =~ /^((ltm profile)\s(web-acceleration|tcp|udp|request-log))\s(\S+)\s\{(\s\})?$/) {
370 0 ▶ next if $5;
Branch: 1 branch
BranchTrueFalseTotal
if $5 0 0 0
371 0 $obj = $2;
372 0 $key = $4;
373 0 $parsed->{$obj}{$key}{"mode"} = $3;
374 }
375 #end of {}
376 elsif ( $ln =~ /^\}$/ ) {
377 0 $obj = undef;
378 0 $key = undef;
379 0 next;
380 }
381
382 # mungle data structure
383 0 ▶ if ( $obj && $key ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj and $key) 0 0 0
Condition0%0/3
$obj and $key
!ll&&!rl&&r
000
MC/DC0%0/2
$obj and $key
$obj $key
Truth table0%0/3
A and B
A= $objB= $key
ABresult
0X0
100
111
384 0 $self->{'Raw'}->{$obj}{$key} .= $ln;
385
386 #Indent=4 { not empty }
387 0 ▶ if ( $ln =~ /^\s{4}(\S+)\s\{$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{4}(\S+)\s\{$/) 0 0 0
388 0 $attr1 = $1;
389 0 next;
390 }
391
392 #$intdent=8 { not empty }
393 0 ▶ if ( $ln =~ /^\s{8}(\S+)\s\{$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{8}(\S+)\s\{$/) 0 0 0
394 0 $attr2 = $1;
395 0 next;
396 }
397  
398 #$intdent=12 { not empty }
399 0 ▶ if ( $ln =~ /^\s{8}(\S+)\s\{$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{8}(\S+)\s\{$/) 0 0 0
400 0 $attr3 = $1;
401 0 next;
402 }
403
404 #Indent=4 with }$
405 0 ▶ if ( $ln =~ /^\s{4}\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{4}\}$/) 0 0 0
406 0 $attr1 = undef;
407 0 next;
408 }
409
410 #Indent=8 with }$
411 0 ▶ if ( $ln =~ /^\s{8}\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{8}\}$/) 0 0 0
412 0 $attr2 = undef;
413 0 next;
414 }
415  
416 #Indent=12 with }$
417 0 ▶ if ( $ln =~ /^\s{12}\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{12}\}$/) 0 0 0
418 0 $attr2 = undef;
419 0 next;
420 }
421
422 #Indent=4 {}
423 0 ▶ if ( $ln =~ /^\s{4}(\S+)\s\{\s\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{4}(\S+)\s\{\s\}$/) 0 0 0
424 0 $parsed->{$obj}{$key}{$1} = undef;
425 0 next;
426 }
427
428 #Indent=4 { scalar }
429 0 ▶ if ( $ln =~ /^\s{4}(\S+)\s\{(.*)\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{4}(\S+)\s\{(.*)\}$/) 0 0 0
430 0 ▶ $parsed->{$obj}{$key}{$1} ||= [];
Condition0%0/2
$parsed->{$obj}{$key}{$1} ||= []
l!l
00
MC/DC0%0/1
$parsed->{$obj}{$key}{$1} ||= []
$parsed->{$obj}{$key}{$1}
Truth table0%0/2
A
A= $parsed->{$obj}{$key}{$1}
Aresult
11
00
431 0 push @{ $parsed->{$obj}{$key}{$1} },
432 0 grep { not /^\s*$/ } split( /\s+/, $2 );
433 0 next;
434 }
435
436 0 ▶ if ( defined $attr1 && $attr1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr1 and $attr1) 0 0 0
Condition0%0/3
defined $attr1 and $attr1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $attr1 and $attr1
defined $attr1 $attr1
Truth table0%0/3
A and B
A= defined $attr1B= $attr1
ABresult
0X0
100
111
437 #Indent=8 {}
438 0 ▶ if ( $ln =~ /^\s{8}(\S+)\s\{\s\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{8}(\S+)\s\{\s\}$/) 0 0 0
439 0 $parsed->{$obj}{$key}{$attr1}{$1} = undef;
440 0 next;
441 }
442
443 #Indent=8 { scalar }
444 0 ▶ if ( $ln =~ /^\s{8}(\S+)\s\{(.*)\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{8}(\S+)\s\{(.*)\}$/) 0 0 0
445 0 ▶ $parsed->{$obj}{$key}{$1} ||= [];
Condition0%0/2
$parsed->{$obj}{$key}{$1} ||= []
l!l
00
MC/DC0%0/1
$parsed->{$obj}{$key}{$1} ||= []
$parsed->{$obj}{$key}{$1}
Truth table0%0/2
A
A= $parsed->{$obj}{$key}{$1}
Aresult
11
00
446 0 push @{ $parsed->{$obj}{$key}{$1} },
447 0 grep { not /^\s*$/ } split( /\s+/, $2 );
448 0 next;
449 }
450
451 #Indent=8 match { key => value }
452 0 ▶ if ( $ln =~ /^\s{8}(\S+)\s(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{8}(\S+)\s(.*)$/) 0 0 0
453 0 $parsed->{$obj}{$key}{$attr1}{$1} = $2;
454 0 next;
455 }
456
457 #Indent=8 match scalar
458 0 ▶ if ( $ln =~ /^\s{8}(\S.+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{8}(\S.+)$/) 0 0 0
459 0 ▶ if ( ref( $parsed->{$obj}{$key}{$attr1} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parsed->{$obj}{$key}{$attr1} eq 'HASH') { } 0 0 0
460 0 $parsed->{$obj}{$key}{$attr1}{$1} = undef;
461 }
462 else {
463 0 ▶ $parsed->{$obj}{$key}{$attr1} ||= [];
Condition0%0/2
$parsed->{$obj}{$key}{$attr1} ||= []
l!l
00
MC/DC0%0/1
$parsed->{$obj}{$key}{$attr1} ||= []
$parsed->{$obj}{$key}{$attr1}
Truth table0%0/2
A
A= $parsed->{$obj}{$key}{$attr1}
Aresult
11
00
464 0 push @{ $parsed->{$obj}{$key}{$attr1} }, $1;
465 }
466 0 next;
467 }
468 }
469
470 0 ▶ if (defined $attr2 && ($attr1 && $attr2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr2 and ($attr1 and $attr2)) 0 0 0
Condition0%0/6
defined $attr2 and ($attr1 and $attr2)
!ll&&!rl&&r
000
$attr1 and $attr2
!ll&&!rl&&r
000
MC/DC0%0/3
defined $attr2 and ($attr1 and $attr2)
defined $attr2 $attr1 $attr2
Truth table0%0/4
A and B and C
A= defined $attr2B= $attr1C= $attr2
ABCresult
0XX0
10X0
1100
1111
471 #Indent=12 match { }
472 0 ▶ if ( $ln =~ /^\s{12}(\S+)\s\{\s\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{12}(\S+)\s\{\s\}$/) 0 0 0
473 0 $parsed->{$obj}{$key}{$attr1}{$attr2}{$1} = undef;
474 0 next;
475 }
476  
477 #Indent=12 { scalar }
478 0 ▶ if ( $ln =~ /^\s{12}(\S+)\s\{(.*)\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{12}(\S+)\s\{(.*)\}$/) 0 0 0
479 0 ▶ $parsed->{$obj}{$key}{$attr1} ||= [];
Condition0%0/2
$parsed->{$obj}{$key}{$attr1} ||= []
l!l
00
MC/DC0%0/1
$parsed->{$obj}{$key}{$attr1} ||= []
$parsed->{$obj}{$key}{$attr1}
Truth table0%0/2
A
A= $parsed->{$obj}{$key}{$attr1}
Aresult
11
00
480 0 push @{ $parsed->{$obj}{$key}{$attr1}{$attr2}{$1} },
481 0 grep { not /^\s*$/ } split(/\s+/, $2);
482 0 next;
483 }
484  
485 #Indent=12 match { key => value }
486 0 ▶ if ( $ln =~ /^\s{12}(\S+)\s(.*)\s?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{12}(\S+)\s(.*)\s?$/) 0 0 0
487 0 $parsed->{$obj}->{$key}{$attr1}{$attr2}{$1} = $2;
488 0 next;
489 }
490  
491 #Indent=12 match scalar
492 0 ▶ if ( $ln =~ /^\s{12}(.*)\s?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{12}(.*)\s?$/) 0 0 0
493 0 ▶ if ( ref($parsed->{$obj}{$key}{$attr1}{$attr2}) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parsed->{$obj}{$key}{$attr1}{$attr2} eq 'HASH') { } 0 0 0
494 0 $parsed->{$obj}{$key}{$attr1}{$attr2}{$1} = undef;
495 }
496 else {
497 0 ▶ $parsed->{$obj}{$key}{$attr1}{$attr2} ||= [];
Condition0%0/2
$parsed->{$obj}{$key}{$attr1}{$attr2} ||= []
l!l
00
MC/DC0%0/1
$parsed->{$obj}{$key}{$attr1}{$attr2} ||= []
$parsed->{$obj}{$key}{$attr1}{$attr2}
Truth table0%0/2
A
A= $parsed->{$obj}{$key}{$attr1}{$attr2}
Aresult
11
00
498 0 push @{ $parsed->{$obj}{$key}{$attr1}{$attr2} }, $1;
499 }
500 0 next;
501 }
502 }
503  
504 0 ▶ if (defined $attr3 && ($attr1 && $attr2 && $attr3)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr3 and ($attr1 and $attr2 and $attr3)) 0 0 0
Condition0%0/9
defined $attr3 and ($attr1 and $attr2 and $attr3)
!ll&&!rl&&r
000
$attr1 and $attr2 and $attr3
!ll&&!rl&&r
000
$attr1 and $attr2
!ll&&!rl&&r
000
MC/DC0%0/4
defined $attr3 and ($attr1 and $attr2 and $attr3)
defined $attr3 $attr1 $attr2 $attr3
Truth table0%0/5
A and B and C and D
A= defined $attr3B= $attr1C= $attr2D= $attr3
ABCDresult
0XXX0
10XX0
110X0
11100
11111
505 #Indent=16 match { }
506 0 ▶ if ( $ln =~ /^\s{16}(\S+)\s\{\s\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{16}(\S+)\s\{\s\}$/) 0 0 0
507 0 $parsed->{$obj}{$key}{$attr1}{$attr2}{$attr3}{$1} = undef;
508 0 next;
509 }
510  
511 #Indent=16 { scalar }
512 0 ▶ if ( $ln =~ /^\s{16}(\S+)\s\{(.*)\}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{16}(\S+)\s\{(.*)\}$/) 0 0 0
513 0 ▶ $parsed->{$obj}{$key}{$attr1} ||= [];
Condition0%0/2
$parsed->{$obj}{$key}{$attr1} ||= []
l!l
00
MC/DC0%0/1
$parsed->{$obj}{$key}{$attr1} ||= []
$parsed->{$obj}{$key}{$attr1}
Truth table0%0/2
A
A= $parsed->{$obj}{$key}{$attr1}
Aresult
11
00
514 0 push @{ $parsed->{$obj}{$key}{$attr1}{$attr2}{$attr3}{$1} },
515 0 grep { not /^\s*$/ } split(/\s+/, $2);
516 0 next;
517 }
518  
519 #Indent=16 match { key => value }
520 0 ▶ if ( $ln =~ /^\s{16}(\S+)\s(.*)\s?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{16}(\S+)\s(.*)\s?$/) 0 0 0
521 0 $parsed->{$obj}->{$key}{$attr1}{$attr2}{$attr3}{$1} = $2;
522 0 next;
523 }
524  
525 #Indent=16 match scalar
526 0 ▶ if ( $ln =~ /^\s{16}(.*)\s?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{16}(.*)\s?$/) 0 0 0
527 0 ▶ if ( ref($parsed->{$obj}{$key}{$attr1}{$attr2}{$attr3}) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parsed->{$obj}{$key}{$attr1}{$attr2}{$attr3} eq 'HASH') { } 0 0 0
528 0 $parsed->{$obj}{$key}{$attr1}{$attr2}{$attr3}{$1} = undef;
529 }
530 else {
531 0 ▶ $parsed->{$obj}{$key}{$attr1}{$attr2} ||= [];
Condition0%0/2
$parsed->{$obj}{$key}{$attr1}{$attr2} ||= []
l!l
00
MC/DC0%0/1
$parsed->{$obj}{$key}{$attr1}{$attr2} ||= []
$parsed->{$obj}{$key}{$attr1}{$attr2}
Truth table0%0/2
A
A= $parsed->{$obj}{$key}{$attr1}{$attr2}
Aresult
11
00
532 0 push @{ $parsed->{$obj}{$key}{$attr1}{$attr2}{$attr3} }, $1;
533 }
534 0 next;
535 }
536 }
537  
538 #Indent=4 match { key => value }
539 0 ▶ if ( $ln =~ /^\s{4}(\S+)\s(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^\s{4}(\S+)\s(.*)$/) 0 0 0
540 0 $parsed->{$obj}{$key}{$1} = $2;
541 0 next;
542 }
543 }
544 }
545  
546 # Fill in ill-formatted objects
547 0 foreach my $object ( keys %{ $self->{'Raw'} } ) {
548 0 foreach my $attr ( keys %{ $self->{'Raw'}->{$object} } ) {
549 0 ▶ $parsed->{$object}->{$attr} ||= $self->{'Raw'}->{$object}->{$attr};
Condition0%0/3
$parsed->{$object}{$attr} ||= $self->{"Raw"}{$object}{$attr}
l!l&&r!l&&!r
000
MC/DC0%0/2
$parsed->{$object}{$attr} ||= $self->{"Raw"}{$object}{$attr}
$parsed->{$object}{$attr} $self->{"Raw"}{$object}{$attr}
Truth table0%0/3
A ||= B
A= $parsed->{$object}{$attr}B= $self->{"Raw"}{$object}{$attr}
ABresult
1X1
011
000
550 }
551 }
552  
553 0 return $parsed;
554 }
555  
556 1 1;
557  
558 __END__
↑ Summary