|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # -*- perl -*-  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #  | 
| 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # Author: Slaven Rezic  | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #  | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # Copyright (C) 2017,2018 Slaven Rezic. All rights reserved.  | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # This package is free software; you can redistribute it and/or  | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # modify it under the same terms as Perl itself.  | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #  | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # Mail: slaven@rezic.de  | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # WWW:  http://www.rezic.de/eserte/  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #  | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Doit::Guarded;  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
16
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
427
 | 
 use strict;  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
50
 | 
    | 
| 
17
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
10
 | 
 use warnings;  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
79
 | 
    | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '0.011';  | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
20
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
9
 | 
 use Exporter 'import';  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
520
 | 
    | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our @EXPORT = qw(ensure using);  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub ensure (&;@) {  | 
| 
24
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
0
  
 | 
2
 | 
     my $code = shift;  | 
| 
25
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     (ensure => $code, @_);  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub using (&) {  | 
| 
29
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
0
  
 | 
11
 | 
     my $code = shift;  | 
| 
30
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
     (using => $code, @_);  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
33
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
  
0
  
 | 
16
 | 
 sub new { bless {}, shift }  | 
| 
34
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
  
0
  
 | 
7
 | 
 sub functions { qw(guarded_step) }  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub guarded_step {  | 
| 
37
 | 
9
 | 
 
 | 
 
 | 
  
9
  
 | 
  
0
  
 | 
26
 | 
     my($doit, $name, %opts) = @_;  | 
| 
38
 | 
9
 | 
 
 | 
  
 66
  
 | 
 
 | 
 
 | 
30
 | 
     my $ensure = delete $opts{ensure} || Doit::Log::error("ensure is missing");  | 
| 
39
 | 
8
 | 
 
 | 
  
 66
  
 | 
 
 | 
 
 | 
24
 | 
     my $using  = delete $opts{using}  || Doit::Log::error("using is missing");  | 
| 
40
 | 
7
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
20
 | 
     Doit::Log::error("Unhandled options: " . join(" ", %opts)) if %opts;  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
42
 | 
6
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
30
 | 
     if (!$ensure->($doit)) {  | 
| 
43
 | 
5
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
59
 | 
 	if ($doit->is_dry_run) {  | 
| 
44
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
 	    Doit::Log::info("$name (dry-run)");  | 
| 
45
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	} else {  | 
| 
46
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
20
 | 
 	    Doit::Log::info($name);  | 
| 
47
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
976
 | 
 	    $using->($doit);  | 
| 
48
 | 
4
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
19
 | 
 	    if (!$ensure->($doit)) {  | 
| 
49
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
 		Doit::Log::error("'ensure' block for '$name' still fails after running the 'using' block");  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	    }  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |