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
|
|
436
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
65
|
|
17
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
96
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.011'; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
10
|
use Exporter 'import'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
620
|
|
21
|
|
|
|
|
|
|
our @EXPORT = qw(ensure using); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub ensure (&;@) { |
24
|
1
|
|
|
1
|
0
|
2
|
my $code = shift; |
25
|
1
|
|
|
|
|
5
|
(ensure => $code, @_); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub using (&) { |
29
|
1
|
|
|
1
|
0
|
14
|
my $code = shift; |
30
|
1
|
|
|
|
|
6
|
(using => $code, @_); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
2
|
0
|
19
|
sub new { bless {}, shift } |
34
|
2
|
|
|
2
|
0
|
7
|
sub functions { qw(guarded_step) } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub guarded_step { |
37
|
9
|
|
|
9
|
0
|
29
|
my($doit, $name, %opts) = @_; |
38
|
9
|
|
66
|
|
|
38
|
my $ensure = delete $opts{ensure} || Doit::Log::error("ensure is missing"); |
39
|
8
|
|
66
|
|
|
30
|
my $using = delete $opts{using} || Doit::Log::error("using is missing"); |
40
|
7
|
100
|
|
|
|
25
|
Doit::Log::error("Unhandled options: " . join(" ", %opts)) if %opts; |
41
|
|
|
|
|
|
|
|
42
|
6
|
100
|
|
|
|
16
|
if (!$ensure->($doit)) { |
43
|
5
|
100
|
|
|
|
61
|
if ($doit->is_dry_run) { |
44
|
1
|
|
|
|
|
5
|
Doit::Log::info("$name (dry-run)"); |
45
|
|
|
|
|
|
|
} else { |
46
|
4
|
|
|
|
|
44
|
Doit::Log::info($name); |
47
|
4
|
|
|
|
|
441
|
$using->($doit); |
48
|
4
|
100
|
|
|
|
38
|
if (!$ensure->($doit)) { |
49
|
1
|
|
|
|
|
21
|
Doit::Log::error("'ensure' block for '$name' still fails after running the 'using' block"); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |