blib/lib/Rex/Commands/Augeas.pm

filter: Statementstmt 20.4% 40 / 196 Branchbran 1.2% 1 / 80 Conditioncond 0.0% 0 / 68 MC/DCmcdc 0.0% 0 / 41 Subroutinesub 80.0% 12 / 15 Podpod 100% 1 / 1 totaltotal 13.4% 54 / 401 CC 72 SCAR 81.3
CC
72
Cov
12%
augeas
4422.0
_run_augtool
56.0
__ANON__
2.0
CRAP 3398.3
↑ Summary lib/Rex/CLI.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 =head1 NAME
6  
7 Rex::Commands::Augeas - An augeas module for (R)?ex
8  
9 =head1 DESCRIPTION
10  
11 This is a simple module to manipulate configuration files with the help of augeas.
12  
13 =head1 SYNOPSIS
14  
15 my $k = augeas exists => "/files/etc/hosts/*/ipaddr", "127.0.0.1";
16  
17 augeas insert => "/files/etc/hosts",
18 label => "01",
19 after => "/7",
20 ipaddr => "192.168.2.23",
21 canonical => "test";
22  
23 augeas dump => "/files/etc/hosts";
24  
25 augeas modify =>
26 "/files/etc/ssh/sshd_config/PermitRootLogin" => "without-password",
27 on_change => sub {
28 service ssh => "restart";
29 };
30  
31 =head1 EXPORTED FUNCTIONS
32  
33 =cut
34  
35 package Rex::Commands::Augeas;
36  
37 2 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 2 our $VERSION = '1.16.1'; # VERSION
41  
42 2 require Exporter;
43  
44 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 2 ▶use vars qw(@EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 2 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ▶use Rex::Commands;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 2 ▶use Rex::Commands::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 2 ▶use Rex::Commands::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 2 ▶use Rex::Commands::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 2 ▶use Rex::Helper::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 2 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 2 ▶use Module::Load::Conditional qw(can_load);
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 2 ▶my $has_config_augeas =
Branch: 1 branch
BranchTrueFalseTotal
can_load('modules', {'Config::Augeas', undef}) ? : 0 2 2
57 can_load( modules => { 'Config::Augeas' => undef } ) ? 1 : 0;
58  
59 2 @EXPORT = qw(augeas);
60  
61 =head2 augeas($action, @options)
62  
63 It returns 1 on success and 0 on failure.
64  
65 Actions:
66  
67 =over 4
68  
69 =cut
70  
71 0 ▶sub augeas {
Subroutine augeas: not called CC=66 SCAR=83.9
Pod documented
72 0 my ( $action, @options ) = @_;
73 0 my $ret;
74  
75 0 my $is_ssh = Rex::is_ssh();
76 0 my $aug; # Augeas object (non-SSH only)
77  
78 0 ▶ my $use_augtool =
Condition0%0/3
!$has_config_augeas || 'Rex::Config'->get_local_augeas_backend eq 'augtool'
l!l&&r!l&&!r
000
MC/DC0%0/2
!$has_config_augeas || 'Rex::Config'->get_local_augeas_backend eq 'augtool'
!$has_config_augeas 'Rex::Config'->get_local_augeas_backend eq 'augtool'
Truth table0%0/3
not(A) || B
A= !$has_config_augeasB= 'Rex::Config'->get_local_augeas_backend eq 'augtool'
ABresult
1X1
011
000
79 !$has_config_augeas || Rex::Config->get_local_augeas_backend eq 'augtool';
80  
81 0 ▶ if ( !$is_ssh && !$use_augtool ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_ssh or $use_augtool) 0 0 0
Condition0%0/3
$is_ssh or $use_augtool
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_ssh or $use_augtool
$is_ssh $use_augtool
Truth table0%0/3
A or B
A= $is_sshB= $use_augtool
ABresult
1X1
011
000
82 0 Rex::Logger::debug("Creating Config::Augeas Object");
83 0 $aug = Config::Augeas->new;
84 0 my $commands_to_prepend = Rex::Config->get_augeas_commands_prepend();
85 0 $aug->srun( join qq(\n), @{$commands_to_prepend} );
86 }
87  
88 0 my $on_change; # Any code to run on change
89 my $changed; # Whether any changes have taken place
90  
91 =item modify
92  
93 This modifies the keys given in @options in $file.
94  
95 augeas modify =>
96 "/files/etc/hosts/7/ipaddr" => "127.0.0.2",
97 "/files/etc/hosts/7/canonical" => "test01",
98 on_change => sub { say "I changed!" };
99  
100 =cut
101  
102 0 ▶ if ( $action eq "modify" ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($action eq 'modify') { } 0 0 0
elsif ($action eq 'remove') { } 0 0 0
elsif ($action eq 'insert') { } 0 0 0
elsif ($action eq 'dump') { } 0 0 0
elsif ($action eq 'exists') { } 0 0 0
elsif ($action eq 'get') { } 0 0 0
103 0 my $config_option = {@options};
104  
105 # Code to run on a change being made
106 $on_change = delete $config_option->{on_change}
107 0 ▶ if ref $config_option->{on_change} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $config_option->{"on_change"} eq "CODE" 0 0 0
108  
109 0 ▶ if ( $is_ssh || $use_augtool ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ssh or $use_augtool) { } 0 0 0
Condition0%0/3
$is_ssh or $use_augtool
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_ssh or $use_augtool
$is_ssh $use_augtool
Truth table0%0/3
A or B
A= $is_sshB= $use_augtool
ABresult
1X1
011
000
110 0 my @commands;
111 0 for my $key ( keys %{$config_option} ) {
112 0 Rex::Logger::debug( "modifying $key -> " . $config_option->{$key} );
113 0 push @commands, qq(set $key "$config_option->{$key}"\n);
114 }
115 0 my $result = _run_augtool(@commands);
116 0 $ret = $result->{return};
117 0 $changed = $result->{changed};
118 }
119 else {
120 0 for my $key ( keys %{$config_option} ) {
121 0 Rex::Logger::debug( "modifying $key -> " . $config_option->{$key} );
122 0 $aug->set( $key, $config_option->{$key} );
123 }
124 0 $ret = $aug->save;
125 0 Rex::Logger::debug("Augeas set status: $ret");
126 0 ▶ $changed = 1 if $ret && $aug->get('/augeas/events/saved'); # Any files changed?
Branch: 1 branch
BranchTrueFalseTotal
if $ret and $aug->get("/augeas/events/saved") 0 0 0
Condition0%0/3
$ret and $aug->get("/augeas/events/saved")
!ll&&!rl&&r
000
MC/DC0%0/2
$ret and $aug->get("/augeas/events/saved")
$ret $aug->get("/augeas/events/saved")
Truth table0%0/3
A and B
A= $retB= $aug->get("/augeas/events/saved")
ABresult
0X0
100
111
127 }
128 }
129  
130 =item remove
131  
132 Remove an entry.
133  
134 augeas remove => "/files/etc/hosts/2",
135 on_change => sub { say "I changed!" };
136  
137 =cut
138  
139 elsif ( $action eq "remove" ) {
140  
141 # Code to run on a change being made
142 0 ▶ if ( $options[-2]
Branch: 1 branch
BranchTrueFalseTotal
if ($options[-2] and $options[-2] eq "on_change" and ref $options[-1] eq "CODE") 0 0 0
Condition0%0/6
$options[-2] and $options[-2] eq "on_change" and ref $options[-1] eq "CODE"
!ll&&!rl&&r
000
$options[-2] and $options[-2] eq "on_change"
!ll&&!rl&&r
000
MC/DC0%0/3
$options[-2] and $options[-2] eq "on_change" and ref $options[-1] eq "CODE"
$options[-2] $options[-2] eq "on_change" ref $options[-1] eq "CODE"
Truth table0%0/4
A and B and C
A= $options[-2]B= $options[-2] eq "on_change"C= ref $options[-1] eq "CODE"
ABCresult
0XX0
10X0
1100
1111
143 && $options[-2] eq 'on_change'
144 && ref $options[-1] eq 'CODE' )
145 {
146 0 $on_change = pop @options;
147 0 pop @options;
148 }
149  
150 0 my @commands;
151 0 for my $aug_key (@options) {
152 0 Rex::Logger::debug("deleting $aug_key");
153  
154 0 ▶ if ( $is_ssh || $use_augtool ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ssh or $use_augtool) { } 0 0 0
Condition0%0/3
$is_ssh or $use_augtool
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_ssh or $use_augtool
$is_ssh $use_augtool
Truth table0%0/3
A or B
A= $is_sshB= $use_augtool
ABresult
1X1
011
000
155 0 push @commands, "rm $aug_key\n";
156 }
157 else {
158 0 my $_r = $aug->remove($aug_key);
159 0 Rex::Logger::debug("Augeas delete status: $_r");
160 }
161 }
162  
163 0 ▶ if ( $is_ssh || $use_augtool ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ssh or $use_augtool) { } 0 0 0
Condition0%0/3
$is_ssh or $use_augtool
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_ssh or $use_augtool
$is_ssh $use_augtool
Truth table0%0/3
A or B
A= $is_sshB= $use_augtool
ABresult
1X1
011
000
164 0 my $result = _run_augtool(@commands);
165 0 $ret = $result->{return};
166 0 $changed = $result->{changed};
167 }
168 else {
169 0 $ret = $aug->save;
170 0 ▶ $changed = 1 if $ret && $aug->get('/augeas/events/saved'); # Any files changed?
Branch: 1 branch
BranchTrueFalseTotal
if $ret and $aug->get("/augeas/events/saved") 0 0 0
Condition0%0/3
$ret and $aug->get("/augeas/events/saved")
!ll&&!rl&&r
000
MC/DC0%0/2
$ret and $aug->get("/augeas/events/saved")
$ret $aug->get("/augeas/events/saved")
Truth table0%0/3
A and B
A= $retB= $aug->get("/augeas/events/saved")
ABresult
0X0
100
111
171 }
172  
173 }
174  
175 =item insert
176  
177 Insert an item into the file. Here, the order of the options is important. If the order is wrong it won't save your changes.
178  
179 augeas insert => "/files/etc/hosts",
180 label => "01",
181 after => "/7",
182 ipaddr => "192.168.2.23",
183 alias => "test02",
184 on_change => sub { say "I changed!" };
185  
186 =cut
187  
188 elsif ( $action eq "insert" ) {
189 0 my $file = shift @options;
190 0 my $opts = {@options};
191  
192 0 my $label = $opts->{"label"};
193 0 delete $opts->{"label"};
194  
195 # Code to run on a change being made
196 0 ▶ if ( $options[-2]
Branch: 1 branch
BranchTrueFalseTotal
if ($options[-2] and $options[-2] eq "on_change" and ref $options[-1] eq "CODE") 0 0 0
Condition0%0/6
$options[-2] and $options[-2] eq "on_change" and ref $options[-1] eq "CODE"
!ll&&!rl&&r
000
$options[-2] and $options[-2] eq "on_change"
!ll&&!rl&&r
000
MC/DC0%0/3
$options[-2] and $options[-2] eq "on_change" and ref $options[-1] eq "CODE"
$options[-2] $options[-2] eq "on_change" ref $options[-1] eq "CODE"
Truth table0%0/4
A and B and C
A= $options[-2]B= $options[-2] eq "on_change"C= ref $options[-1] eq "CODE"
ABCresult
0XX0
10X0
1100
1111
197 && $options[-2] eq 'on_change'
198 && ref $options[-1] eq 'CODE' )
199 {
200 0 $on_change = pop @options;
201 0 pop @options;
202 }
203  
204 0 ▶ if ( $is_ssh || $use_augtool ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ssh or $use_augtool) { } 0 0 0
Condition0%0/3
$is_ssh or $use_augtool
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_ssh or $use_augtool
$is_ssh $use_augtool
Truth table0%0/3
A or B
A= $is_sshB= $use_augtool
ABresult
1X1
011
000
205 0 ▶ my $position = ( exists $opts->{"before"} ? "before" : "after" );
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'before'} ? : 0 0 0
206 0 ▶ unless ( exists $opts->{$position} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{$position}) 0 0 0
207 0 Rex::Logger::info(
208 "Error inserting key. You have to specify before or after.");
209 0 return 0;
210 }
211  
212 0 my @commands = ("ins $label $position $file$opts->{$position}\n");
213 0 delete $opts->{$position};
214  
215 0 ▶ for ( my $i = 0 ; $i < @options ; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @options) 0 0 0
216 0 my $key = $options[$i];
217 0 my $val = $options[ $i + 1 ];
218 0 ▶ next if ( $key eq "after" or $key eq "before" or $key eq "label" );
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "after" or $key eq "before" or $key eq "label" 0 0 0
Condition0%0/6
$key eq "after" or $key eq "before" or $key eq "label"
l!l&&r!l&&!r
000
$key eq "after" or $key eq "before"
l!l&&r!l&&!r
000
MC/DC0%0/3
$key eq "after" or $key eq "before" or $key eq "label"
$key eq "after" $key eq "before" $key eq "label"
Truth table0%0/4
A or B or C
A= $key eq "after"B= $key eq "before"C= $key eq "label"
ABCresult
1XX1
01X1
0011
0000
219  
220 0 my $_key = "$file/$label/$key";
221 0 Rex::Logger::debug("Setting $_key => $val");
222  
223 0 push @commands, qq(set $_key "$val"\n);
224 }
225 0 my $result = _run_augtool(@commands);
226 0 $ret = $result->{return};
227 0 $changed = $result->{changed};
228 }
229 else {
230 0 ▶ if ( exists $opts->{"before"} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{'before'}) { } 0 0 0
elsif (exists $opts->{'after'}) { } 0 0 0
231 0 $aug->insert( $label, before => "$file" . $opts->{"before"} );
232 0 delete $opts->{"before"};
233 }
234 elsif ( exists $opts->{"after"} ) {
235 0 my $t = $aug->insert( $label, after => "$file" . $opts->{"after"} );
236 0 delete $opts->{"after"};
237 }
238 else {
239 0 Rex::Logger::info(
240 "Error inserting key. You have to specify before or after.");
241 0 return 0;
242 }
243  
244 0 ▶ for ( my $i = 0 ; $i < @options ; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @options) 0 0 0
245 0 my $key = $options[$i];
246 0 my $val = $options[ $i + 1 ];
247  
248 0 ▶ next if ( $key eq "after" or $key eq "before" or $key eq "label" );
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "after" or $key eq "before" or $key eq "label" 0 0 0
Condition0%0/6
$key eq "after" or $key eq "before" or $key eq "label"
l!l&&r!l&&!r
000
$key eq "after" or $key eq "before"
l!l&&r!l&&!r
000
MC/DC0%0/3
$key eq "after" or $key eq "before" or $key eq "label"
$key eq "after" $key eq "before" $key eq "label"
Truth table0%0/4
A or B or C
A= $key eq "after"B= $key eq "before"C= $key eq "label"
ABCresult
1XX1
01X1
0011
0000
249  
250 0 my $_key = "$file/$label/$key";
251 0 Rex::Logger::debug("Setting $_key => $val");
252  
253 0 $aug->set( $_key, $val );
254 }
255  
256 0 $ret = $aug->save();
257 0 ▶ $changed = 1 if $ret && $aug->get('/augeas/events/saved'); # Any files changed?
Branch: 1 branch
BranchTrueFalseTotal
if $ret and $aug->get("/augeas/events/saved") 0 0 0
Condition0%0/3
$ret and $aug->get("/augeas/events/saved")
!ll&&!rl&&r
000
MC/DC0%0/2
$ret and $aug->get("/augeas/events/saved")
$ret $aug->get("/augeas/events/saved")
Truth table0%0/3
A and B
A= $retB= $aug->get("/augeas/events/saved")
ABresult
0X0
100
111
258 }
259 }
260  
261 =item dump
262  
263 Dump the contents of a file to STDOUT.
264  
265 augeas dump => "/files/etc/hosts";
266  
267 =cut
268  
269 elsif ( $action eq "dump" ) {
270 0 my $file = shift @options;
271 0 my $aug_key = $file;
272  
273 0 ▶ if ( $is_ssh || $use_augtool ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ssh or $use_augtool) { } 0 0 0
Condition0%0/3
$is_ssh or $use_augtool
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_ssh or $use_augtool
$is_ssh $use_augtool
Truth table0%0/3
A or B
A= $is_sshB= $use_augtool
ABresult
1X1
011
000
274 0 my $output = _run_augtool("print $aug_key");
275 0 say $output->{'return'};
276 }
277 else {
278 0 $aug->print($aug_key);
279 }
280 0 $ret = 0;
281 }
282  
283 =item exists
284  
285 Check if an item exists.
286  
287 my $exists = augeas exists => "/files/etc/hosts/*/ipaddr" => "127.0.0.1";
288 if($exists) {
289 say "127.0.0.1 exists!";
290 }
291  
292 =cut
293  
294 elsif ( $action eq "exists" ) {
295 0 my $file = shift @options;
296  
297 0 my $aug_key = $file;
298 0 ▶ my $val = $options[0] || "";
Condition0%0/2
$options[0] || ''
l!l
00
MC/DC0%0/1
$options[0] || ''
$options[0]
Truth table0%0/2
A
A= $options[0]
Aresult
11
00
299  
300 0 ▶ if ( $is_ssh || $use_augtool ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ssh or $use_augtool) { } 0 0 0
Condition0%0/3
$is_ssh or $use_augtool
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_ssh or $use_augtool
$is_ssh $use_augtool
Truth table0%0/3
A or B
A= $is_sshB= $use_augtool
ABresult
1X1
011
000
301 0 my @paths;
302 0 my $result = _run_augtool("match $aug_key");
303 0 for my $line ( split "\n", $result->{return} ) {
304 0 ▶ $line =~ s/\s=[^=]+$// or next;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ s/\s=[^=]+$//u or next 0 0 0
305 0 push @paths, $line;
306 }
307  
308 0 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) { } 0 0 0
309 0 for my $k (@paths) {
310 0 my @ret;
311 0 my $result = _run_augtool("get $k");
312 0 for my $line ( split "\n", $result->{return} ) {
313 0 $line =~ s/^[^=]+=\s//;
314 0 push @ret, $line;
315 }
316  
317 0 ▶ if ( $ret[0] eq $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret[0] eq $val) 0 0 0
318 0 return $k;
319 }
320 }
321 }
322 else {
323 0 return @paths;
324 }
325  
326 0 $ret = undef;
327 }
328 else {
329 0 my @paths = $aug->match($aug_key);
330  
331 0 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) { } 0 0 0
332 0 for my $k (@paths) {
333 0 ▶ if ( $aug->get($k) eq $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aug->get($k) eq $val) 0 0 0
334 0 return $k;
335 }
336 }
337 }
338 else {
339 0 return @paths;
340 }
341  
342 0 $ret = undef;
343 }
344 }
345  
346 =item get
347  
348 Returns the value of the given item.
349  
350 my $val = augeas get => "/files/etc/hosts/1/ipaddr";
351  
352 =cut
353  
354 elsif ( $action eq "get" ) {
355 0 my $file = shift @options;
356  
357 0 ▶ if ( $is_ssh || $use_augtool ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ssh or $use_augtool) { } 0 0 0
Condition0%0/3
$is_ssh or $use_augtool
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_ssh or $use_augtool
$is_ssh $use_augtool
Truth table0%0/3
A or B
A= $is_sshB= $use_augtool
ABresult
1X1
011
000
358 0 my @lines;
359 0 my $result = _run_augtool("get $file");
360 0 for my $line ( split "\n", $result->{return} ) {
361 0 $line =~ s/^[^=]+=\s//;
362 0 push @lines, $line;
363 }
364 0 return $lines[0];
365 }
366 else {
367 0 return $aug->get($file);
368 }
369 }
370  
371 else {
372 0 Rex::Logger::info("Unknown augeas action.");
373 }
374  
375 0 ▶ if ( $on_change && $changed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($on_change and $changed) 0 0 0
Condition0%0/3
$on_change and $changed
!ll&&!rl&&r
000
MC/DC0%0/2
$on_change and $changed
$on_change $changed
Truth table0%0/3
A and B
A= $on_changeB= $changed
ABresult
0X0
100
111
376 0 Rex::Logger::debug("Calling on_change hook of augeas");
377 0 $on_change->();
378 }
379  
380 0 ▶ Rex::Logger::debug("Augeas Returned: $ret") if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 0 0
381  
382 0 return $ret;
383 }
384  
385 =back
386  
387 =cut
388  
389 0 ▶sub _run_augtool {
Subroutine _run_augtool: not called CC=7 SCAR=40.3
390 0 my (@commands) = @_;
391  
392 0 ▶ die "augtool is not installed or not executable in the path"
Branch: 1 branch
BranchTrueFalseTotal
unless can_run("augtool") 0 0 0
393 unless can_run "augtool";
394 0 my $rnd_file = get_tmp_file;
395 0 my $fh = Rex::Interface::File->create;
396  
397 0 my $commands_to_prepend = Rex::Config->get_augeas_commands_prepend();
398 0 unshift @commands, @{$commands_to_prepend};
399  
400 0 $fh->open( ">", $rnd_file );
401 0 $fh->write( $_ . qq(\n) ) foreach (@commands);
402 0 $fh->close;
403 my ( $return, $error ) = i_run "augtool --file $rnd_file --autosave",
404 0 ▶ sub { @_ }, fail_ok => 1;
Subroutine __ANON__: not called CC=1 SCAR=6.9
405 0 ▶ my $ret = $? == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? == 0 ? : 0 0 0
406  
407 0 ▶ if ($ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) { } 0 0 0
408 0 Rex::Logger::debug("Augeas command return value: $ret");
409 0 Rex::Logger::debug("Augeas result: $return");
410 }
411 else {
412 0 Rex::Logger::info( "Augeas command failed: $error", 'warn' );
413 }
414 0 ▶ my $changed = "$return" =~ /Saved/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
"$return" =~ /Saved/u ? : 0 0 0
415 0 unlink $rnd_file;
416  
417 {
418 0 ▶ result => $ret,
Condition0%0/3
$return || $error
l!l&&r!l&&!r
000
MC/DC0%0/2
$return || $error
$return $error
Truth table0%0/3
A || B
A= $returnB= $error
ABresult
1X1
011
000
419 return => $return || $error,
420 changed => $changed,
421 };
422 }
423  
424 2 1;
↑ Summary lib/Rex/CLI.pm »